Use the new Universe class.

ver1_5_1
Chris Laurel 2002-01-07 22:48:32 +00:00
parent 9a61c6524a
commit a0718055a7
10 changed files with 146 additions and 514 deletions

View File

@ -100,7 +100,6 @@ Renderer::Renderer() :
saturationMagNight(1.0f),
saturationMag(1.0f),
starVertexBuffer(NULL),
asterisms(NULL),
nSimultaneousTextures(1),
useTexEnvCombine(false),
useRegisterCombiners(false),
@ -254,7 +253,7 @@ bool Renderer::init(int winWidth, int winHeight)
InitExtMultiTexture();
if (ExtensionSupported("GL_NV_register_combiners"))
InitExtRegisterCombiners();
if (ExtensionSupported("GL_NV_vertex_program") && glGenProgramsNV)
if (ExtensionSupported("GL_NV_vertex_program"))
InitExtVertexProgram();
if (ExtensionSupported("GL_EXT_texture_cube_map"))
{
@ -478,12 +477,6 @@ void Renderer::clearLabelledStars()
}
void Renderer::showAsterisms(AsterismList* a)
{
asterisms = a;
}
float Renderer::getAmbientLightLevel() const
{
return ambientLightLevel;
@ -558,10 +551,8 @@ void Renderer::clearLabels()
void Renderer::render(const Observer& observer,
const StarDatabase& starDB,
const Universe& universe,
float faintestMagNight,
SolarSystem* solarSystem,
GalaxyList* galaxies,
const Selection& sel,
double now)
{
@ -595,6 +586,8 @@ void Renderer::render(const Observer& observer,
// renderList.
renderList.clear();
// See if there's a solar system nearby that we need to render.
SolarSystem* solarSystem = universe.getNearestSolarSystem(observer.getPosition());
const Star* sun = NULL;
if (solarSystem != NULL)
sun = solarSystem->getStar();
@ -690,22 +683,25 @@ void Renderer::render(const Observer& observer,
glEnable(GL_TEXTURE_2D);
}
if ((renderFlags & ShowGalaxies) != 0 && galaxies != NULL)
renderGalaxies(*galaxies, observer);
if ((renderFlags & ShowGalaxies) != 0 &&
universe.getGalaxyCatalog() != NULL)
renderGalaxies(*universe.getGalaxyCatalog(), observer);
// Translate the camera before rendering the stars
glPushMatrix();
glTranslatef(-observerPos.x, -observerPos.y, -observerPos.z);
// Render stars
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
if ((renderFlags & ShowStars) != 0)
renderStars(starDB, faintestMag, observer);
if ((renderFlags & ShowStars) != 0 && universe.getStarCatalog() != NULL)
renderStars(*universe.getStarCatalog(), faintestMag, observer);
// Render asterisms
if ((renderFlags & ShowDiagrams) != 0 && asterisms != NULL)
if ((renderFlags & ShowDiagrams) != 0 && universe.getAsterisms() != NULL)
{
glColor4f(0.5f, 0.0, 1.0f, 0.5f);
glDisable(GL_TEXTURE_2D);
AsterismList* asterisms = universe.getAsterisms();
for (AsterismList::const_iterator iter = asterisms->begin();
iter != asterisms->end(); iter++)
{
@ -724,12 +720,13 @@ void Renderer::render(const Observer& observer,
}
}
if ((labelMode & GalaxyLabels) != 0)
labelGalaxies(*galaxies, observer);
if ((labelMode & StarLabels) != 0)
labelStars(labelledStars, starDB, observer);
if ((labelMode & ConstellationLabels) != 0 && asterisms != NULL)
labelConstellations(*asterisms, observer);
if ((labelMode & GalaxyLabels) != 0 && universe.getGalaxyCatalog() != NULL)
labelGalaxies(*universe.getGalaxyCatalog(), observer);
if ((labelMode & StarLabels) != 0 && universe.getStarCatalog() != NULL)
labelStars(labelledStars, *universe.getStarCatalog(), observer);
if ((labelMode & ConstellationLabels) != 0 &&
universe.getAsterisms() != NULL)
labelConstellations(*universe.getAsterisms(), observer);
glPopMatrix();

View File

@ -12,11 +12,8 @@
#include <vector>
#include <string>
#include <celengine/stardb.h>
#include <celengine/observer.h>
#include <celengine/solarsys.h>
#include <celengine/galaxy.h>
#include <celengine/asterism.h>
#include <celengine/universe.h>
#include <celengine/selection.h>
#include <celtxf/texturefont.h>
@ -37,10 +34,8 @@ class Renderer
void setRenderMode(int);
void render(const Observer&,
const StarDatabase&,
const Universe&,
float faintestVisible,
SolarSystem*,
GalaxyList*,
const Selection& sel,
double now);
@ -88,8 +83,6 @@ class Renderer
float getBrightnessBias() const;
void setBrightnessBias(float);
void showAsterisms(AsterismList*);
typedef struct {
std::string text;
Color color;
@ -231,8 +224,6 @@ class Renderer
std::vector<Star*> labelledStars;
AsterismList* asterisms;
double modelMatrix[16];
double projMatrix[16];

View File

@ -25,13 +25,11 @@ using namespace std;
#define VELOCITY_CHANGE_TIME 0.25f
Simulation::Simulation() :
Simulation::Simulation(Universe* _universe) :
realTime(0.0),
simTime(0.0),
timeScale(1.0),
stardb(NULL),
solarSystemCatalog(NULL),
galaxies(NULL),
universe(_universe),
closestSolarSystem(NULL),
selection(),
targetSpeed(0.0),
@ -164,10 +162,8 @@ static RigidTransform fromUniversal(const FrameOfReference& frame,
void Simulation::render(Renderer& renderer)
{
renderer.render(observer,
*stardb,
*universe,
faintestVisible,
closestSolarSystem,
galaxies,
selection,
simTime);
}
@ -184,20 +180,6 @@ static Quatf lookAt(Point3f from, Point3f to, Vec3f up)
}
SolarSystem* Simulation::getSolarSystem(const Star* star)
{
if (star == NULL)
return NULL;
uint32 starNum = star->getCatalogNumber();
SolarSystemCatalog::iterator iter = solarSystemCatalog->find(starNum);
if (iter == solarSystemCatalog->end())
return NULL;
else
return iter->second;
}
UniversalCoord Simulation::getSelectionPosition(Selection& sel, double when)
{
if (sel.body != NULL)
@ -239,23 +221,9 @@ float getSelectionSize(Selection& sel)
}
StarDatabase* Simulation::getStarDatabase() const
Universe* Simulation::getUniverse() const
{
return stardb;
}
SolarSystemCatalog* Simulation::getSolarSystemCatalog() const
{
return solarSystemCatalog;
}
void Simulation::setStarDatabase(StarDatabase* db,
SolarSystemCatalog* catalog,
GalaxyList* galaxyList)
{
stardb = db;
solarSystemCatalog = catalog;
galaxies = galaxyList;
return universe;
}
@ -272,34 +240,6 @@ void Simulation::setTime(double jd)
}
class ClosestStarFinder : public StarHandler
{
public:
ClosestStarFinder(float _maxDistance);
~ClosestStarFinder() {};
void process(const Star& star, float distance, float appMag);
public:
float maxDistance;
float closestDistance;
Star* closestStar;
};
ClosestStarFinder::ClosestStarFinder(float _maxDistance) :
maxDistance(_maxDistance), closestDistance(_maxDistance), closestStar(NULL)
{
}
void ClosestStarFinder::process(const Star& star, float distance, float appMag)
{
if (distance < closestDistance)
{
closestStar = const_cast<Star*>(&star);
closestDistance = distance;
}
}
// Set the observer position and orientation based on the frame of reference
void Simulation::updateObserver()
{
@ -426,10 +366,7 @@ void Simulation::update(double dt)
}
// Find the closest solar system
Point3f observerPos = (Point3f) observer.getPosition();
ClosestStarFinder closestFinder(1.0f);
stardb->findCloseStars(closestFinder, observerPos, 1.0f);
closestSolarSystem = getSolarSystem(closestFinder.closestStar);
closestSolarSystem = universe->getNearestSolarSystem(observer.getPosition());
}
@ -445,264 +382,12 @@ void Simulation::setSelection(const Selection& sel)
}
struct PlanetPickInfo
{
double cosClosestAngle;
double closestDistance;
Body* closestBody;
Vec3d direction;
Point3d origin;
double jd;
};
bool ApproxPlanetPickTraversal(Body* body, void* info)
{
PlanetPickInfo* pickInfo = (PlanetPickInfo*) info;
Point3d bpos = body->getHeliocentricPosition(pickInfo->jd);
Vec3d bodyDir = bpos - pickInfo->origin;
bodyDir.normalize();
double cosAngle = bodyDir * pickInfo->direction;
if (cosAngle > pickInfo->cosClosestAngle)
{
pickInfo->cosClosestAngle = cosAngle;
pickInfo->closestBody = body;
}
return true;
}
// Perform an intersection test between the pick ray and a body
bool ExactPlanetPickTraversal(Body* body, void* info)
{
PlanetPickInfo* pickInfo = (PlanetPickInfo*) info;
Point3d bpos = body->getHeliocentricPosition(pickInfo->jd);
Vec3d bodyDir = bpos - pickInfo->origin;
// This intersection test naively assumes that the body is spherical.
double v = bodyDir * pickInfo->direction;
double disc = square(body->getRadius()) - ((bodyDir * bodyDir) - square(v));
if (disc > 0.0)
{
double distance = v - sqrt(disc);
if (distance > 0.0 && distance < pickInfo->closestDistance)
{
pickInfo->closestDistance = distance;
pickInfo->closestBody = body;
}
}
return true;
}
Selection Simulation::pickPlanet(Observer& observer,
const Star& sun,
SolarSystem& solarSystem,
Vec3f pickRay)
{
PlanetPickInfo pickInfo;
// Transform the pick direction
pickRay = pickRay * observer.getOrientation().toMatrix4();
pickInfo.direction = Vec3d((double) pickRay.x,
(double) pickRay.y,
(double) pickRay.z);
pickInfo.origin = astro::heliocentricPosition(observer.getPosition(),
sun.getPosition());
pickInfo.cosClosestAngle = -1.0;
pickInfo.closestDistance = 1.0e50;
pickInfo.closestBody = NULL;
pickInfo.jd = simTime;
// First see if there's a planet that the pick ray intersects.
// Select the closest planet intersected.
solarSystem.getPlanets()->traverse(ExactPlanetPickTraversal,
(void*) &pickInfo);
if (pickInfo.closestBody != NULL)
return Selection(pickInfo.closestBody);
// If no planet was intersected by the pick ray, choose the planet
// with the smallest angular separation from the pick ray. Very distant
// planets are likley to fail the intersection test even if the user
// clicks on a pixel where the planet's disc has been rendered--in order
// to make distant planets visible on the screen at all, their apparent size
// has to be greater than their actual disc size.
solarSystem.getPlanets()->traverse(ApproxPlanetPickTraversal,
(void*) &pickInfo);
if (pickInfo.cosClosestAngle > cos(degToRad(0.5)))
return Selection(pickInfo.closestBody);
else
return Selection();
}
/*
* StarPicker is a callback class for StarDatabase::findVisibleStars
*/
class StarPicker : public StarHandler
{
public:
StarPicker(const Point3f&, const Vec3f&, float);
~StarPicker() {};
void process(const Star&, float, float);
public:
const Star* pickedStar;
Point3f pickOrigin;
Vec3f pickRay;
float cosAngleClosest;
};
StarPicker::StarPicker(const Point3f& _pickOrigin, const Vec3f& _pickRay,
float angle) :
pickedStar(NULL),
pickOrigin(_pickOrigin),
pickRay(_pickRay),
cosAngleClosest((float) cos(angle))
{
}
void StarPicker::process(const Star& star, float distance, float appMag)
{
Vec3f starDir = star.getPosition() - pickOrigin;
starDir.normalize();
float cosAngle = starDir * pickRay;
if (cosAngle > cosAngleClosest)
{
cosAngleClosest = cosAngle;
pickedStar = &star;
}
}
class CloseStarPicker : public StarHandler
{
public:
CloseStarPicker(const UniversalCoord& pos,
const Vec3f& dir,
float _maxDistance,
float angle);
~CloseStarPicker() {};
void process(const Star& star, float distance, float appMag);
public:
UniversalCoord pickOrigin;
Vec3f pickDir;
float maxDistance;
const Star* closestStar;
float closestDistance;
float cosAngleClosest;
};
CloseStarPicker::CloseStarPicker(const UniversalCoord& pos,
const Vec3f& dir,
float _maxDistance,
float angle) :
pickOrigin(pos),
pickDir(dir),
maxDistance(_maxDistance),
closestStar(NULL),
closestDistance(0.0f),
cosAngleClosest((float) cos(angle))
{
}
void CloseStarPicker::process(const Star& star,
float lowPrecDistance,
float appMag)
{
if (lowPrecDistance > maxDistance)
return;
// Ray-sphere intersection
Vec3f starDir = (star.getPosition() - pickOrigin) *
astro::lightYearsToKilometers(1.0f);
float v = starDir * pickDir;
float disc = square(star.getRadius()) - ((starDir * starDir) - square(v));
if (disc > 0.0f)
{
float distance = v - (float) sqrt(disc);
if (distance > 0.0)
{
if (closestStar == NULL || distance < closestDistance)
{
closestStar = &star;
closestDistance = starDir.length();
cosAngleClosest = 1.0f; // An exact hit--set the angle to zero
}
}
}
else
{
// We don't have an exact hit; check to see if we're close enough
float distance = starDir.length();
starDir *= (1.0f / distance);
float cosAngle = starDir * pickDir;
if (cosAngle > cosAngleClosest &&
(closestStar == NULL || distance < closestDistance))
{
closestStar = &star;
closestDistance = distance;
cosAngleClosest = cosAngle;
}
}
}
Selection Simulation::pickStar(Vec3f pickRay)
{
float angle = degToRad(0.5f);
// Transform the pick direction
pickRay = pickRay * observer.getOrientation().toMatrix4();
// Use a high precision pick test for any stars that are close to the
// observer. If this test fails, use a low precision pick test for stars
// which are further away. All this work is necessary because the low
// precision pick test isn't reliable close to a star and the high
// precision test isn't nearly fast enough to use on our database of
// over 100k stars.
CloseStarPicker closePicker(observer.getPosition(), pickRay, 1.0f, angle);
stardb->findCloseStars(closePicker, (Point3f) observer.getPosition(),1.0f);
if (closePicker.closestStar != NULL)
return Selection(const_cast<Star*>(closePicker.closestStar));
StarPicker picker((Point3f) observer.getPosition(), pickRay, angle);
stardb->findVisibleStars(picker,
(Point3f) observer.getPosition(),
observer.getOrientation(),
angle, 1.0f,
faintestVisible);
if (picker.pickedStar != NULL)
return Selection(const_cast<Star*>(picker.pickedStar));
else
return Selection();
}
Selection Simulation::pickObject(Vec3f pickRay)
{
Selection sel;
if (closestSolarSystem != NULL)
{
const Star* sun = closestSolarSystem->getPlanets()->getStar();
if (sun != NULL)
sel = pickPlanet(observer, *sun, *closestSolarSystem, pickRay);
}
if (sel.empty())
sel = pickStar(pickRay);
return sel;
return universe->pick(observer.getPosition(),
pickRay * observer.getOrientation().toMatrix4(),
simTime,
faintestVisible);
}
@ -1180,10 +865,16 @@ void Simulation::track()
void Simulation::selectStar(uint32 catalogNo)
{
selection = Selection(stardb->find(catalogNo));
StarDatabase* stardb = universe->getStarCatalog();
if (stardb != NULL)
selection = Selection(stardb->find(catalogNo));
}
// Choose a planet around a star given it's index in the planetary system.
// The planetary system is either the system of the selected object, or the
// nearest planetary system if no object is selected. If index is less than
// zero, pick the star. This function should probably be in celestiacore.cpp.
void Simulation::selectPlanet(int index)
{
if (index < 0)
@ -1199,22 +890,21 @@ void Simulation::selectPlanet(int index)
{
const Star* star = NULL;
if (selection.star != NULL)
{
star = selection.star;
}
else if (selection.body != NULL)
{
star = getSun(selection.body);
}
SolarSystem* solarSystem = NULL;
if (star != NULL)
solarSystem = getSolarSystem(star);
solarSystem = universe->getSolarSystem(star);
else
solarSystem = closestSolarSystem;
if (solarSystem != NULL && index < solarSystem->getPlanets()->getSystemSize())
if (solarSystem != NULL &&
index < solarSystem->getPlanets()->getSystemSize())
{
selection = Selection(solarSystem->getPlanets()->getBody(index));
}
}
}
@ -1227,52 +917,27 @@ void Simulation::selectPlanet(int index)
// 4. Search the planets and moons in any 'nearby' (< 0.1 ly) planetary systems
Selection Simulation::findObject(string s)
{
Star* star = stardb->find(s);
if (star != NULL)
return Selection(star);
PlanetarySystem* path[2];
int nPathEntries = 0;
if (galaxies != NULL)
if (selection.star != NULL)
{
for (GalaxyList::const_iterator iter = galaxies->begin();
iter != galaxies->end(); iter++)
{
if ((*iter)->getName() == s)
return Selection(*iter);
}
SolarSystem* sys = universe->getSolarSystem(selection.star);
if (sys != NULL)
path[nPathEntries++] = sys->getPlanets();
}
else if (selection.body != NULL)
{
const PlanetarySystem* solarSystem = NULL;
if (selection.star != NULL)
{
SolarSystem* sys = getSolarSystem(selection.star);
if (sys != NULL)
solarSystem = sys->getPlanets();
}
else if (selection.body != NULL)
{
solarSystem = selection.body->getSystem();
while (solarSystem != NULL && solarSystem->getPrimaryBody() != NULL)
solarSystem = solarSystem->getPrimaryBody()->getSystem();
}
if (solarSystem != NULL)
{
Body* body = solarSystem->find(s, true);
if (body != NULL)
return Selection(body);
}
if (closestSolarSystem != NULL)
{
Body* body = closestSolarSystem->getPlanets()->find(s, true);
if (body != NULL)
return Selection(body);
}
PlanetarySystem* sys = selection.body->getSystem();
while (sys != NULL && sys->getPrimaryBody() != NULL)
sys = sys->getPrimaryBody()->getSystem();
path[nPathEntries++] = sys;
}
return Selection();
if (closestSolarSystem != NULL)
path[nPathEntries++] = closestSolarSystem->getPlanets();
return universe->find(s, path, nPathEntries);
}
@ -1281,60 +946,27 @@ Selection Simulation::findObject(string s)
// paths that contain galaxies.
Selection Simulation::findObjectFromPath(string s)
{
string::size_type pos = s.find('/', 0);
PlanetarySystem* path[2];
int nPathEntries = 0;
if (pos == string::npos)
return findObject(s);
string base(s, 0, pos);
Selection sel = findObject(base);
if (sel.empty())
return sel;
// Don't support paths relative to a galaxy . . . for now.
if (sel.galaxy != NULL)
return Selection();
const PlanetarySystem* worlds = NULL;
if (sel.body != NULL)
if (selection.star != NULL)
{
worlds = sel.body->getSatellites();
SolarSystem* sys = universe->getSolarSystem(selection.star);
if (sys != NULL)
path[nPathEntries++] = sys->getPlanets();
}
else if (sel.star != NULL)
else if (selection.body != NULL)
{
SolarSystem* ssys = getSolarSystem(sel.star);
if (ssys != NULL)
worlds = ssys->getPlanets();
PlanetarySystem* sys = selection.body->getSystem();
while (sys != NULL && sys->getPrimaryBody() != NULL)
sys = sys->getPrimaryBody()->getSystem();
path[nPathEntries++] = sys;
}
while (worlds != NULL)
{
string::size_type nextPos = s.find('/', pos + 1);
string::size_type len;
if (nextPos == string::npos)
len = s.size() - pos - 1;
else
len = nextPos - pos - 1;
if (closestSolarSystem != NULL)
path[nPathEntries++] = closestSolarSystem->getPlanets();
string name = string(s, pos + 1, len);
Body* body = worlds->find(name);
if (body == NULL)
{
return Selection();
}
else if (nextPos == string::npos)
{
return Selection(body);
}
else
{
worlds = body->getSatellites();
pos = nextPos;
}
}
return Selection();
return universe->findPath(s, path, nPathEntries);
}

View File

@ -16,8 +16,7 @@
#include <celmath/quaternion.h>
#include <celengine/texture.h>
#include <celengine/mesh.h>
#include <celengine/stardb.h>
#include <celengine/solarsys.h>
#include <celengine/universe.h>
#include <celengine/astro.h>
#include <celengine/galaxy.h>
#include <celengine/texmanager.h>
@ -60,7 +59,7 @@ struct RigidTransform
class Simulation
{
public:
Simulation();
Simulation(Universe*);
~Simulation();
double getTime() const; // Time in seconds
@ -71,11 +70,7 @@ class Simulation
Selection pickObject(Vec3f pickRay);
StarDatabase* getStarDatabase() const;
SolarSystemCatalog* getSolarSystemCatalog() const;
void setStarDatabase(StarDatabase* db,
SolarSystemCatalog* catalog,
GalaxyList*);
Universe* getUniverse() const;
Observer& getObserver();
@ -147,11 +142,6 @@ class Simulation
private:
SolarSystem* getSolarSystem(const Star* star);
Selection pickPlanet(Observer& observer,
const Star& sun,
SolarSystem& solarSystem,
Vec3f pickRay);
Selection pickStar(Vec3f pickRay);
void computeGotoParameters(Selection& sel,
JourneyParams& jparams,
double gotoTime,
@ -166,9 +156,7 @@ class Simulation
double simTime;
double timeScale;
StarDatabase* stardb;
SolarSystemCatalog* solarSystemCatalog;
GalaxyList* galaxies;
Universe* universe;
SolarSystem* closestSolarSystem;
Star* selectedStar;

View File

@ -76,7 +76,7 @@ void Universe::setAsterisms(AsterismList* _asterisms)
// Return the planetary system of a star, or NULL if it has no planets.
SolarSystem* Universe::getSolarSystem(const Star* star)
SolarSystem* Universe::getSolarSystem(const Star* star) const
{
if (star == NULL)
return NULL;
@ -128,7 +128,7 @@ struct PlanetPickInfo
double jd;
};
bool ApproxPlanetPickTraversal(Body* body, void* info)
static bool ApproxPlanetPickTraversal(Body* body, void* info)
{
PlanetPickInfo* pickInfo = (PlanetPickInfo*) info;
@ -147,7 +147,7 @@ bool ApproxPlanetPickTraversal(Body* body, void* info)
// Perform an intersection test between the pick ray and a body
bool ExactPlanetPickTraversal(Body* body, void* info)
static bool ExactPlanetPickTraversal(Body* body, void* info)
{
PlanetPickInfo* pickInfo = (PlanetPickInfo*) info;
@ -342,11 +342,33 @@ Selection Universe::pickStar(const UniversalCoord& origin,
starCatalog->findCloseStars(closePicker, (Point3f) origin, 1.0f);
if (closePicker.closestStar != NULL)
return Selection(const_cast<Star*>(closePicker.closestStar));
// Find visible stars expects an orientation, but we just have a direction
// vector. Convert the direction vector into an orientation by computing
// the rotation required to map (0, 0, -1) to the direction.
Quatf rotation;
Vec3f n(0, 0, -1);
float epsilon = 1.0e-6f;
float cosAngle = n * direction;
if (cosAngle > 1.0f - epsilon)
{
rotation.setAxisAngle(Vec3f(1, 0, 0), 0);
}
else if (cosAngle < epsilon - 1.0f)
{
rotation.setAxisAngle(Vec3f(1, 0, 0), (float) PI);
}
else
{
Vec3f axis = direction ^ n;
axis.normalize();
rotation.setAxisAngle(axis, (float) acos(cosAngle));
}
StarPicker picker((Point3f) origin, direction, angle);
starCatalog->findVisibleStars(picker,
(Point3f) origin,
Quatf(1.0f), // observer.getOrientation(),
rotation,
angle, 1.0f,
faintestMag);
if (picker.pickedStar != NULL)
@ -486,7 +508,7 @@ Selection Universe::findPath(const string& s,
// Return the closest solar system to position, or NULL if there are no planets
// with in one light year.
SolarSystem* Universe::getNearestSolarSystem(const UniversalCoord& position)
SolarSystem* Universe::getNearestSolarSystem(const UniversalCoord& position) const
{
ClosestStarFinder closestFinder(1.0f);
starCatalog->findCloseStars(closestFinder, (Point3f) position, 1.0f);

View File

@ -12,12 +12,12 @@
#include <celmath/vecmath.h>
#include <celmath/quaternion.h>
#include <celengine/univcoord.h>
#include <celengine/stardb.h>
#include <celengine/solarsys.h>
#include <celengine/galaxy.h>
#include <celengine/asterism.h>
#include <celengine/selection.h>
#include <celengine/univcoord.h>
#include <celengine/render.h>
class Universe
@ -35,12 +35,11 @@ class Universe
AsterismList* getAsterisms() const;
void setAsterisms(AsterismList*);
void render(Renderer&);
Selection pick(const UniversalCoord& origin,
const Vec3f& direction,
double when,
float faintestMag);
Selection pickStar(const UniversalCoord&, const Vec3f&, float faintest);
Selection find(const std::string& s,
PlanetarySystem** solarSystems = NULL,
int nSolarSystems = 0);
@ -48,16 +47,15 @@ class Universe
PlanetarySystem** solarSystems = NULL,
int nSolarSystems = 0);
SolarSystem* getNearestSolarSystem(const UniversalCoord& position);
SolarSystem* getNearestSolarSystem(const UniversalCoord& position) const;
SolarSystem* getSolarSystem(const Star* star) const;
private:
SolarSystem* getSolarSystem(const Star* star);
Selection pickPlanet(SolarSystem& solarSystem,
const UniversalCoord&,
const Vec3f&,
double when,
float faintestMag);
Selection pickStar(const UniversalCoord&, const Vec3f&, float faintest);
private:
StarDatabase* starCatalog;

View File

@ -25,9 +25,6 @@
#include <celmath/quaternion.h>
#include <celmath/mathlib.h>
#include <celutil/util.h>
#include <celengine/stardb.h>
#include <celengine/solarsys.h>
#include <celengine/asterism.h>
#include <celengine/astro.h>
#include <celengine/overlay.h>
#include <celengine/execution.h>
@ -86,10 +83,7 @@ public:
CelestiaCore::CelestiaCore() :
config(NULL),
starDB(NULL),
solarSystemCatalog(NULL),
galaxies(NULL),
asterisms(NULL),
universe(NULL),
favorites(NULL),
destinations(NULL),
sim(NULL),
@ -962,7 +956,7 @@ static void displayStarNames(Overlay& overlay,
static void displayStarInfo(Overlay& overlay,
int detail,
Star& star,
SolarSystemCatalog& solarSystems,
const Universe& universe,
double distance)
{
overlay << "Distance: ";
@ -978,9 +972,13 @@ static void displayStarInfo(Overlay& overlay,
overlay << "Surface Temp: " << star.getTemperature() << " K\n";
overlay.printf("Radius: %.2f Rsun\n", star.getRadius() / 696000.0f);
SolarSystemCatalog::iterator iter = solarSystems.find(star.getCatalogNumber());
if (iter != solarSystems.end())
overlay << "Planetary companions present\n";
SolarSystemCatalog* solarSystems = universe.getSolarSystemCatalog();
if (solarSystems != NULL)
{
SolarSystemCatalog::iterator iter = solarSystems->find(star.getCatalogNumber());
if (iter != solarSystems->end())
overlay << "Planetary companions present\n";
}
}
}
@ -1188,13 +1186,13 @@ void CelestiaCore::renderOverlay()
overlay->setFont(titleFont);
displayStarNames(*overlay,
*sel.star,
*(sim->getStarDatabase()));
*(sim->getUniverse()->getStarCatalog()));
overlay->setFont(font);
*overlay << '\n';
displayStarInfo(*overlay,
hudDetail,
*sel.star,
*(sim->getSolarSystemCatalog()),
*(sim->getUniverse()),
v.length());
}
else if (sel.body != NULL)
@ -1374,14 +1372,16 @@ bool CelestiaCore::initSimulation()
if (favorites == NULL)
favorites = new FavoritesList();
universe = new Universe();
if (!readStars(*config))
{
fatalError("Cannot read star database.");
return false;
}
solarSystemCatalog = new SolarSystemCatalog();
{
SolarSystemCatalog* solarSystemCatalog = new SolarSystemCatalog();
for (vector<string>::const_iterator iter = config->solarSystemFiles.begin();
iter != config->solarSystemFiles.end();
iter++)
@ -1393,9 +1393,12 @@ bool CelestiaCore::initSimulation()
}
else
{
ReadSolarSystems(solarSysFile, *starDB, *solarSystemCatalog);
ReadSolarSystems(solarSysFile,
*(universe->getStarCatalog()),
*solarSystemCatalog);
}
}
universe->setSolarSystemCatalog(solarSystemCatalog);
}
if (config->galaxyCatalog != "")
@ -1407,7 +1410,8 @@ bool CelestiaCore::initSimulation()
}
else
{
galaxies = ReadGalaxyList(galaxiesFile);
GalaxyList* galaxies = ReadGalaxyList(galaxiesFile);
universe->setGalaxyCatalog(galaxies);
}
}
@ -1420,7 +1424,9 @@ bool CelestiaCore::initSimulation()
}
else
{
asterisms = ReadAsterismList(asterismsFile, *starDB);
AsterismList* asterisms = ReadAsterismList(asterismsFile,
*universe->getStarCatalog());
universe->setAsterisms(asterisms);
}
}
@ -1460,8 +1466,7 @@ bool CelestiaCore::initSimulation()
}
}
sim = new Simulation();
sim->setStarDatabase(starDB, solarSystemCatalog, galaxies);
sim = new Simulation(universe);
sim->setFaintestVisible(config->faintestVisible);
return true;
@ -1493,7 +1498,7 @@ bool CelestiaCore::initRenderer()
iter != config->labelledStars.end();
iter++)
{
Star* star = starDB->find(*iter);
Star* star = universe->getStarCatalog()->find(*iter);
if (star != NULL)
renderer->addLabelledStar(star);
}
@ -1501,8 +1506,6 @@ bool CelestiaCore::initRenderer()
renderer->setBrightnessBias(0.1f);
renderer->setSaturationMagnitude(1.0f);
renderer->showAsterisms(asterisms);
if (config->mainFont == "")
font = LoadTextureFont("fonts/default.txf");
else
@ -1568,7 +1571,7 @@ bool CelestiaCore::readStars(const CelestiaConfig& cfg)
return false;
}
starDB = StarDatabase::read(starFile);
StarDatabase* starDB = StarDatabase::read(starFile);
if (starDB == NULL)
{
cerr << "Error reading stars file\n";
@ -1584,6 +1587,8 @@ bool CelestiaCore::readStars(const CelestiaConfig& cfg)
starDB->setNameDatabase(starNameDB);
universe->setStarCatalog(starDB);
return true;
}

