Added galaxies.

This commit is contained in:
Chris Laurel 2001-04-20 04:25:27 +00:00
parent ae19fac4bc
commit b16e2b37dc
5 changed files with 71 additions and 20 deletions

View file

@ -52,8 +52,6 @@ static CTexture* veilTex = NULL;
static TexFont* font = NULL;
static GalaxyList galaxies;
Renderer::Renderer() :
windowWidth(0),
@ -249,6 +247,7 @@ bool Renderer::init(int winWidth, int winHeight)
commonDataInitialized = true;
}
#if 0
{
Galaxy* g = new Galaxy();
g->setName("Milky Way");
@ -281,6 +280,7 @@ bool Renderer::init(int winWidth, int winHeight)
g->setType(Galaxy::Irr);
galaxies.insert(galaxies.end(), g);
}
#endif
cout << "GL extensions supported:\n";
cout << glGetString(GL_EXTENSIONS) << '\n';
@ -485,6 +485,7 @@ void Renderer::render(const Observer& observer,
const StarDatabase& starDB,
const VisibleStarSet& visset,
SolarSystem* solarSystem,
GalaxyList* galaxies,
const Selection& sel,
double now)
{
@ -532,7 +533,8 @@ void Renderer::render(const Observer& observer,
clearLabels();
renderList.clear();
renderGalaxies(galaxies, observer);
if (galaxies != NULL)
renderGalaxies(*galaxies, observer);
// Translate the camera before rendering the stars
glPushMatrix();
@ -1673,7 +1675,7 @@ void Renderer::renderPlanetarySystem(const Star& sun,
Mat4d newFrame = Mat4d::xrotation(-body->getObliquity()) * Mat4d::translation(localPos) * frame;
Point3d bodyPos = Point3d(0, 0, 0) * newFrame;
bodyPos = body->getHeliocentricPosition(now);
double distanceFromSun = bodyPos.distanceTo(Point3d(0, 0, 0));
double distanceFromSun = bodyPos.distanceFromOrigin();
// We now have the positions of the observer and the planet relative
// to the sun. From these, compute the position of the planet
@ -1868,7 +1870,7 @@ void Renderer::renderGalaxies(const GalaxyList& galaxies,
Point3f offset = Point3f((float) (observerPos.x - pos.x),
(float) (observerPos.y - pos.y),
(float) (observerPos.z - pos.z));
float distanceToGalaxy = offset.distanceTo(Point3f(0, 0, 0)) - radius;
float distanceToGalaxy = offset.distanceFromOrigin() - radius;
if (distanceToGalaxy < 0)
distanceToGalaxy = 0;
float minimumFeatureSize = pixelSize * distanceToGalaxy;
@ -1880,14 +1882,17 @@ void Renderer::renderGalaxies(const GalaxyList& galaxies,
glTranslate(Point3f(0, 0, 0) - offset);
Mat4f m = (galaxy->getOrientation().toMatrix4() *
Mat4f::scaling(form->scale) *
Mat4f::scaling(radius));
float size = radius;
int pow2 = 1;
vector<Point3f>* points = form->points;
glBegin(GL_QUADS);
for (int i = 0; i < form->size(); i++)
for (int i = 0; i < points->size(); i++)
{
Point3f p = (*form)[i] * m;
Point3f p = (*points)[i] * m;
Vec3f relPos = p - offset;
if ((i & pow2) != 0)
@ -1896,7 +1901,7 @@ void Renderer::renderGalaxies(const GalaxyList& galaxies,
size /= 1.5f;
if (size < minimumFeatureSize)
{
cout << galaxy->getName() << ": Quitting after " << i << " particles.\n";
// cout << galaxy->getName() << ": Quitting after " << i << " particles.\n";
break;
}
}

View file

@ -43,6 +43,7 @@ class Renderer
const StarDatabase&,
const VisibleStarSet&,
SolarSystem*,
GalaxyList*,
const Selection& sel,
double now);

View file

@ -13,20 +13,22 @@
class Selection
{
public:
Selection() : star(NULL), body(NULL) {};
Selection(Star* _star) : star(_star), body(NULL) {};
Selection(Body* _body) : star(NULL), body(_body) {};
Selection() : star(NULL), body(NULL), galaxy(NULL) {};
Selection(Star* _star) : star(_star), body(NULL), galaxy(NULL) {};
Selection(Body* _body) : star(NULL), body(_body), galaxy(NULL) {};
Selection(Galaxy* _galaxy) : star(NULL), body(NULL), galaxy(_galaxy) {};
~Selection() {};
bool empty() { return star == NULL && body == NULL; };
bool empty() { return star == NULL && body == NULL && galaxy == NULL; };
Star* star;
Body* body;
Galaxy* galaxy;
};
inline bool operator==(const Selection& s0, const Selection& s1)
{
return s0.star == s1.star && s0.body == s1.body;
return s0.star == s1.star && s0.body == s1.body && s0.galaxy == s1.galaxy;
}
#endif // _SELECTION_H_

View file

@ -29,6 +29,7 @@ Simulation::Simulation() :
timeScale(1.0),
stardb(NULL),
solarSystemCatalog(NULL),
galaxies(NULL),
visibleStars(NULL),
closestSolarSystem(NULL),
selection(),
@ -110,6 +111,18 @@ static void displayPlanetInfo(Console& console,
}
static void displayGalaxyInfo(Console& console,
Galaxy& galaxy,
double distance)
{
console << galaxy.getName() << '\n';
console << "Distance: ";
displayDistance(console, distance);
console << '\n';
console << "Radius: " << galaxy.getRadius() << " ly\n";
}
void Simulation::displaySelectionInfo(Console& console)
{
if (selection.empty())
@ -120,6 +133,8 @@ void Simulation::displaySelectionInfo(Console& console)
displayStarInfo(console, *selection.star, *stardb, v.length());
else if (selection.body != NULL)
displayPlanetInfo(console, *selection.body, v.length());
else if (selection.galaxy != NULL)
displayGalaxyInfo(console, *selection.galaxy, v.length());
}
@ -139,6 +154,7 @@ void Simulation::render(Renderer& renderer)
*stardb,
*visibleStars,
closestSolarSystem,
galaxies,
selection,
simTime);
}
@ -193,6 +209,12 @@ UniversalCoord Simulation::getSelectionPosition(Selection& sel, double when)
{
return astro::universalPosition(Point3d(0.0, 0.0, 0.0), sel.star->getPosition());
}
else if (sel.galaxy != NULL)
{
Point3d p = sel.galaxy->getPosition();
return astro::universalPosition(Point3d(0.0, 0.0, 0.0),
Point3f((float) p.x, (float) p.y, (float) p.z));
}
else
{
return UniversalCoord(Point3d(0.0, 0.0, 0.0));
@ -206,16 +228,20 @@ float getSelectionSize(Selection& sel)
return sel.body->getRadius();
else if (sel.star != NULL)
return sel.star->getRadius();
else if (sel.galaxy != NULL)
return sel.galaxy->getRadius();
else
return 0.0f;
}
void Simulation::setStarDatabase(StarDatabase* db,
SolarSystemCatalog* catalog)
SolarSystemCatalog* catalog,
GalaxyList* galaxyList)
{
stardb = db;
solarSystemCatalog = catalog;
galaxies = galaxyList;
if (visibleStars != NULL)
{
@ -596,7 +622,7 @@ void Simulation::rotate(Quatf q)
// both the observer's position and orientation.
void Simulation::orbit(Quatf q)
{
if (selection.body != NULL || selection.star != NULL)
if (!selection.empty())
{
UniversalCoord focusPosition = getSelectionPosition(selection, simTime);
Vec3d v = observer.getPosition() - focusPosition;
@ -641,7 +667,7 @@ void Simulation::orbit(Quatf q)
// at a rate dependent on the observer's distance from the object.
void Simulation::changeOrbitDistance(float d)
{
if (selection.body != NULL || selection.star != NULL)
if (!selection.empty())
{
UniversalCoord focusPosition = getSelectionPosition(selection, simTime);
double size = getSelectionSize(selection);
@ -689,7 +715,7 @@ float Simulation::getTargetSpeed()
void Simulation::gotoSelection(double gotoTime)
{
if (selection.body != NULL || selection.star != NULL)
if (!selection.empty())
{
computeGotoParameters(selection, journey, gotoTime);
observerMode = Travelling;
@ -703,7 +729,7 @@ void Simulation::cancelMotion()
void Simulation::centerSelection(double centerTime)
{
if (selection.body != NULL || selection.star != NULL)
if (!selection.empty())
{
computeCenterParameters(selection, journey, centerTime);
observerMode = Travelling;
@ -788,8 +814,22 @@ void Simulation::selectBody(string s)
if (star != NULL)
{
selectStar(star->getCatalogNumber());
return;
}
else
if (galaxies != NULL)
{
for (GalaxyList::const_iterator iter = galaxies->begin();
iter != galaxies->end(); iter++)
{
if ((*iter)->getName() == s)
{
selection = Selection(*iter);
return;
}
}
}
{
const PlanetarySystem* solarSystem = NULL;

View file

@ -20,6 +20,7 @@
#include "stardb.h"
#include "visstars.h"
#include "solarsys.h"
#include "galaxy.h"
#include "texmanager.h"
#include "render.h"
@ -39,7 +40,8 @@ class Simulation
Selection pickObject(Vec3f pickRay);
void setStarDatabase(StarDatabase* db,
SolarSystemCatalog* catalog);
SolarSystemCatalog* catalog,
GalaxyList*);
Observer& getObserver();
@ -122,6 +124,7 @@ class Simulation
StarDatabase* stardb;
SolarSystemCatalog* solarSystemCatalog;
GalaxyList* galaxies;
VisibleStarSet* visibleStars;
SolarSystem* closestSolarSystem;