Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

DSORenderer Class Reference

Inheritance diagram for DSORenderer:

Inheritance graph
Collaboration diagram for DSORenderer:

Collaboration graph
List of all members.

Public Member Functions

 DSORenderer ()
void process (DeepSkyObject *const &, double, float)

Public Attributes

double avgAbsMag
DSODatabasedsoDB
Frustum frustum
Point3d obsPos
Mat3f orientationMatrix
int wHeight
int wWidth

Constructor & Destructor Documentation

DSORenderer::DSORenderer  ) 
 

Definition at line 6525 of file render.cpp.

References degToRad(), and DSO_DISTANCE_LIMIT.

06525                          :
06526     ObjectRenderer<DeepSkyObject*, double>(DSO_DISTANCE_LIMIT),
06527     frustum(degToRad(45.0f), 1.0f, 1.0f)
06528 {
06529 }


Member Function Documentation

void DSORenderer::process DeepSkyObject *const &  ,
double  ,
float 
[virtual]
 

Reimplemented from ObjectRenderer< DeepSkyObject *, double >.

Definition at line 6532 of file render.cpp.

References astro::absToAppMag(), Renderer::addLabel(), avgAbsMag, dot(), dsoDB, frustum, DSODatabase::getDSOName(), Renderer::getFaintestAM45deg(), Observer::getOrientation(), Renderer::getScreenDpi(), glTranslate(), log(), obsPos, orientationMatrix, REF_DISTANCE_TO_SCREEN, Renderer::render(), Frustum::testSphere(), wHeight, wWidth, Vector3< T >::x, Point3< T >::x, Vector3< T >::y, Point3< T >::y, Vector3< T >::z, and Point3< T >::z.

