#include <fstream>#include <algorithm>#include <cstdio>#include <cassert>#include "celestia.h"#include <celmath/mathlib.h>#include <celmath/perlin.h>#include "astro.h"#include "galaxy.h"#include <celutil/util.h>#include <celutil/debug.h>#include "gl.h"#include "vecgl.h"#include "render.h"#include "texture.h"Include dependency graph for galaxy.cpp:

Go to the source code of this file.
Functions | |
| GalacticForm * | buildGalacticForms (const std::string &filename) |
| static void | GalaxyTextureEval (float u, float v, float w, unsigned char *pixel) |
| static void | InitializeForms () |
| ostream & | operator<< (ostream &s, const Galaxy::GalaxyType &sc) |
Variables | |
| static Color | colorTable [256] |
| static GalacticForm ** | ellipticalForms = NULL |
| static bool | formsInitialized = false |
| static const unsigned int | GALAXY_POINTS = 7000 |
| static Texture * | galaxyTex = NULL |
| static GalaxyTypeName | GalaxyTypeNames [] |
| static GalacticForm * | irregularForm = NULL |
| static GalacticForm ** | spiralForms = NULL |
|
|
Definition at line 465 of file galaxy.cpp. References GalacticForm::blobs, Blob::brightness, Blob::colorIndex, Point3< T >::distanceFromOrigin(), GALAXY_POINTS, Blob::position, and GalacticForm::scale. Referenced by InitializeForms(). 00466 {
00467 unsigned int galaxySize = GALAXY_POINTS;
00468 Blob b;
00469 vector<Blob>* galacticPoints = new vector<Blob>;
00470 galacticPoints->reserve(galaxySize);
00471
00472 ifstream inFile(filename.c_str());
00473 while (inFile.good())
00474 {
00475 float x, y, z, br;
00476 inFile >> x;
00477 inFile >> y;
00478 inFile >> z;
00479 inFile >> br;
00480
00481 b.position = Point3f(x, y, z);
00482 b.brightness = br;
00483 b.colorIndex = (unsigned int) (b.position.distanceFromOrigin() * 255);
00484
00485 galacticPoints->push_back(b);
00486 }
00487
00488 GalacticForm* galacticForm = new GalacticForm();
00489 galacticForm->blobs = galacticPoints;
00490 galacticForm->scale = Vec3f(1.0f, 1.0f, 1.0f);
00491
00492 return galacticForm;
00493 };
|
|
||||||||||||||||||||
|
Definition at line 72 of file galaxy.cpp. References sqrt(). Referenced by Galaxy::renderGalaxyPointSprites(). 00074 {
00075 float r = 0.9f - (float) sqrt(u * u + v * v);
00076 if (r < 0)
00077 r = 0;
00078
00079 int pixVal = (int) (r * 255.99f);
00080 pixel[0] = 255;//65;
00081 pixel[1] = 255;//64;
00082 pixel[2] = 255;//65;
00083 pixel[3] = pixVal;
00084 }
|
|
|
Definition at line 496 of file galaxy.cpp. References GalacticForm::blobs, Blob::brightness, buildGalacticForms(), Blob::colorIndex, colorTable, Point3< T >::distanceFromOrigin(), ellipticalForms, formsInitialized, fractalsum(), GALAXY_POINTS, Galaxy::hsv2rgb(), irregularForm, Blob::position, GalacticForm::scale, spiralForms, Point3< T >::x, Point3< T >::y, and Point3< T >::z. Referenced by Galaxy::setType(). 00497 {
00498 unsigned int i = 0;
00499
00500 // build color table:
00501 for (i = 0; i < 256; ++i)
00502 {
00503 float rr,gg,bb;
00504 float rho = (float) i / 255.0f;
00505 // generic Hue profile as deduced from true-color imaging for spirals
00506 float h = 30.0f * (float) tanh(15.68 * (0.1086 - rho));
00507 if (rho > 0.1086f)
00508 h += 260.0f;
00509 //convert Hue to RGB
00510 Galaxy::hsv2rgb( &rr, &gg, &bb, h , 0.15f, 1.0f);
00511 colorTable[i] = Color( rr,gg,bb);
00512 }
00513 // Spiral Galaxies, 7 classical Hubble types
00514
00515 spiralForms = new GalacticForm*[7];
00516
00517 spiralForms[Galaxy::S0] = buildGalacticForms("models/S0.pts");
00518 spiralForms[Galaxy::Sa] = buildGalacticForms("models/Sa.pts");
00519 spiralForms[Galaxy::Sb] = buildGalacticForms("models/Sb.pts");
00520 spiralForms[Galaxy::Sc] = buildGalacticForms("models/Sc.pts");
00521 spiralForms[Galaxy::SBa] = buildGalacticForms("models/SBa.pts");
00522
00523 spiralForms[Galaxy::SBb] = buildGalacticForms("models/SBb.pts");
00524 spiralForms[Galaxy::SBc] = buildGalacticForms("models/SBc.pts");
00525
00526 // Elliptical Galaxies , 8 classical Hubble types, E0..E7,
00527 //
00528 // To save space: generate spherical E0 template from S0 disk
00529 // via rescaling by (1.0f, 3.8f, 1.0f).
00530
00531 ellipticalForms = new GalacticForm*[8];
00532
00533 for (unsigned int eform = 0; eform <= 7; ++eform)
00534 {
00535 float ell = 1.0f - (float) eform / 8.0f;
00536 ellipticalForms[eform] = new GalacticForm();
00537 ellipticalForms[eform]->blobs = spiralForms[Galaxy::S0]->blobs;
00538 // note the correct x,y-alignment of 'ell' scaling!!
00539 ellipticalForms[eform]->scale = Vec3f(ell, 3.8*ell, 1.0f);
00540 }
00541
00542 //Irregular Galaxies
00543 unsigned int galaxySize = GALAXY_POINTS;
00544 Blob b;
00545 Point3f p;
00546
00547
00548 vector<Blob>* irregularPoints = new vector<Blob>;
00549 irregularPoints->reserve(galaxySize);
00550
00551 i = 0;
00552 while (i < galaxySize)
00553 {
00554 p = Point3f(Mathf::sfrand(), Mathf::sfrand(), Mathf::sfrand());
00555 float r = p.distanceFromOrigin();
00556 if (r < 1)
00557 {
00558 float prob = (1 - r) * (fractalsum(Point3f(p.x + 5, p.y + 5, p.z + 5), 8) + 1) * 0.5f;
00559 if (Mathf::frand() < prob)
00560 {
00561 b.position = p;
00562 b.brightness = 1.0f;
00563 b.colorIndex = (unsigned int) (r*255);
00564 irregularPoints->push_back(b);
00565 ++i;
00566 }
00567 }
00568 }
00569 irregularForm = new GalacticForm();
00570 irregularForm->blobs = irregularPoints;
00571 irregularForm->scale = Vec3f(1.0f, 0.1f, 1.0f);
00572
00573 formsInitialized = true;
00574 }
|
|
||||||||||||
|
Definition at line 577 of file galaxy.cpp. 00578 {
00579 return s << GalaxyTypeNames[static_cast<int>(sc)].name;
00580 }
|
|
|
Definition at line 28 of file galaxy.cpp. Referenced by InitializeForms(), and Galaxy::renderGalaxyPointSprites(). |
|
|
Definition at line 35 of file galaxy.cpp. Referenced by InitializeForms(), and Galaxy::setType(). |
|
|
Definition at line 32 of file galaxy.cpp. Referenced by InitializeForms(), and Galaxy::setType(). |
|
|
Definition at line 30 of file galaxy.cpp. Referenced by buildGalacticForms(), and InitializeForms(). |
|
|
Definition at line 38 of file galaxy.cpp. Referenced by Galaxy::renderGalaxyPointSprites(). |
|
|
Initial value:
{
{ "S0", Galaxy::S0 },
{ "Sa", Galaxy::Sa },
{ "Sb", Galaxy::Sb },
{ "Sc", Galaxy::Sc },
{ "SBa", Galaxy::SBa },
{ "SBb", Galaxy::SBb },
{ "SBc", Galaxy::SBc },
{ "E0", Galaxy::E0 },
{ "E1", Galaxy::E1 },
{ "E2", Galaxy::E2 },
{ "E3", Galaxy::E3 },
{ "E4", Galaxy::E4 },
{ "E5", Galaxy::E5 },
{ "E6", Galaxy::E6 },
{ "E7", Galaxy::E7 },
{ "Irr", Galaxy::Irr },
}
Definition at line 51 of file galaxy.cpp. Referenced by Galaxy::getType(), and Galaxy::setType(). |
|
|
Definition at line 36 of file galaxy.cpp. Referenced by InitializeForms(), and Galaxy::setType(). |
|
|
Definition at line 34 of file galaxy.cpp. Referenced by InitializeForms(), and Galaxy::setType(). |
1.4.1