View File

@ -17,6 +17,7 @@
#include <celengine/command.h>
#include <celengine/execution.h>
#include <celengine/texture.h>
#include <celengine/universe.h>
#include <celengine/render.h>
#include <celengine/simulation.h>
#include "configfile.h"
@ -161,10 +162,8 @@ class CelestiaCore
private:
CelestiaConfig* config;
StarDatabase* starDB;
SolarSystemCatalog* solarSystemCatalog;
GalaxyList* galaxies;
AsterismList* asterisms;
Universe* universe;
FavoritesList* favorites;
DestinationList* destinations;

View File

@ -785,13 +785,13 @@ VOID APIENTRY handlePopupMenu(HWND hwnd,
else if (sel.star != NULL)
{
Simulation* sim = appCore->getSimulation();
name = sim->getStarDatabase()->getStarName(*sel.star);
name = sim->getUniverse()->getStarCatalog()->getStarName(*sel.star);
AppendMenu(hMenu, MF_STRING, ID_NAVIGATION_CENTER, name.c_str());
AppendMenu(hMenu, MF_SEPARATOR, 0, 0);
AppendMenu(hMenu, MF_STRING, ID_NAVIGATION_GOTO, "&Goto");
AppendMenu(hMenu, MF_STRING, ID_INFO, "&Info");
SolarSystemCatalog* solarSystemCatalog = sim->getSolarSystemCatalog();
SolarSystemCatalog* solarSystemCatalog = sim->getUniverse()->getSolarSystemCatalog();
SolarSystemCatalog::iterator iter = solarSystemCatalog->find(sel.star->getCatalogNumber());
if (iter != solarSystemCatalog->end())
{

View File

@ -206,9 +206,9 @@ bool InitStarBrowserLVItems(HWND listView, vector<const Star*>& stars)
bool InitStarBrowserItems(HWND listView, StarBrowser* browser)
{
Simulation* sim = browser->appCore->getSimulation();
StarDatabase* stardb = browser->appCore->getSimulation()->getStarDatabase();
SolarSystemCatalog* solarSystems = browser->appCore->getSimulation()->getSolarSystemCatalog();
Universe* univ = browser->appCore->getSimulation()->getUniverse();
StarDatabase* stardb = univ->getStarCatalog();
SolarSystemCatalog* solarSystems = univ->getSolarSystemCatalog();
vector<const Star*>* stars = NULL;
switch (browser->predicate)
@ -326,8 +326,8 @@ void StarBrowserDisplayItem(LPNMLVDISPINFOA nm, StarBrowser* browser)
{
case 0:
{
Simulation* sim = browser->appCore->getSimulation();
starNameString = sim->getStarDatabase()->getStarName(*star);
Universe* u = browser->appCore->getSimulation()->getUniverse();
starNameString = u->getStarCatalog()->getStarName(*star);
nm->item.pszText = const_cast<char*>(starNameString.c_str());
}
break;