#include <galaxy.h>
Inheritance diagram for Galaxy:


Public Types | |
| enum | GalaxyType { S0 = 0, Sa = 1, Sb = 2, Sc = 3, SBa = 4, SBb = 5, SBc = 6, E0 = 7, E1 = 8, E2 = 9, E3 = 10, E4 = 11, E5 = 12, E6 = 13, E7 = 14, Irr = 15 } |
Public Member Functions | |
| Galaxy () | |
| virtual size_t | getDescription (char *buf, size_t bufLength) const |
| float | getDetail () const |
| GalacticForm * | getForm () const |
| virtual unsigned int | getLabelMask () const |
| virtual unsigned int | getRenderMask () const |
| virtual const char * | getType () const |
| virtual bool | load (AssociativeArray *, const std::string &) |
| virtual void | render (const GLContext &context, const Vec3f &offset, const Quatf &viewerOrientation, float brightness, float pixelSize) |
| virtual void | renderGalaxyEllipsoid (const GLContext &context, const Vec3f &offset, const Quatf &viewerOrientation, float brightness, float pixelSize) |
| virtual void | renderGalaxyPointSprites (const GLContext &context, const Vec3f &offset, const Quatf &viewerOrientation, float brightness, float pixelSize) |
| void | setDetail (float) |
| virtual void | setType (const std::string &) |
Static Public Member Functions | |
| static void | decreaseLightGain () |
| static float | getLightGain () |
| static void | hsv2rgb (float *r, float *g, float *b, float h, float s, float v) |
| static void | increaseLightGain () |
| static void | setLightGain (float) |
Private Attributes | |
| float | detail |
| GalacticForm * | form |
| GalaxyType | type |
Static Private Attributes | |
| static float | lightGain = 0.0f |
|
|
Definition at line 78 of file galaxy.h. 00078 {
00079 S0 = 0,
00080 Sa = 1,
00081 Sb = 2,
00082 Sc = 3,
00083 SBa = 4,
00084 SBb = 5,
00085 SBc = 6,
00086 E0 = 7,
00087 E1 = 8,
00088 E2 = 9,
00089 E3 = 10,
00090 E4 = 11,
00091 E5 = 12,
00092 E6 = 13,
00093 E7 = 14,
00094 Irr = 15
00095 };
|
|
|
Definition at line 87 of file galaxy.cpp.
|
|
|
Definition at line 385 of file galaxy.cpp. References lightGain. Referenced by CelestiaCore::charEntered(). 00386 {
00387 lightGain -= 0.05f;
00388 if (lightGain < 0.0f)
00389 lightGain = 0.0f;
00390 }
|
|
||||||||||||
|
Reimplemented from DeepSkyObject. Definition at line 154 of file galaxy.cpp. 00155 {
00156 // Should use snprintf, but it's not available on Windows; the
00157 // buffer *must* be large enough.
00158 return sprintf(buf, _("Galaxy (Hubble type: %s)"), getType());
00159 }
|
|
|
Definition at line 94 of file galaxy.cpp. References detail. Referenced by renderGalaxyPointSprites(). 00095 {
00096 return detail;
00097 }
|
|
|
Definition at line 162 of file galaxy.cpp. References form. 00163 {
00164 return form;
00165 }
|
|
|
Reimplemented from DeepSkyObject. Definition at line 371 of file galaxy.cpp. 00372 {
00373 return Renderer::GalaxyLabels;
00374 }
|
|
|
Definition at line 393 of file galaxy.cpp. References lightGain. Referenced by resyncGalaxyGainActions(). 00394 {
00395 return lightGain;
00396 }
|
|
|
Reimplemented from DeepSkyObject. Definition at line 365 of file galaxy.cpp. 00366 {
00367 return Renderer::ShowGalaxies;
00368 }
|
|
|
Implements DeepSkyObject. Definition at line 106 of file galaxy.cpp. References GalaxyTypeNames, GalaxyTypeName::name, and type. Referenced by getDescription(). 00107 {
00108 return GalaxyTypeNames[(int) type].name;
00109 }
|
|
||||||||||||||||||||||||||||
|
Definition at line 410 of file galaxy.cpp. Referenced by InitializeForms(). 00411 {
00412 // r,g,b values are from 0 to 1
00413 // h = [0,360], s = [0,1], v = [0,1]
00414
00415 int i;
00416 float f, p, q, t;
00417
00418 if( s == 0 ) {
00419 // achromatic (grey)
00420 *r = *g = *b = v;
00421 return;
00422 }
00423
00424 h /= 60; // sector 0 to 5
00425 i = (int) floorf( h );
00426 f = h - (float) i; // factorial part of h
00427 p = v * ( 1 - s );
00428 q = v * ( 1 - s * f );
00429 t = v * ( 1 - s * ( 1 - f ) );
00430
00431 switch( i ) {
00432 case 0:
00433 *r = v;
00434 *g = t;
00435 *b = p;
00436 break;
00437 case 1:
00438 *r = q;
00439 *g = v;
00440 *b = p;
00441 break;
00442 case 2:
00443 *r = p;
00444 *g = v;
00445 *b = t;
00446 break;
00447 case 3:
00448 *r = p;
00449 *g = q;
00450 *b = v;
00451 break;
00452 case 4:
00453 *r = t;
00454 *g = p;
00455 *b = v;
00456 break;
00457 default: *r = v;
00458 *g = p;
00459 *b = q;
00460 break;
00461 }
00462 }
|
|
|
Definition at line 377 of file galaxy.cpp. References lightGain. Referenced by CelestiaCore::charEntered(). 00378 {
00379 lightGain += 0.05f;
00380 if (lightGain > 1.0f)
00381 lightGain = 1.0f;
00382 }
|
|
||||||||||||
|
Reimplemented from DeepSkyObject. Definition at line 168 of file galaxy.cpp. References detail, DeepSkyObject::load(), setDetail(), and setType(). 00169 {
00170 double detail = 1.0;
00171 params->getNumber("Detail", detail);
00172 setDetail((float) detail);
00173
00174 string typeName;
00175 params->getString("Type", typeName);
00176 setType(typeName);
00177
00178 return DeepSkyObject::load(params, resPath);
00179 }
|
|
||||||||||||||||||||||||
|
Implements DeepSkyObject. Definition at line 182 of file galaxy.cpp. References form, renderGalaxyEllipsoid(), and renderGalaxyPointSprites(). 00187 {
00188 if (form == NULL)
00189 renderGalaxyEllipsoid(context, offset, viewerOrientation, brightness, pixelSize);
00190 else
00191 renderGalaxyPointSprites(context, offset, viewerOrientation, brightness, pixelSize);
00192 }
|
|
||||||||||||||||||||||||
|
Definition at line 305 of file galaxy.cpp. References cos(), VertexProcessor::disable(), E0, VertexProcessor::enable(), DeepSkyObject::getOrientation(), DeepSkyObject::getRadius(), glRotate(), Vector3< T >::length(), max, min, VertexProcessor::parameter(), PI, sin(), type, VertexProcessor::use(), Vector3< T >::x, Vector3< T >::y, and Vector3< T >::z. Referenced by render(). 00310 {
00311 float discSizeInPixels = pixelSize * getRadius() / offset.length();
00312 unsigned int nRings = (unsigned int) (discSizeInPixels / 4.0f);
00313 unsigned int nSlices = (unsigned int) (discSizeInPixels / 4.0f);
00314 nRings = max(nRings, 100);
00315 nSlices = max(nSlices, 100);
00316
00317 VertexProcessor* vproc = context.getVertexProcessor();
00318 if (vproc == NULL)
00319 return;
00320
00321 int e = min(max((int) type - (int) E0, 0), 7);
00322 Vec3f scale = Vec3f(1.0f, 0.9f, 1.0f) * getRadius();
00323 Vec3f eyePos_obj = -offset * (~getOrientation()).toMatrix3();
00324
00325 vproc->enable();
00326 vproc->use(vp::ellipticalGalaxy);
00327
00328 vproc->parameter(vp::EyePosition, eyePos_obj);
00329 vproc->parameter(vp::Scale, scale);
00330 vproc->parameter(vp::InverseScale,
00331 Vec3f(1.0f / scale.x, 1.0f / scale.y, 1.0f / scale.z));
00332 vproc->parameter((vp::Parameter) 23, eyePos_obj.length() / scale.x, 0.0f, 0.0f, 0.0f);
00333
00334 glRotate(getOrientation());
00335
00336 glDisable(GL_TEXTURE_2D);
00337 glColor4f(1.0f, 1.0f, 1.0f, 0.3f);
00338 for (unsigned int i = 0; i < nRings; i++)
00339 {
00340 float phi0 = (float) PI * ((float) i / (float) nRings - 0.5f);
00341 float phi1 = (float) PI * ((float) (i + 1) / (float) nRings - 0.5f);
00342
00343 glBegin(GL_QUAD_STRIP);
00344 for (unsigned int j = 0; j <= nSlices; j++)
00345 {
00346 float theta = (float) (PI * 2) * (float) j / (float) nSlices;
00347 float sinTheta = (float) sin(theta);
00348 float cosTheta = (float) cos(theta);
00349
00350 glVertex3f((float) cos(phi0) * cosTheta * scale.x,
00351 (float) sin(phi0) * scale.y,
00352 (float) cos(phi0) * sinTheta * scale.z);
00353 glVertex3f((float) cos(phi1) * cosTheta * scale.x,
00354 (float) sin(phi1) * scale.y,
00355 (float) cos(phi1) * sinTheta * scale.z);
00356 }
00357 glEnd();
00358 }
00359 glEnable(GL_TEXTURE_2D);
00360
00361 vproc->disable();
00362 }
|
|
||||||||||||||||||||||||
|
Definition at line 195 of file galaxy.cpp. References abs(), Texture::bind(), GalacticForm::blobs, Color::blue(), Blob::brightness, clamp(), Blob::colorIndex, colorTable, CreateProceduralTexture(), Point3< T >::distanceFromOrigin(), E0, E3, form, galaxyTex, GalaxyTextureEval(), getDetail(), DeepSkyObject::getOrientation(), DeepSkyObject::getRadius(), glVertex(), Color::green(), lightGain, Blob::position, Color::red(), GalacticForm::scale, Matrix3< float >::scaling(), sqrt(), Quaternion< T >::toMatrix3(), and type. Referenced by render(). 00200 {
00201 if (form == NULL)
00202 return;
00203
00204 if (galaxyTex == NULL)
00205 {
00206 galaxyTex = CreateProceduralTexture(128, 128, GL_RGBA,
00207 GalaxyTextureEval);
00208 }
00209 assert(galaxyTex != NULL);
00210
00211 glEnable(GL_TEXTURE_2D);
00212 galaxyTex->bind();
00213
00214 Mat3f viewMat = viewerOrientation.toMatrix3();
00215 Vec3f v0 = Vec3f(-1, -1, 0) * viewMat;
00216 Vec3f v1 = Vec3f( 1, -1, 0) * viewMat;
00217 Vec3f v2 = Vec3f( 1, 1, 0) * viewMat;
00218 Vec3f v3 = Vec3f(-1, 1, 0) * viewMat;
00219
00220 float distanceToDSO = offset.length() - getRadius();
00221 if (distanceToDSO < 0)
00222 distanceToDSO = 0;
00223
00224 float minimumFeatureSize = pixelSize * distanceToDSO;
00225
00226 //Mat4f m = (getOrientation().toMatrix4() *
00227 // Mat4f::scaling(form->scale) *
00228 // Mat4f::scaling(getRadius()));
00229
00230 float size = 2 * getRadius();
00231 Mat3f m =
00232 Mat3f::scaling(form->scale)*getOrientation().toMatrix3()*Mat3f::scaling(size);
00233
00234 // Note: fixed missing factor of 2 in getRadius() scaling of galaxy diameter!
00235 // Note: fixed correct ordering of (non-commuting) operations!
00236
00237 int pow2 = 1;
00238
00239 vector<Blob>* points = form->blobs;
00240 unsigned int nPoints = (unsigned int) (points->size() * clamp(getDetail()));
00241
00242 // corrections to avoid excessive brightening if viewed e.g. edge-on
00243
00244 float brightness_corr = 1.0f;
00245 float cosi;
00246
00247 if (type < E0 || type > E3) //all galaxies, except ~round elliptics
00248 {
00249 cosi = Vec3f(0,1,0) * getOrientation().toMatrix3()
00250 * offset/offset.length();
00251 brightness_corr = (float) sqrt(abs(cosi));
00252 if (brightness_corr < 0.2f)
00253 brightness_corr = 0.2f;
00254 }
00255
00256 if (type > E3) // only elliptics with higher ellipticities
00257 {
00258 cosi = Vec3f(1,0,0) * getOrientation().toMatrix3()
00259 * offset/offset.length();
00260 brightness_corr = brightness_corr * (float) sqrt(abs((cosi)));
00261 if (brightness_corr < 0.65f)
00262 brightness_corr = 0.65f;
00263 }
00264
00265 glBegin(GL_QUADS);
00266 for (unsigned int i = 0; i < nPoints; ++i)
00267 {
00268 Blob b = (*points)[i];
00269 Point3f p = b.position * m;
00270 float br = b.brightness;
00271
00272 // Reddening for elliptical galaxies
00273
00274 b.colorIndex = type < E0 ? b.colorIndex : (unsigned int) ceil(0.3f*b.colorIndex);
00275 Color c = colorTable[b.colorIndex]; // lookup static color table
00276
00277 Point3f relPos = p + offset;
00278
00279 if ((i & pow2) != 0)
00280 {
00281 pow2 <<= 1;
00282 size /= 1.57f;
00283 if (size < minimumFeatureSize)
00284 break;
00285 }
00286
00287 float screenFrac = size / relPos.distanceFromOrigin();
00288
00289 if (screenFrac < 0.1f)
00290 {
00291 float a = 3.5f * (0.1f - screenFrac) * brightness_corr * brightness * br;
00292
00293 glColor4f(c.red(), c.green(), c.blue(), (4.0f*lightGain + 1.0f)*a);
00294
00295 glTexCoord2f(0, 0); glVertex(p + (v0 * size));
00296 glTexCoord2f(1, 0); glVertex(p + (v1 * size));
00297 glTexCoord2f(1, 1); glVertex(p + (v2 * size));
00298 glTexCoord2f(0, 1); glVertex(p + (v3 * size));
00299 }
00300 }
00301 glEnd();
00302 }
|
|
|
Definition at line 100 of file galaxy.cpp. References detail. Referenced by load(). 00101 {
00102 detail = d;
00103 }
|
|
|
Definition at line 399 of file galaxy.cpp. References lightGain. Referenced by setSaneGalaxyLightGain(). 00400 {
00401 if (lg < 0.0f)
00402 lightGain = 0.0f;
00403 else if (lg > 1.0f)
00404 lightGain = 1.0f;
00405 else
00406 lightGain = lg;
00407 }
|
|
|
Implements DeepSkyObject. Definition at line 111 of file galaxy.cpp. References E0, E1, E2, E3, E4, E5, E6, E7, ellipticalForms, form, formsInitialized, GalaxyTypeNames, InitializeForms(), Irr, irregularForm, S0, Sa, Sb, SBa, SBb, SBc, Sc, spiralForms, GalaxyTypeName::type, and type. Referenced by load(). 00112 {
00113 type = Galaxy::Irr;
00114 for (int i = 0; i < (int) (sizeof(GalaxyTypeNames) / sizeof(GalaxyTypeNames[0])); ++i)
00115 {
00116 if (GalaxyTypeNames[i].name == typeStr)
00117 {
00118 type = GalaxyTypeNames[i].type;
00119 break;
00120 }
00121 }
00122
00123 if (!formsInitialized)
00124 InitializeForms();
00125 switch (type)
00126 {
00127 case S0:
00128 case Sa:
00129 case Sb:
00130 case Sc:
00131 case SBa:
00132 case SBb:
00133 case SBc:
00134 form = spiralForms[type - S0];
00135 break;
00136 case E0:
00137 case E1:
00138 case E2:
00139 case E3:
00140 case E4:
00141 case E5:
00142 case E6:
00143 case E7:
00144 form = ellipticalForms[type - E0];
00145 //form = NULL;
00146 break;
00147 case Irr:
00148 form = irregularForm;
00149 break;
00150 }
00151 }
|
|
|
Definition at line 98 of file galaxy.h. Referenced by getDetail(), load(), and setDetail(). |
|
|
Definition at line 101 of file galaxy.h. Referenced by getForm(), render(), renderGalaxyPointSprites(), and setType(). |
|
|
Definition at line 42 of file galaxy.cpp. Referenced by decreaseLightGain(), getLightGain(), increaseLightGain(), renderGalaxyPointSprites(), and setLightGain(). |
|
|
Definition at line 100 of file galaxy.h. Referenced by getType(), renderGalaxyEllipsoid(), renderGalaxyPointSprites(), and setType(). |
1.4.1