06535 {
06536     if (distanceToDSO > distanceLimit)
06537         return;
06538 
06539     Point3d dsoPos = dso->getPosition();
06540     Vec3f   relPos = Vec3f((float)(dsoPos.x - obsPos.x),
06541                            (float)(dsoPos.y - obsPos.y),
06542                            (float)(dsoPos.z - obsPos.z));
06543 
06544     Point3d center = Point3d(0.0f, 0.0f, 0.0f) + relPos * orientationMatrix;
06545 
06546     // Test the object's bounding sphere against the view frustum. If we
06547     // avoid this stage, overcrowded octree cells may hit performance badly:
06548     // each object (even if it's not visible) would be sent to the OpenGL
06549     // pipeline.
06550 
06551     if (renderFlags & dso->getRenderMask())
06552     {
06553         double  dsoRadius = dso->getRadius();
06554         if (frustum.testSphere(center, dsoRadius) != Frustum::Outside)
06555         {
06556                 // display looks satisfactory for 0.2 < brightness < O(1.0)
06557             // Ansatz: brightness = a - b*appMag(distanceToDSO), emulates eye sensitivity...
06558             // determine a,b such that
06559             // a-b*absMag = absMag/avgAbsMag ~ 1; a-b*faintestMag = 0.2
06560             // the 2nd eqn guarantees that the faintest galaxies are still visible.
06561             // the parameters in the 'close' correction function are fixed by matching
06562             // the gradients at 10 pc and by: close (10 pc) = 0. 
06563             // ri adjusts the Milky Way brightness as viewed from "inside" (e.g. from Earth).
06564 
06565             double ri  = -0.1, pc10 = 32.6167;
06566             double r   = absMag / avgAbsMag;
06567             double num = 5 * (absMag - faintestMag);
06568             double a   = r * (avgAbsMag - 5 * faintestMag) / num;
06569             double b   = (1.0 - 5 * r) / num; 
06570             double close = (distanceToDSO > -10.0)?
06571                 -4.3429448 * b * log((pc10 + distanceToDSO)/(2 * pc10)): ri; 
06572             // note: 10.0 / log(10.0) = 4.3429448
06573             if (distanceToDSO < 0)
06574                 distanceToDSO = 0;
06575             double brightness = (distanceToDSO  >= pc10)?
06576                 a - b * astro::absToAppMag(absMag, (float) distanceToDSO): r + close;    
06577             brightness = 2.3 * brightness * (faintestMag - 4.75)/renderer->getFaintestAM45deg();
06578             if (brightness < 0.0)
06579                 brightness = 0.0;
06580 
06581             if (dsoRadius < 1000.0)
06582             {
06583                 // Small objects may be prone to clipping; give them special
06584                 // handling.  We don't want to always set the projection
06585                 // matrix, since that could be expensive with large galaxy
06586                 // catalogs.
06587                 float nearZ = (float) (distanceToDSO / 2);
06588                 float farZ  = (float) (distanceToDSO + dsoRadius * 2);
06589                 if (nearZ < dsoRadius * 0.001)
06590                 {
06591                     nearZ = (float) (dsoRadius * 0.001);
06592                     farZ  = nearZ * 10000.0f;
06593                 }
06594 
06595                 glMatrixMode(GL_PROJECTION);
06596                 glPushMatrix();
06597                 glLoadIdentity();
06598                 gluPerspective(fov,
06599                                (float) wWidth / (float) wHeight,
06600                                nearZ,
06601                                farZ);
06602                 glMatrixMode(GL_MODELVIEW);
06603             }
06604 
06605             glPushMatrix();
06606             glTranslate(relPos);
06607 
06608             dso->render(*context,
06609                         relPos,
06610                         observer->getOrientation(),
06611                         (float) brightness,
06612                         pixelSize);
06613             glPopMatrix();
06614 
06615 #if 1
06616             if (dsoRadius < 1000.0)
06617             {
06618                 glMatrixMode(GL_PROJECTION);
06619                 glPopMatrix();
06620                 glMatrixMode(GL_MODELVIEW);
06621             }
06622 #endif
06623         } // frustum test
06624     } // renderFlags check
06625 
06626     // avoid label overlap by pixelSize-controlled apparent magnitude cut-off!
06627     // Use pixelSize * screenDpi instead of FoV, to eliminate windowHeight dependence.
06628     // Label appearance is sorted according to apparent galaxy brightness!
06629     // Only render those labels that are in front of the camera:
06630 
06631     float relDistanceToScreen = REF_DISTANCE_TO_SCREEN * pixelSize * renderer->getScreenDpi() / 25.4f; 
06632     // = 1.0 initially, after startup
06633     if ((dso->getLabelMask() & labelMode)
06634     && astro::absToAppMag(absMag, (float) distanceToDSO) < faintestMag * (1.0f - 0.5f * log10(relDistanceToScreen)) 
06635     && dot(relPos, viewNormal) > 0)
06636     {
06637         renderer->addLabel(dsoDB->getDSOName(dso),
06638                             Color(0.1f, 0.85f, 0.85f, 1.0f),
06639                             Point3f(relPos.x, relPos.y, relPos.z));
06640     }
06641 }


Member Data Documentation

double DSORenderer::avgAbsMag
 

Definition at line 6521 of file render.cpp.

Referenced by process(), and Renderer::renderDeepSkyObjects().

DSODatabase* DSORenderer::dsoDB
 

Definition at line 6513 of file render.cpp.

Referenced by process(), and Renderer::renderDeepSkyObjects().

Frustum DSORenderer::frustum
 

Definition at line 6514 of file render.cpp.

Referenced by process(), and Renderer::renderDeepSkyObjects().

Point3d DSORenderer::obsPos
 

Definition at line 6512 of file render.cpp.

Referenced by process(), and Renderer::renderDeepSkyObjects().

Mat3f DSORenderer::orientationMatrix
 

Definition at line 6516 of file render.cpp.

Referenced by process(), and Renderer::renderDeepSkyObjects().

int DSORenderer::wHeight
 

Definition at line 6519 of file render.cpp.

Referenced by process(), and Renderer::renderDeepSkyObjects().

int DSORenderer::wWidth
 

Definition at line 6518 of file render.cpp.

Referenced by process(), and Renderer::renderDeepSkyObjects().


The documentation for this class was generated from the following file:
Generated on Sat Jan 14 22:33:18 2006 for Celestia by  doxygen 1.4.1