Converted to use Surface class instead of independent material properties.

pull/3/head
Chris Laurel 2001-02-28 01:59:05 +00:00
parent b0bf0f1377
commit 7a98e42268
5 changed files with 64 additions and 81 deletions

View File

@ -1,7 +1,11 @@
// body.cpp
//
// Copyright (C) 2001 Chris Laurel <claurel@shatters.net>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
#include <stdlib.h>
#include "mathlib.h"
@ -16,9 +20,8 @@ Body::Body(PlanetarySystem* _system) :
satellites(NULL),
rings(NULL),
rotationPeriod(1),
color(1.0f, 1.0f, 1.0f),
oblateness(0),
appearanceFlags(0)
surface(Color(1.0f, 1.0f, 1.0f)),
oblateness(0)
{
system = _system;
}
@ -128,27 +131,15 @@ void Body::setRotationPeriod(float _rotationPeriod)
}
Color Body::getColor() const
const Surface& Body::getSurface() const
{
return color;
return surface;
}
void Body::setColor(Color _color)
void Body::setSurface(const Surface& surf)
{
color = _color;
}
string Body::getTexture() const
{
return texture;
}
void Body::setTexture(const string _texture)
{
texture = _texture;
surface = surf;
}
@ -157,38 +148,12 @@ string Body::getMesh() const
return mesh;
}
void Body::setMesh(const string _mesh)
{
mesh = _mesh;
}
uint32 Body::getAppearanceFlags() const
{
return appearanceFlags;
}
void Body::setAppearanceFlags(uint32 flags)
{
appearanceFlags = flags;
}
bool Body::getAppearanceFlag(uint32 flag) const
{
return (appearanceFlags & flag) != 0;
}
void Body::setAppearanceFlag(uint32 flag, bool on)
{
appearanceFlags &= ~flag;
appearanceFlags |= on ? flag : 0;
}
const PlanetarySystem* Body::getSatellites() const
{
return satellites;

View File

@ -1,6 +1,11 @@
// body.h
//
// Copyright (C) 2001 Chris Laurel <claurel@shatters.net>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
#ifndef _BODY_H_
#define _BODY_H_
@ -8,6 +13,7 @@
#include <string>
#include <vector>
#include "color.h"
#include "surface.h"
#include "orbit.h"
#include "star.h"
@ -89,16 +95,10 @@ class Body
RingSystem* getRings() const;
void setRings(RingSystem&);
void setColor(Color);
Color getColor() const;
void setTexture(std::string);
std::string getTexture() const;
void setMesh(std::string);
std::string getMesh() const;
void setAppearanceFlags(uint32);
uint32 getAppearanceFlags() const;
void setAppearanceFlag(uint32, bool);
bool getAppearanceFlag(uint32) const;
void setSurface(const Surface&);
const Surface& getSurface() const;
float getLuminosity(const Star& sun,
float distanceFromSun) const;
@ -112,11 +112,6 @@ class Body
Mat4d getLocalToHeliocentric(double when);
Point3d getHeliocentricPosition(double when);
// Appearance flags
enum {
BlendTexture = 1,
};
private:
std::string name;
@ -130,10 +125,8 @@ class Body
float albedo;
float rotationPeriod;
Color color;
std::string texture;
std::string mesh;
uint32 appearanceFlags;
Surface surface;
RingSystem* rings;

View File

@ -27,6 +27,8 @@ using namespace std;
#define RENDER_DISTANCE 10.0f
#define FAINTEST_MAGNITUDE 5.5f
// Static meshes and textures used by all instances of Simulation
static bool commonDataInitialized = false;
@ -36,6 +38,8 @@ static bool commonDataInitialized = false;
static SphereMesh* sphereMesh[SPHERE_LODS];
static SphereMesh* asteroidMesh = NULL;
static CTexture* normalizationTex = NULL;
static CTexture* starTex = NULL;
static CTexture* glareTex = NULL;
static CTexture* ringsTex = NULL;
@ -52,7 +56,9 @@ Renderer::Renderer() :
labelMode(NoLabels),
ambientLightLevel(0.1f),
console(NULL),
nSimultaneousTextures(1)
nSimultaneousTextures(1),
useRegisterCombiners(false),
useCubeMaps(false)
{
textureManager = new TextureManager("textures");
meshManager = new MeshManager("models");
@ -180,9 +186,13 @@ bool Renderer::init(int winWidth, int winHeight)
if (font != NULL)
txfEstablishTexture(font, 0, GL_TRUE);
// Initialize GL extensions
if (ExtensionSupported("GL_ARB_multitexture"))
InitExtMultiTexture();
if (ExtensionSupported("GL_NV_register_combiners"))
InitExtRegisterCombiners();
if (ExtensionSupported("GL_EXT_texture_cube_map"))
normalizationTex = CreateNormalizationCubeMap(64);
commonDataInitialized = true;
}
@ -192,7 +202,20 @@ bool Renderer::init(int winWidth, int winHeight)
// Get GL extension information
if (ExtensionSupported("GL_ARB_multitexture"))
{
DPRINTF("Renderer: multi-texture supported.\n");
glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &nSimultaneousTextures);
}
if (ExtensionSupported("GL_NV_register_combiners"))
{
DPRINTF("Renderer: nVidia register combiners supported.\n");
useRegisterCombiners = true;
}
if (ExtensionSupported("GL_EXT_texture_cube_map"))
{
DPRINTF("Renderer: cube texture maps supported.\n");
useCubeMaps = true;
}
cout << "Simultaneous textures supported: " << nSimultaneousTextures << '\n';
@ -714,12 +737,13 @@ void Renderer::renderPlanet(const Body& body,
glLightColor(GL_LIGHT0, GL_DIFFUSE, Vec3f(1.0f, 1.0f, 1.0f));
glEnable(GL_LIGHT0);
const Surface& surface = body.getSurface();
// Get the texture . . .
CTexture* tex = NULL;
if (body.getTexture() != "")
if (surface.baseTexture != "")
{
if (!textureManager->find(body.getTexture(), &tex))
tex = textureManager->load(body.getTexture());
if (!textureManager->find(surface.baseTexture, &tex))
tex = textureManager->load(surface.baseTexture);
}
if (tex == NULL)
@ -732,8 +756,8 @@ void Renderer::renderPlanet(const Body& body,
glBindTexture(GL_TEXTURE_2D, tex->getName());
}
if (tex == NULL || body.getAppearanceFlag(Body::BlendTexture))
glColor(body.getColor());
if (tex == NULL || (surface.appearanceFlags & Surface::BlendTexture) != 0)
glColor(surface.color);
else
glColor4f(1, 1, 1, 1);
@ -935,7 +959,7 @@ void Renderer::renderPlanet(const Body& body,
renderBodyAsParticle(pos,
appMag,
discSizeInPixels,
body.getColor(),
body.getSurface().color,
orientation,
false);
#if 0

View File

@ -161,6 +161,8 @@ class Renderer
double projMatrix[16];
int nSimultaneousTextures;
bool useRegisterCombiners;
bool useCubeMaps;
public:
friend bool operator<(const Renderer::RenderListEntry&,

View File

@ -167,22 +167,21 @@ static Body* CreatePlanet(PlanetarySystem* system,
planetData->getNumber("RotationPeriod", rotationPeriod);
body->setRotationPeriod(rotationPeriod);
Color color(1.0f, 1.0f, 1.0f);
planetData->getColor("Color", color);
body->setColor(color);
string texture("");
planetData->getString("Texture", texture);
body->setTexture(texture);
Surface surface;
surface.color = Color(1.0f, 1.0f, 1.0f);
planetData->getColor("Color", surface.color);
planetData->getString("Texture", surface.baseTexture);
planetData->getString("BumpMap", surface.bumpTexture);
bool blendTexture = false;
planetData->getBoolean("BlendTexture", blendTexture);
if (blendTexture)
surface.appearanceFlags |= Surface::BlendTexture;
body->setSurface(surface);
string mesh("");
planetData->getString("Mesh", mesh);
body->setMesh(mesh);
bool blendTexture = false;
planetData->getBoolean("BlendTexture", blendTexture);
body->setAppearanceFlag(Body::BlendTexture, blendTexture);
// Read the ring system
{
Value* ringsDataValue = planetData->getValue("Rings");