#include <render.h>
Collaboration diagram for Renderer:

Public Types | |
| enum | { NoLabels = 0x000, StarLabels = 0x001, PlanetLabels = 0x002, MoonLabels = 0x004, ConstellationLabels = 0x008, GalaxyLabels = 0x010, AsteroidLabels = 0x020, SpacecraftLabels = 0x040, LocationLabels = 0x080, CometLabels = 0x100, NebulaLabels = 0x200, OpenClusterLabels = 0x400, I18nConstellationLabels = 0x800, BodyLabelMask = (PlanetLabels | MoonLabels | AsteroidLabels | SpacecraftLabels | CometLabels) } |
| enum | { ShowNothing = 0x0000, ShowStars = 0x0001, ShowPlanets = 0x0002, ShowGalaxies = 0x0004, ShowDiagrams = 0x0008, ShowCloudMaps = 0x0010, ShowOrbits = 0x0020, ShowCelestialSphere = 0x0040, ShowNightMaps = 0x0080, ShowAtmospheres = 0x0100, ShowSmoothLines = 0x0200, ShowEclipseShadows = 0x0400, ShowStarsAsPoints = 0x0800, ShowRingShadows = 0x1000, ShowBoundaries = 0x2000, ShowAutoMag = 0x4000, ShowCometTails = 0x8000, ShowMarkers = 0x10000, ShowPartialTrajectories = 0x20000, ShowNebulae = 0x40000, ShowOpenClusters = 0x80000 } |
| enum | StarStyle { FuzzyPointStars = 0, PointStars = 1, ScaledDiscStars = 2, StarStyleCount = 3 } |
Public Member Functions | |
| void | addLabel (std::string, Color, const Point3f &, float depth=-1) |
| void | addLabelledStar (Star *, const std::string &) |
| void | addSortedLabel (std::string, Color, const Point3f &) |
| void | autoMag (float &faintestMag) |
| float | calcPixelSize (float fov, float windowHeight) |
| void | clearLabelledStars () |
| void | clearLabels () |
| bool | fragmentShaderSupported () const |
| float | getAmbientLightLevel () const |
| float | getBrightnessBias () const |
| float | getDistanceLimit () const |
| float | getFaintestAM45deg () |
| TextureFont * | getFont () const |
| bool | getFragmentShaderEnabled () const |
| GLContext * | getGLContext () |
| int | getLabelMode () const |
| float | getMinimumFeatureSize () const |
| float | getMinimumOrbitSize () const |
| int | getOrbitMask () const |
| int | getRenderFlags () const |
| unsigned int | getResolution () |
| float | getSaturationMagnitude () const |
| int | getScreenDpi () const |
| const ColorTemperatureTable * | getStarColorTable () const |
| StarStyle | getStarStyle () const |
| bool | getVertexShaderEnabled () const |
| bool | init (GLContext *, int, int, DetailOptions &) |
| void | loadTextures (Body *) |
| void | render (const Observer &, const Universe &, float faintestVisible, const Selection &sel) |
| Renderer () | |
| void | resize (int, int) |
| void | setAmbientLightLevel (float) |
| void | setBrightnessBias (float) |
| void | setDistanceLimit (float) |
| void | setFaintestAM45deg (float) |
| void | setFont (TextureFont *) |
| void | setFragmentShaderEnabled (bool) |
| void | setLabelMode (int) |
| void | setMinimumFeatureSize (float) |
| void | setMinimumOrbitSize (float) |
| void | setOrbitMask (int) |
| void | setRenderFlags (int) |
| void | setRenderMode (int) |
| void | setResolution (unsigned int resolution) |
| void | setSaturationMagnitude (float) |
| void | setScreenDpi (int) |
| void | setStarColorTable (const ColorTemperatureTable *) |
| void | setStarStyle (StarStyle) |
| void | setVertexShaderEnabled (bool) |
| void | shutdown () |
| bool | vertexShaderSupported () const |
| ~Renderer () | |
Private Types | |
| typedef ObjectLabel< DeepSkyObject > | DSOLabel |
| typedef ObjectLabel< Star > | StarLabel |
Private Member Functions | |
| void | labelConstellations (const AsterismList &asterisms, const Observer &observer) |
| void | labelStars (const std::vector< StarLabel > &labelledStars, const StarDatabase &, const Observer &) |
| void | renderBodyAsParticle (Point3f center, float appMag, float _faintestMag, float discSizeInPixels, Color color, const Quatf &orientation, float renderDistance, bool useHaloes) |
| void | renderCelestialSphere (const Observer &observer) |
| void | renderCometTail (const Body &body, Point3f pos, float distance, float appMag, double now, Quatf orientation, const vector< LightSource > &lightSources, float, float) |
| void | renderDeepSkyObjects (const Universe &, const Observer &, float faintestMagNight) |
| void | renderEllipsoidAtmosphere (const Atmosphere &atmosphere, Point3f center, const Quatf &orientation, Vec3f semiAxes, const Vec3f &sunDirection, Color ambientColor, float fade, bool lit) |
| void | renderForegroundOrbits (const PlanetarySystem *system, const Point3f ¢er, float distance, float discSizeInPixels, const Selection &sel, double t) |
| void | renderLabels () |
| void | renderLocations (const vector< Location * > &locations, const Quatf &cameraOrientation, const Point3f &position, const Quatf &orientation, float scale) |
| void | renderMarkers (const MarkerList &, const UniversalCoord &position, const Quatf &orientation, double jd) |
| void | renderObject (Point3f pos, float distance, double now, Quatf cameraOrientation, float nearPlaneDistance, float farPlaneDistance, RenderProperties &obj, const LightingState &) |
| void | renderOrbit (Body *, double) |
| void | renderOrbits (PlanetarySystem *, const Selection &, double, const Point3d &, const Point3d &) |
| void | renderParticles (const std::vector< Particle > &particles, Quatf orientation) |
| void | renderPlanet (Body &body, Point3f pos, float distance, float appMag, double now, Quatf orientation, const vector< LightSource > &lightSources, float, float) |
| void | renderPlanetarySystem (const Star &sun, const PlanetarySystem &solSystem, const Observer &observer, double now, unsigned int solarSysIndex, bool showLabels=false) |
| std::vector< Label >::iterator | renderSortedLabels (std::vector< Label >::iterator, float depth) |
| void | renderStar (const Star &star, Point3f pos, float distance, float appMag, Quatf orientation, double now, float, float) |
| void | renderStars (const StarDatabase &starDB, float faintestVisible, const Observer &observer) |
| void | setFieldOfView (float) |
| bool | testEclipse (const Body &receiver, const Body &caster, const DirectionalLight &light, double now, vector< EclipseShadow > &shadows) |
Private Attributes | |
| Color | ambientColor |
| float | ambientLightLevel |
| float | brightnessBias |
| float | brightnessScale |
| const ColorTemperatureTable * | colorTemp |
| GLContext * | context |
| float | corrFac |
| std::vector< Label > | depthSortedLabels |
| DetailOptions | detailOptions |
| std::string | displayedSurface |
| float | distanceLimit |
| std::vector< EclipseShadow > | eclipseShadows [MaxLights] |
| float | faintestAutoMag45deg |
| float | faintestMag |
| float | faintestPlanetMag |
| TextureFont * | font |
| float | fov |
| bool | fragmentShaderEnabled |
| std::vector< Particle > | glareParticles |
| std::vector< DSOLabel > | labelledDSOs |
| std::vector< StarLabel > | labelledStars |
| int | labelMode |
| std::vector< Label > | labels |
| std::vector< LightSource > | lightSourceLists [MaxSolarSystems] |
| uint32 | locationFilter |
| float | minFeatureSize |
| float | minOrbitSize |
| double | modelMatrix [16] |
| std::vector< const Star * > | nearStars |
| std::vector< CachedOrbit * > | orbitCache |
| int | orbitMask |
| float | pixelSize |
| double | projMatrix [16] |
| int | renderFlags |
| std::vector< RenderListEntry > | renderList |
| int | renderMode |
| float | saturationMag |
| float | saturationMagNight |
| int | screenDpi |
| SkyContourPoint * | skyContour |
| uint32 * | skyIndices |
| SkyVertex * | skyVertices |
| StarStyle | starStyle |
| StarVertexBuffer * | starVertexBuffer |
| unsigned int | textureResolution |
| bool | useClampToBorder |
| bool | useCompressedTextures |
| bool | usePointSprite |
| bool | useRescaleNormal |
| bool | useVertexPrograms |
| bool | vertexShaderEnabled |
| int | windowHeight |
| int | windowWidth |
Classes | |
| struct | CachedOrbit |
| struct | DetailOptions |
| struct | Label |
| struct | LightSource |
| struct | ObjectLabel |
| struct | OrbitSample |
| struct | Particle |
| class | PointStarVertexBuffer |
| struct | RenderProperties |
| struct | SkyContourPoint |
| struct | SkyVertex |
| class | StarVertexBuffer |
|
|
|
|
|
|
|
|
Definition at line 74 of file render.h. 00074 {
00075 NoLabels = 0x000,
00076 StarLabels = 0x001,
00077 PlanetLabels = 0x002,
00078 MoonLabels = 0x004,
00079 ConstellationLabels = 0x008,
00080 GalaxyLabels = 0x010,
00081 AsteroidLabels = 0x020,
00082 SpacecraftLabels = 0x040,
00083 LocationLabels = 0x080,
00084 CometLabels = 0x100,
00085 NebulaLabels = 0x200,
00086 OpenClusterLabels = 0x400,
00087 I18nConstellationLabels = 0x800,
00088 BodyLabelMask = (PlanetLabels | MoonLabels | AsteroidLabels | SpacecraftLabels | CometLabels),
00089 };
|
|
|
Definition at line 91 of file render.h. 00091 {
00092 ShowNothing = 0x0000,
00093 ShowStars = 0x0001,
00094 ShowPlanets = 0x0002,
00095 ShowGalaxies = 0x0004,
00096 ShowDiagrams = 0x0008,
00097 ShowCloudMaps = 0x0010,
00098 ShowOrbits = 0x0020,
00099 ShowCelestialSphere = 0x0040,
00100 ShowNightMaps = 0x0080,
00101 ShowAtmospheres = 0x0100,
00102 ShowSmoothLines = 0x0200,
00103 ShowEclipseShadows = 0x0400,
00104 ShowStarsAsPoints = 0x0800,
00105 ShowRingShadows = 0x1000,
00106 ShowBoundaries = 0x2000,
00107 ShowAutoMag = 0x4000,
00108 ShowCometTails = 0x8000,
00109 ShowMarkers = 0x10000,
00110 ShowPartialTrajectories = 0x20000,
00111 ShowNebulae = 0x40000,
00112 ShowOpenClusters = 0x80000,
00113 };
|
|
|
Definition at line 115 of file render.h. 00116 {
00117 FuzzyPointStars = 0,
00118 PointStars = 1,
00119 ScaledDiscStars = 2,
00120 StarStyleCount = 3,
00121 };
|
|
|
Definition at line 132 of file render.cpp. References ColorTable_Enhanced, colorTemp, FOV, GetStarColorTable(), MaxSkyRings, MaxSkySlices, medres, MinFeatureSizeForLabel, MinOrbitSizeForLabel, skyContour, skyIndices, skyVertices, and starVertexBuffer. 00132 : 00133 context(0), 00134 windowWidth(0), 00135 windowHeight(0), 00136 fov(FOV), 00137 screenDpi(96), 00138 corrFac(1.12f), 00139 faintestAutoMag45deg(7.0f), 00140 renderMode(GL_FILL), 00141 labelMode(NoLabels), 00142 renderFlags(ShowStars | ShowPlanets), 00143 orbitMask(Body::Planet | Body::Moon), 00144 ambientLightLevel(0.1f), 00145 fragmentShaderEnabled(false), 00146 vertexShaderEnabled(false), 00147 brightnessBias(0.0f), 00148 saturationMagNight(1.0f), 00149 saturationMag(1.0f), 00150 starStyle(FuzzyPointStars), 00151 starVertexBuffer(NULL), 00152 useVertexPrograms(false), 00153 useRescaleNormal(false), 00154 usePointSprite(false), 00155 textureResolution(medres), 00156 minOrbitSize(MinOrbitSizeForLabel), 00157 distanceLimit(1.0e6f), 00158 minFeatureSize(MinFeatureSizeForLabel), 00159 locationFilter(~0), 00160 colorTemp(NULL) 00161 { 00162 starVertexBuffer = new StarVertexBuffer(2048); 00163 skyVertices = new SkyVertex[MaxSkySlices * (MaxSkyRings + 1)]; 00164 skyIndices = new uint32[(MaxSkySlices + 1) * 2 * MaxSkyRings]; 00165 skyContour = new SkyContourPoint[MaxSkySlices + 1]; 00166 colorTemp = GetStarColorTable(ColorTable_Enhanced); 00167 }
|
|
|
Definition at line 170 of file render.cpp. References skyContour, skyIndices, skyVertices, and starVertexBuffer. 00171 {
00172 if (starVertexBuffer != NULL)
00173 delete starVertexBuffer;
00174 delete[] skyVertices;
00175 delete[] skyIndices;
00176 delete[] skyContour;
00177 }
|
|
||||||||||||||||||||
|
Definition at line 773 of file render.cpp. References Renderer::Label::color, labels, modelMatrix, Renderer::Label::position, projMatrix, ReplaceGreekLetterAbbr(), Renderer::Label::text, windowHeight, and windowWidth. Referenced by labelConstellations(), labelStars(), DSORenderer::process(), and renderCelestialSphere(). 00777 {
00778 double winX, winY, winZ;
00779 int view[4] = { 0, 0, 0, 0 };
00780 view[0] = -windowWidth / 2;
00781 view[1] = -windowHeight / 2;
00782 view[2] = windowWidth;
00783 view[3] = windowHeight;
00784 depth = (float) (pos.x * modelMatrix[2] +
00785 pos.y * modelMatrix[6] +
00786 pos.z * modelMatrix[10]);
00787 if (gluProject(pos.x, pos.y, pos.z,
00788 modelMatrix,
00789 projMatrix,
00790 (const GLint*) view,
00791 &winX, &winY, &winZ) != GL_FALSE)
00792 {
00793 Label l;
00794 l.text = ReplaceGreekLetterAbbr(text.c_str());
00795 l.color = color;
00796 l.position = Point3f((float) winX, (float) winY, -depth);
00797 labels.insert(labels.end(), l);
00798 }
00799 }
|
|
||||||||||||
|
Definition at line 681 of file render.cpp. References labelledStars. Referenced by CelestiaCore::initRenderer(). 00682 {
00683 labelledStars.push_back(StarLabel(star, label));
00684 }
|
|
||||||||||||||||
|
Definition at line 802 of file render.cpp. References _, Renderer::Label::color, depthSortedLabels, modelMatrix, Renderer::Label::position, projMatrix, ReplaceGreekLetterAbbr(), Renderer::Label::text, windowHeight, and windowWidth. Referenced by renderPlanetarySystem(). 00803 {
00804 double winX, winY, winZ;
00805 int view[4] = { 0, 0, 0, 0 };
00806 view[0] = -windowWidth / 2;
00807 view[1] = -windowHeight / 2;
00808 view[2] = windowWidth;
00809 view[3] = windowHeight;
00810 float depth = (float) (pos.x * modelMatrix[2] +
00811 pos.y * modelMatrix[6] +
00812 pos.z * modelMatrix[10]);
00813 if (gluProject(pos.x, pos.y, pos.z,
00814 modelMatrix,
00815 projMatrix,
00816 (const GLint*) view,
00817 &winX, &winY, &winZ) != GL_FALSE)
00818 {
00819 Label l;
00820 l.text = ReplaceGreekLetterAbbr(_(text.c_str()));
00821 l.color = color;
00822 l.position = Point3f((float) winX, (float) winY, -depth);
00823 depthSortedLabels.insert(depthSortedLabels.end(), l);
00824 }
00825 }
|
|
|
Definition at line 1188 of file render.cpp. References faintestAutoMag45deg, faintestMag, fov, FOV, saturationMag, saturationMagNight, and sqrt(). Referenced by render(), and CelestiaCore::setFaintestAutoMag(). 01189 {
01190 float fieldCorr = 2.0f * FOV/(fov + FOV);
01191 faintestMag = (float) (faintestAutoMag45deg * sqrt(fieldCorr));
01192 saturationMag = saturationMagNight * (1.0f + fieldCorr * fieldCorr);
01193 }
|
|
||||||||||||
|
Definition at line 577 of file render.cpp. References degToRad(). Referenced by render(). 00578 {
00579 return 2 * (float) tan(degToRad(fovY / 2.0)) / (float) windowHeight;
00580 }
|
|
|
Definition at line 687 of file render.cpp. References labelledStars. 00688 {
00689 labelledStars.clear();
00690 }
|
|
|
Definition at line 828 of file render.cpp. References depthSortedLabels, and labels. Referenced by render(). 00829 {
00830 labels.clear();
00831 depthSortedLabels.clear();
00832 }
|
|
|
Definition at line 752 of file render.cpp. References GLContext::bumpMappingSupported(), and context. Referenced by setFragmentShaderEnabled(). 00753 {
00754 return context->bumpMappingSupported();
00755 }
|
|
|
Definition at line 693 of file render.cpp. References ambientLightLevel. Referenced by celestia_getambient(), CelestiaCore::charEntered(), GetCurrentPreferences(), KdePreferencesDialog::KdePreferencesDialog(), KdeApp::queryExit(), KdePreferencesDialog::slotApply(), and syncMenusWithRendererState(). 00694 {
00695 return ambientLightLevel;
00696 }
|
|
|
Definition at line 7023 of file render.cpp. References brightnessBias. 07024 {
07025 return brightnessBias;
07026 }
|
|
|
Definition at line 730 of file render.cpp. References distanceLimit. Referenced by celestia_getstardistancelimit(), and ViewOptionsDialog::SetControls(). 00731 {
00732 return distanceLimit;
00733 }
|
|
|
Definition at line 603 of file render.cpp. References faintestAutoMag45deg. Referenced by celestia_getfaintestvisible(), CelestiaCore::charEntered(), CelestiaCore::initRenderer(), and DSORenderer::process(). 00604 {
00605 return faintestAutoMag45deg;
00606 }
|
|
|
Definition at line 621 of file render.cpp. References font. 00622 {
00623 return font;
00624 }
|
|
|
Definition at line 742 of file render.cpp. References fragmentShaderEnabled. 00743 {
00744 return fragmentShaderEnabled;
00745 }
|
|
|
|
|
Definition at line 705 of file render.cpp. References minFeatureSize. Referenced by celestia_getminfeaturesize(), KdePreferencesDialog::KdePreferencesDialog(), LocationsProc(), KdeApp::queryExit(), LocationsDialog::SetControls(), and KdePreferencesDialog::slotApply(). 00706 {
00707 return minFeatureSize;
00708 }
|
|
|
Definition at line 717 of file render.cpp. References minOrbitSize. Referenced by celestia_getminorbitsize(). 00718 {
00719 return minOrbitSize;
00720 }
|
|
|
Definition at line 656 of file render.cpp. References orbitMask. Referenced by celestia_getorbitflags(), celestia_setorbitflags(), GetCurrentPreferences(), KdeApp::initActions(), KdePreferencesDialog::KdePreferencesDialog(), CommandOrbitFlags::process(), KdeApp::queryExit(), KdeApp::resyncMenus(), ViewOptionsDialog::SetControls(), KdeApp::slotShowAsteroidOrbits(), KdeApp::slotShowCometOrbits(), KdeApp::slotShowMoonOrbits(), KdeApp::slotShowPlanetOrbits(), KdeApp::slotShowSpacecraftOrbits(), and ViewOptionsProc(). 00657 {
00658 return orbitMask;
00659 }
|
|
|
|
Definition at line 608 of file render.cpp. References textureResolution. Referenced by CelestiaCore::charEntered(), and GetCurrentPreferences(). 00609 {
00610 return textureResolution;
00611 }
|
|
|
Definition at line 7011 of file render.cpp. References saturationMag. 07012 {
07013 return saturationMag;
07014 }
|
|
|
Definition at line 588 of file render.cpp. References screenDpi. Referenced by DSORenderer::process(). 00589 {
00590 return screenDpi;
00591 }
|
|
|
Definition at line 668 of file render.cpp. References colorTemp. Referenced by CelestiaCore::charEntered(). 00669 {
00670 return colorTemp;
00671 }
|
|
|
Definition at line 7041 of file render.cpp. References starStyle. Referenced by celestia_getstarstyle(), CelestiaCore::charEntered(), GetCurrentPreferences(), MainWindowProc(), and syncMenusWithRendererState(). 07042 {
07043 return starStyle;
07044 }
|
|
|
Definition at line 757 of file render.cpp. References vertexShaderEnabled. 00758 {
00759 return vertexShaderEnabled;
00760 }
|
|
||||||||||||||||||||
|
Definition at line 379 of file render.cpp. References buggyVertexProgramEmulation, commonDataInitialized, context, coordLabels, CreateProceduralCubeMap(), CreateProceduralTexture(), SphericalCoordLabel::dec, detailOptions, DPRINTF, eclipseShadowTextures, Renderer::DetailOptions::eclipseTextureSize, GLContext::extensionSupported(), GL_RESCALE_NORMAL_EXT, glareTex, GlareTextureEval(), IllumMapEval(), SphericalCoordLabel::label, LoadTextureFromFile(), lodSphere, nCoordLabels, normalizationTex, PenumbraFunctionEval(), penumbraFunctionTexture, SphericalCoordLabel::ra, resize(), Texture::setBorderColor(), shadowMaskTexture, shadowTex, ShadowTextureEval(), Renderer::DetailOptions::shadowTextureSize, starTex, StarTextureEval(), useClampToBorder, usePointSprite, and useRescaleNormal. Referenced by CelestiaCore::initRenderer(). 00382 {
00383 context = _context;
00384 detailOptions = _detailOptions;
00385
00386 // Initialize static meshes and textures common to all instances of Renderer
00387 if (!commonDataInitialized)
00388 {
00389 lodSphere = new LODSphereMesh();
00390
00391 starTex = CreateProceduralTexture(64, 64, GL_RGB, StarTextureEval);
00392
00393 glareTex = LoadTextureFromFile("textures/flare.jpg");
00394 if (glareTex == NULL)
00395 glareTex = CreateProceduralTexture(64, 64, GL_RGB, GlareTextureEval);
00396
00397 // Max mipmap level doesn't work reliably on all graphics
00398 // cards. In particular, Rage 128 and TNT cards resort to software
00399 // rendering when this feature is enabled. The only workaround is to
00400 // disable mipmapping completely unless texture border clamping is
00401 // supported, which solves the problem much more elegantly than all
00402 // the mipmap level nonsense.
00403 // shadowTex->setMaxMipMapLevel(3);
00404 Texture::AddressMode shadowTexAddress = Texture::EdgeClamp;
00405 Texture::MipMapMode shadowTexMip = Texture::NoMipMaps;
00406 useClampToBorder = context->extensionSupported("GL_ARB_texture_border_clamp");
00407 if (useClampToBorder)
00408 {
00409 shadowTexAddress = Texture::BorderClamp;
00410 shadowTexMip = Texture::DefaultMipMaps;
00411 }
00412
00413 shadowTex = CreateProceduralTexture(detailOptions.shadowTextureSize,
00414 detailOptions.shadowTextureSize,
00415 GL_RGB,
00416 ShadowTextureEval,
00417 shadowTexAddress, shadowTexMip);
00418 shadowTex->setBorderColor(Color::White);
00419
00420 // Create the eclipse shadow textures
00421 {
00422 for (int i = 0; i < 4; i++)
00423 {
00424 ShadowTextureFunction func(i * 0.25f);
00425 eclipseShadowTextures[i] =
00426 CreateProceduralTexture(detailOptions.eclipseTextureSize,
00427 detailOptions.eclipseTextureSize,
00428 GL_RGB, func,
00429 shadowTexAddress, shadowTexMip);
00430 if (eclipseShadowTextures[i] != NULL)
00431 {
00432 // eclipseShadowTextures[i]->setMaxMipMapLevel(2);
00433 eclipseShadowTextures[i]->setBorderColor(Color::White);
00434 }
00435 }
00436 }
00437
00438 // Create the shadow mask texture
00439 {
00440 ShadowMaskTextureFunction func;
00441 shadowMaskTexture = CreateProceduralTexture(128, 2, GL_RGBA, func);
00442 //shadowMaskTexture->bindName();
00443 }
00444
00445 // Create a function lookup table in a texture for use with
00446 // fragment program eclipse shadows.
00447 penumbraFunctionTexture = CreateProceduralTexture(512, 1, GL_LUMINANCE,
00448 PenumbraFunctionEval,
00449 Texture::EdgeClamp);
00450
00451 if (context->extensionSupported("GL_EXT_texture_cube_map"))
00452 {
00453 // normalizationTex = CreateNormalizationCubeMap(64);
00454 normalizationTex = CreateProceduralCubeMap(64, GL_RGB, IllumMapEval);
00455 }
00456
00457 // Create labels for celestial sphere
00458 {
00459 char buf[10];
00460 int i;
00461
00462 coordLabels = new SphericalCoordLabel[nCoordLabels];
00463 for (i = 0; i < 12; i++)
00464 {
00465 coordLabels[i].ra = float(i * 2);
00466 coordLabels[i].dec = 0;
00467 sprintf(buf, "%dh", i * 2);
00468 coordLabels[i].label = string(buf);
00469 }
00470
00471 coordLabels[12] = SphericalCoordLabel(0, -75);
00472 coordLabels[13] = SphericalCoordLabel(0, -60);
00473 coordLabels[14] = SphericalCoordLabel(0, -45);
00474 coordLabels[15] = SphericalCoordLabel(0, -30);
00475 coordLabels[16] = SphericalCoordLabel(0, -15);
00476 coordLabels[17] = SphericalCoordLabel(0, 15);
00477 coordLabels[18] = SphericalCoordLabel(0, 30);
00478 coordLabels[19] = SphericalCoordLabel(0, 45);
00479 coordLabels[20] = SphericalCoordLabel(0, 60);
00480 coordLabels[21] = SphericalCoordLabel(0, 75);
00481 for (i = 22; i < nCoordLabels; i++)
00482 {
00483 coordLabels[i].ra = 12;
00484 coordLabels[i].dec = coordLabels[i - 10].dec;
00485 }
00486
00487 for (i = 12; i < nCoordLabels; i++)
00488 {
00489 char buf[10];
00490 sprintf(buf, "%d", (int) coordLabels[i].dec);
00491 coordLabels[i].label = string(buf);
00492 }
00493 }
00494
00495 commonDataInitialized = true;
00496 }
00497
00498 if (context->extensionSupported("GL_EXT_rescale_normal"))
00499 {
00500 // We need this enabled because we use glScale, but only
00501 // with uniform scale factors.
00502 DPRINTF(1, "Renderer: EXT_rescale_normal supported.\n");
00503 useRescaleNormal = true;
00504 glEnable(GL_RESCALE_NORMAL_EXT);
00505 }
00506
00507 if (context->extensionSupported("GL_ARB_point_sprite"))
00508 {
00509 DPRINTF(1, "Renderer: point sprites supported.\n");
00510 usePointSprite = true;
00511 }
00512
00513 // Ugly renderer-specific bug workarounds follow . . .
00514 char* glRenderer = (char*) glGetString(GL_RENDERER);
00515 if (glRenderer != NULL)
00516 {
00517 // Fog is broken with vertex program emulation in most versions of
00518 // the GF 1 and 2 drivers; we need to detect this and disable
00519 // vertex programs which output fog coordinates
00520 if (strstr(glRenderer, "GeForce3") != NULL ||
00521 strstr(glRenderer, "GeForce4") != NULL)
00522 {
00523 buggyVertexProgramEmulation = false;
00524 }
00525
00526 if (strstr(glRenderer, "Savage4") != NULL ||
00527 strstr(glRenderer, "ProSavage") != NULL)
00528 {
00529 // S3 Savage4 drivers appear to rescale normals without reporting
00530 // EXT_rescale_normal. Lighting will be messed up unless
00531 // we set the useRescaleNormal flag.
00532 useRescaleNormal = true;
00533 }
00534 }
00535
00536 // More ugly hacks; according to Matt Craighead at NVIDIA, an NVIDIA
00537 // OpenGL driver that reports version 1.3.1 or greater will have working
00538 // fog in emulated vertex programs.
00539 char* glVersion = (char*) glGetString(GL_VERSION);
00540 if (glVersion != NULL)
00541 {
00542 int major = 0, minor = 0, extra = 0;
00543 int nScanned = sscanf(glVersion, "%d.%d.%d", &major, &minor, &extra);
00544
00545 if (nScanned >= 2)
00546 {
00547 if (major > 1 || minor > 3 || (minor == 3 && extra >= 1))
00548 buggyVertexProgramEmulation = false;
00549 }
00550 }
00551
00552 glLoadIdentity();
00553
00554 glEnable(GL_CULL_FACE);
00555 glCullFace(GL_BACK);
00556
00557 glEnable(GL_COLOR_MATERIAL);
00558 glEnable(GL_LIGHTING);
00559 glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE);
00560
00561 // LEQUAL rather than LESS required for multipass rendering
00562 glDepthFunc(GL_LEQUAL);
00563
00564 resize(winWidth, winHeight);
00565
00566 return true;
00567 }
|
|
||||||||||||
|
Definition at line 6787 of file render.cpp. References addLabel(), conjugate(), Asterism::getChain(), Asterism::getChainCount(), Asterism::getName(), I18nConstellationLabels, labelMode, Vector3< T >::x, Vector3< T >::y, and Vector3< T >::z. Referenced by render(). 06789 {
06790 Point3f observerPos = (Point3f) observer.getPosition();
06791
06792 for (AsterismList::const_iterator iter = asterisms.begin();
06793 iter != asterisms.end(); iter++)
06794 {
06795 Asterism* ast = *iter;
06796 if (ast->getChainCount() > 0)
06797 {
06798 const Asterism::Chain& chain = ast->getChain(0);
06799
06800 if (chain.size() > 0)
06801 {
06802 // The constellation label is positioned at the average
06803 // position of all stars in the first chain. This usually
06804 // gives reasonable results.
06805 Vec3f avg(0, 0, 0);
06806 for (Asterism::Chain::const_iterator iter = chain.begin();
06807 iter != chain.end(); iter++)
06808 avg += (*iter - Point3f(0, 0, 0));
06809
06810 avg = avg / (float) chain.size();
06811 avg = avg * 1e6f;
06812 Vec3f rpos = Point3f(avg.x, avg.y, avg.z) - observerPos;
06813 if ((rpos * conjugate(observer.getOrientation()).toMatrix3()).z < 0)
06814 {
06815 addLabel(ast->getName(labelMode & I18nConstellationLabels),
06816 Color(0.5f, 0.0f, 1.0f, 1.0f),
06817 Point3f(rpos.x, rpos.y, rpos.z));
06818 }
06819 }
06820 }
06821 }
06822 }
|
|
||||||||||||||||
|
Definition at line 6748 of file render.cpp. References astro::absToAppMag(), addLabel(), conjugate(), distance(), distanceLimit, Point3< T >::distanceTo(), faintestMag, Star::getAbsoluteMagnitude(), Star::getPosition(), astro::heliocentricPosition(), labelledStars, Vector3< T >::x, Point3< T >::x, Vector3< T >::y, Point3< T >::y, Vector3< T >::z, and Point3< T >::z. Referenced by render(). 06751 {
06752 Point3f observerPos_ly = (Point3f) observer.getPosition() * 1e-6f;
06753
06754 for (vector<StarLabel>::const_iterator iter = labelledStars.begin(); iter != labelledStars.end(); ++iter)
06755 {
06756 Star* star = iter->obj;
06757 Point3f pos = star->getPosition();
06758 float distance = pos.distanceTo(observerPos_ly);
06759 float appMag = (distance > 0.0f) ?
06760 astro::absToAppMag(star->getAbsoluteMagnitude(), distance) : -100.0f;
06761
06762 if (appMag < faintestMag && distance <= distanceLimit)
06763 {
06764 Vec3f rpos = pos - observerPos_ly;
06765
06766 // Use a more accurate and expensive calculation if the
06767 // distance to the star is less than a light year. Single
06768 // precision arithmetic isn't good enough when we're very close
06769 // to the star.
06770 if (distance < 1.0f)
06771 {
06772 Point3d hpos = astro::heliocentricPosition(observer.getPosition(), pos);
06773 rpos = Vec3f((float) -hpos.x, (float) -hpos.y, (float) -hpos.z);
06774 }
06775
06776 if ((rpos * conjugate(observer.getOrientation()).toMatrix3()).z < 0)
06777 {
06778 addLabel(iter->label,
06779 Color(0.3f, 0.3f, 1.0f),
06780 Point3f(rpos.x, rpos.y, rpos.z));
06781 }
06782 }
06783 }
06784 }
|
|
|
Definition at line 7378 of file render.cpp. References Surface::appearanceFlags, Surface::baseTexture, GLContext::bumpMappingSupported(), Surface::bumpTexture, context, MultiResTexture::find(), InvalidResource, Surface::nightTexture, renderFlags, ShowCloudMaps, ShowNightMaps, Surface::specularTexture, MultiResTexture::tex, and textureResolution. Referenced by object_preloadtexture(), and CommandPreloadTextures::process(). 07379 {
07380 Surface& surface = body->getSurface();
07381
07382 if (surface.baseTexture.tex[textureResolution] != InvalidResource)
07383 surface.baseTexture.find(textureResolution);
07384 if ((surface.appearanceFlags & Surface::ApplyBumpMap) != 0 &&
07385 context->bumpMappingSupported() &&
07386 surface.bumpTexture.tex[textureResolution] != InvalidResource)
07387 surface.bumpTexture.find(textureResolution);
07388 if ((surface.appearanceFlags & Surface::ApplyNightMap) != 0 &&
07389 (renderFlags & ShowNightMaps) != 0)
07390 surface.nightTexture.find(textureResolution);
07391 if ((surface.appearanceFlags & Surface::SeparateSpecularMap) != 0 &&
07392 surface.specularTexture.tex[textureResolution] != InvalidResource)
07393 surface.specularTexture.find(textureResolution);
07394
07395 if ((renderFlags & ShowCloudMaps) != 0 &&
07396 body->getAtmosphere() != NULL &&
07397 body->getAtmosphere()->cloudTexture.tex[textureResolution] != InvalidResource)
07398 {
07399 body->getAtmosphere()->cloudTexture.find(textureResolution);
07400 }
07401
07402 if (body->getRings() != NULL &&
07403 body->getRings()->texture.tex[textureResolution] != InvalidResource)
07404 {
07405 body->getRings()->texture.find(textureResolution);
07406 }
07407 }
|
|
||||||||||||||||||||
|
Definition at line 1248 of file render.cpp. References ambientColor, ambientLightLevel, astrocentricPosition(), autoMag(), Texture::bind(), Color::blue(), BodyLabelMask, brightnessScale, calcPixelSize(), Math< T >::clamp(), clearLabels(), conjugate(), ConstellationLabels, CoronaHeight, cos(), degToRad(), depthSortedLabels, disableSmoothLines(), displayedSurface, distance(), Point3< T >::distanceFromOrigin(), enableSmoothLines(), faintestMag, faintestPlanetMag, FAR_DIST, fov, Asterism::getChain(), SolarSystem::getPlanets(), glAmbientLightColor(), glRotate(), glVertex(), Color::green(), Atmosphere::height, InvalidResource, labelConstellations(), labelledStars, labelMode, labels, labelStars(), lightSourceLists, locationFilter, max, MaxFarNearRatio, min, MinNearPlaneDistance, modelMatrix, NEAR_DIST, nearStars, Vector3< T >::normalize(), orbitCache, orbitMask, pixelSize, projMatrix, radToDeg(), Color::red(), renderCelestialSphere(), renderCometTail(), renderDeepSkyObjects(), renderFlags, renderForegroundOrbits(), renderLabels(), renderList, renderMarkers(), renderMode, renderOrbits(), renderPlanet(), renderPlanetarySystem(), renderSortedLabels(), renderStar(), renderStars(), saturationMag, saturationMagNight, Matrix3< float >::scaling(), setFieldOfView(), setupLightSources(), ShowAtmospheres, ShowAutoMag, ShowBoundaries, ShowCelestialSphere, ShowDiagrams, ShowMarkers, ShowOrbits, ShowPlanets, ShowSmoothLines, ShowStars, sqrt(), square(), StarLabels, starTex, Frustum::testSphere(), Quaternion< T >::w, windowHeight, windowWidth, Quaternion< T >::x, Point3< T >::x, Quaternion< T >::y, Point3< T >::y, Quaternion< T >::z, and Point3< T >::z. Referenced by DSORenderer::process(). 01252 {
01253 // Get the observer's time
01254 double now = observer.getTime();
01255
01256 // Compute the size of a pixel
01257 setFieldOfView(radToDeg(observer.getFOV()));
01258 pixelSize = calcPixelSize(fov, (float) windowHeight);
01259 // Set up the projection we'll use for rendering stars.
01260 glMatrixMode(GL_PROJECTION);
01261 glLoadIdentity();
01262 gluPerspective(fov,
01263 (float) windowWidth / (float) windowHeight,
01264 NEAR_DIST, FAR_DIST);
01265
01266 // Set the modelview matrix
01267 glMatrixMode(GL_MODELVIEW);
01268
01269 // Get the displayed surface texture set to use from the observer
01270 displayedSurface = observer.getDisplayedSurface();
01271
01272 locationFilter = observer.getLocationFilter();
01273
01274 // Set up the camera
01275 Point3f observerPos = (Point3f) observer.getPosition();
01276 observerPos.x *= 1e-6f;
01277 observerPos.y *= 1e-6f;
01278 observerPos.z *= 1e-6f;
01279 glPushMatrix();
01280 glRotate(observer.getOrientation());
01281
01282 // Get the model matrix *before* translation. We'll use this for
01283 // positioning star and planet labels.
01284 glGetDoublev(GL_MODELVIEW_MATRIX, modelMatrix);
01285 glGetDoublev(GL_PROJECTION_MATRIX, projMatrix);
01286
01287 clearLabels();
01288
01289 // Put all solar system bodies into the render list. Stars close and
01290 // large enough to have discernible surface detail are also placed in
01291 // renderList.
01292 renderList.clear();
01293
01294 // See if we want to use AutoMag.
01295 if ((renderFlags & ShowAutoMag) != 0)
01296 {
01297 autoMag(faintestMag);
01298 }
01299 else
01300 {
01301 faintestMag = faintestMagNight;
01302 saturationMag = saturationMagNight;
01303 }
01304
01305 // Automatic FOV-based adjustment of limiting magnitude for solar system
01306 // objects. Now that we have the automag feature, this hack should no
01307 // longer be required.
01308 // faintestPlanetMag = faintestMag + (2.5f * (float) log10((double) square(45.0f / fov)));
01309 faintestPlanetMag = faintestMag;
01310
01311 if (renderFlags & ShowPlanets)
01312 {
01313 nearStars.clear();
01314 universe.getNearStars(observer.getPosition(), 1.0f, nearStars);
01315
01316 unsigned int solarSysIndex = 0;
01317 for (vector<const Star*>::const_iterator iter = nearStars.begin();
01318 iter != nearStars.end(); iter++)
01319 {
01320 const Star* sun = *iter;
01321 SolarSystem* solarSystem = universe.getSolarSystem(sun);
01322 if (solarSystem != NULL)
01323 {
01324 setupLightSources(nearStars, *sun, now,
01325 lightSourceLists[solarSysIndex]);
01326 renderPlanetarySystem(*sun,
01327 *solarSystem->getPlanets(),
01328 observer,
01329 now,
01330 solarSysIndex,
01331 (labelMode & (BodyLabelMask)) != 0);
01332 solarSysIndex++;
01333 }
01334 }
01335 starTex->bind();
01336 }
01337
01338 Color skyColor(0.0f, 0.0f, 0.0f);
01339
01340 // Scan through the render list to see if we're inside a planetary
01341 // atmosphere. If so, we need to adjust the sky color as well as the
01342 // limiting magnitude of stars (so stars aren't visible in the daytime
01343 // on planets with thick atmospheres.)
01344 if ((renderFlags & ShowAtmospheres) != 0)
01345 {
01346 for (vector<RenderListEntry>::iterator iter = renderList.begin();
01347 iter != renderList.end(); iter++)
01348 {
01349 if (iter->body != NULL && iter->body->getAtmosphere() != NULL)
01350 {
01351 // Compute the density of the atmosphere, and from that
01352 // the amount light scattering. It's complicated by the
01353 // possibility that the planet is oblate and a simple distance
01354 // to sphere calculation will not suffice.
01355 const Atmosphere* atmosphere = iter->body->getAtmosphere();
01356 float radius = iter->body->getRadius();
01357 float oblateness = iter->body->getOblateness();
01358 Vec3f recipSemiAxes(1.0f, 1.0f / (1.0f - oblateness), 1.0f);
01359 Mat3f A = Mat3f::scaling(recipSemiAxes);
01360 Vec3f eyeVec = iter->position - Point3f(0.0f, 0.0f, 0.0f);
01361 eyeVec *= (1.0f / radius);
01362
01363 // Compute the orientation of the planet before axial rotation
01364 Quatd qd = iter->body->getEclipticalToEquatorial(now);
01365 Quatf q((float) qd.w, (float) qd.x, (float) qd.y, (float) qd.z);
01366 eyeVec = eyeVec * conjugate(q).toMatrix3();
01367
01368 // ellipDist is not the true distance from the surface unless
01369 // the planet is spherical. The quantity that we do compute
01370 // is the distance to the surface along a line from the eye
01371 // position to the center of the ellipsoid.
01372 float ellipDist = (float) sqrt((eyeVec * A) * (eyeVec * A)) - 1.0f;
01373 if (ellipDist < atmosphere->height / radius &&
01374 atmosphere->height > 0.0f)
01375 {
01376 float density = 1.0f - ellipDist /
01377 (atmosphere->height / radius);
01378 if (density > 1.0f)
01379 density = 1.0f;
01380
01381 Vec3f sunDir = iter->sun;
01382 Vec3f normal = Point3f(0.0f, 0.0f, 0.0f) - iter->position;
01383 sunDir.normalize();
01384 normal.normalize();
01385 float illumination = Math<float>::clamp((sunDir * normal) + 0.2f);
01386
01387 float lightness = illumination * density;
01388 faintestMag = faintestMag - 15.0f * lightness;
01389 saturationMag = saturationMag - 15.0f * lightness;
01390 }
01391 }
01392 }
01393 }
01394
01395 // Now we need to determine how to scale the brightness of stars. The
01396 // brightness will be proportional to the apparent magnitude, i.e.
01397 // a logarithmic function of the stars apparent brightness. This mimics
01398 // the response of the human eye. We sort of fudge things here and
01399 // maintain a minimum range of four magnitudes between faintest visible
01400 // and saturation; this keeps stars from popping in or out as the sun
01401 // sets or rises.
01402 if (faintestMag - saturationMag >= 4.0f)
01403 brightnessScale = 1.0f / (faintestMag - saturationMag);
01404 else
01405 brightnessScale = 0.25f;
01406
01407 ambientColor = Color(ambientLightLevel, ambientLightLevel, ambientLightLevel);
01408
01409 // Create the ambient light source. For realistic scenes in space, this
01410 // should be black.
01411 glAmbientLightColor(ambientColor);
01412
01413 glClearColor(skyColor.red(), skyColor.green(), skyColor.blue(), 1);
01414 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
01415
01416 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
01417
01418 glDisable(GL_LIGHTING);
01419 glDepthMask(GL_FALSE);
01420 glEnable(GL_BLEND);
01421 glEnable(GL_TEXTURE_2D);
01422
01423 if ((renderFlags & ShowCelestialSphere) != 0)
01424 {
01425 glColor4f(0.3f, 0.7f, 0.7f, 0.55f);
01426 glDisable(GL_TEXTURE_2D);
01427 if ((renderFlags & ShowSmoothLines) != 0)
01428 enableSmoothLines();
01429 renderCelestialSphere(observer);
01430 if ((renderFlags & ShowSmoothLines) != 0)
01431 disableSmoothLines();
01432 glEnable(GL_BLEND);
01433 glEnable(GL_TEXTURE_2D);
01434 }
01435
01436 if (universe.getDSOCatalog() != NULL)
01437 renderDeepSkyObjects(universe, observer, faintestMag);
01438
01439 // Translate the camera before rendering the stars
01440 glPushMatrix();
01441 glTranslatef(-observerPos.x, -observerPos.y, -observerPos.z);
01442 // Render stars
01443 glBlendFunc(GL_SRC_ALPHA, GL_ONE);
01444 if ((renderFlags & ShowStars) != 0 && universe.getStarCatalog() != NULL)
01445 renderStars(*universe.getStarCatalog(), faintestMag, observer);
01446
01447 // Render asterisms
01448 if ((renderFlags & ShowDiagrams) != 0 && universe.getAsterisms() != NULL)
01449 {
01450 glColor4f(0.28f, 0.0f, 0.66f, 0.96f);
01451 glDisable(GL_TEXTURE_2D);
01452 if ((renderFlags & ShowSmoothLines) != 0)
01453 enableSmoothLines();
01454 AsterismList* asterisms = universe.getAsterisms();
01455 for (AsterismList::const_iterator iter = asterisms->begin();
01456 iter != asterisms->end(); iter++)
01457 {
01458 Asterism* ast = *iter;
01459
01460 for (int i = 0; i < ast->getChainCount(); i++)
01461 {
01462 const Asterism::Chain& chain = ast->getChain(i);
01463
01464 glBegin(GL_LINE_STRIP);
01465 for (Asterism::Chain::const_iterator iter = chain.begin();
01466 iter != chain.end(); iter++)
01467 glVertex(*iter);
01468 glEnd();
01469 }
01470 }
01471
01472 if ((renderFlags & ShowSmoothLines) != 0)
01473 disableSmoothLines();
01474 }
01475
01476 if ((renderFlags & ShowBoundaries) != 0)
01477 {
01478 glColor4f(0.8f, 0.33f, 0.63f, 0.35f);
01479 glDisable(GL_TEXTURE_2D);
01480 if ((renderFlags & ShowSmoothLines) != 0)
01481 enableSmoothLines();
01482 if (universe.getBoundaries() != NULL)
01483 universe.getBoundaries()->render();
01484 if ((renderFlags & ShowSmoothLines) != 0)
01485 disableSmoothLines();
01486 }
01487
01488 if ((labelMode & StarLabels) != 0 && universe.getStarCatalog() != NULL)
01489 labelStars(labelledStars, *universe.getStarCatalog(), observer);
01490 if ((labelMode & ConstellationLabels) != 0 &&
01491 universe.getAsterisms() != NULL)
01492 labelConstellations(*universe.getAsterisms(), observer);
01493
01494 glPopMatrix();
01495
01496 // Render orbit paths
01497 if ((renderFlags & ShowOrbits) != 0 && orbitMask != 0)
01498 {
01499 // Clear the keep flag for all orbits in the cache; if they're not
01500 // used when rendering this frame, they'll get marked for
01501 // recycling.
01502 vector<CachedOrbit*>::const_iterator iter;
01503 for (iter = orbitCache.begin(); iter != orbitCache.end(); iter++)
01504 (*iter)->keep = false;
01505
01506 glDisable(GL_LIGHTING);
01507 glDisable(GL_TEXTURE_2D);
01508 if ((renderFlags & ShowSmoothLines) != 0)
01509 enableSmoothLines();
01510
01511 for (vector<const Star*>::const_iterator starIter = nearStars.begin();
01512 starIter != nearStars.end(); starIter++)
01513 {
01514 const Star* sun = *starIter;
01515 SolarSystem* solarSystem = universe.getSolarSystem(sun);
01516
01517 if (solarSystem != NULL)
01518 {
01519 Point3d obsPos = astrocentricPosition(observer.getPosition(),
01520 *sun, observer.getTime());
01521 glPushMatrix();
01522 glTranslatef((float) astro::kilometersToAU(-obsPos.x),
01523 (float) astro::kilometersToAU(-obsPos.y),
01524 (float) astro::kilometersToAU(-obsPos.z));
01525 renderOrbits(solarSystem->getPlanets(), sel, now,
01526 obsPos, Point3d(0.0, 0.0, 0.0));
01527 glPopMatrix();
01528 }
01529 }
01530
01531 if ((renderFlags & ShowSmoothLines) != 0)
01532 disableSmoothLines();
01533
01534 // Mark for recycling all unused orbits in the cache
01535 for (iter = orbitCache.begin(); iter != orbitCache.end(); iter++)
01536 {
01537 if (!(*iter)->keep)
01538 (*iter)->body = NULL;
01539 }
01540 }
01541
01542 renderLabels();
01543
01544 glPolygonMode(GL_FRONT, (GLenum) renderMode);
01545 glPolygonMode(GL_BACK, (GLenum) renderMode);
01546
01547 {
01548 Frustum frustum(degToRad(fov),
01549 (float) windowWidth / (float) windowHeight,
01550 MinNearPlaneDistance);
01551 Mat3f viewMat = conjugate(observer.getOrientation()).toMatrix3();
01552
01553 // Remove objects from the render list that lie completely outside the
01554 // view frustum.
01555 vector<RenderListEntry>::iterator notCulled = renderList.begin();
01556 for (vector<RenderListEntry>::iterator iter = renderList.begin();
01557 iter != renderList.end(); iter++)
01558 {
01559 Point3f center = iter->position * viewMat;
01560
01561 bool convex = true;
01562 float radius = 1.0f;
01563 float cullRadius = 1.0f;
01564 float cloudHeight = 0.0f;
01565 if (iter->body != NULL)
01566 {
01567 radius = iter->body->getBoundingRadius();
01568 if (iter->body->getRings() != NULL)
01569 {
01570 radius = iter->body->getRings()->outerRadius;
01571 convex = false;
01572 }
01573
01574 if (iter->body->getModel() != InvalidResource)
01575 convex = false;
01576
01577 cullRadius = radius;
01578 if (iter->body->getAtmosphere() != NULL)
01579 {
01580 cullRadius += iter->body->getAtmosphere()->height;
01581 cloudHeight = iter->body->getAtmosphere()->cloudHeight;
01582 }
01583 }
01584 else if (iter->star != NULL)
01585 {
01586 radius = iter->star->getRadius();
01587 cullRadius = radius * (1.0f + CoronaHeight);
01588 }
01589
01590 // Test the object's bounding sphere against the view frustum
01591 if (frustum.testSphere(center, cullRadius) != Frustum::Outside)
01592 {
01593 float nearZ = center.distanceFromOrigin() - radius;
01594 float maxSpan = (float) sqrt(square((float) windowWidth) +
01595 square((float) windowHeight));
01596
01597 nearZ = -nearZ * (float) cos(degToRad(fov / 2)) *
01598 ((float) windowHeight / maxSpan);
01599
01600 if (nearZ > -MinNearPlaneDistance)
01601 iter->nearZ = -MinNearPlaneDistance;
01602 else
01603 iter->nearZ = nearZ;
01604
01605 if (!convex)
01606 {
01607 iter->farZ = center.z - radius;
01608 if (iter->farZ / iter->nearZ > MaxFarNearRatio)
01609 iter->nearZ = iter->farZ / MaxFarNearRatio;
01610 }
01611 else
01612 {
01613 // Make the far plane as close as possible
01614 float d = center.distanceFromOrigin();
01615
01616 // Account for the oblateness
01617 float eradius = radius;
01618 if (iter->body != NULL)
01619 eradius *= 1.0f - iter->body->getOblateness();
01620
01621 if (d > eradius)
01622 {
01623 // Multiply by a factor to eliminate overaggressive
01624 // clipping due to limited floating point precision
01625 iter->farZ = (float) (sqrt(square(d) -
01626 square(eradius)) * -1.1);
01627 }
01628 else
01629 {
01630 // We're inside the bounding sphere (and, if the planet
01631 // is spherical, inside the planet.)
01632 iter->farZ = iter->nearZ * 2.0f;
01633 }
01634
01635 if (cloudHeight > 0.0f && d < eradius + cloudHeight)
01636 {
01637 // If there's a cloud layer, we need to move the
01638 // far plane out so that the clouds aren't clipped
01639 float cloudLayerRadius = eradius + cloudHeight;
01640 iter->farZ -= (float) sqrt(square(cloudLayerRadius) -
01641 square(eradius));
01642 }
01643 }
01644
01645 *notCulled = *iter;
01646 notCulled++;
01647 }
01648 }
01649
01650 renderList.resize(notCulled - renderList.begin());
01651
01652 // The calls to renderSolarSystem/renderStars filled renderList
01653 // with visible planetary bodies. Sort it by distance, then
01654 // render each entry.
01655 stable_sort(renderList.begin(), renderList.end());
01656
01657 // Sort the labels
01658 sort(depthSortedLabels.begin(), depthSortedLabels.end());
01659
01660 int nEntries = renderList.size();
01661
01662 // Determine how to split up the depth buffer. Typically, each body
01663 // with an apparent size greater than one pixel is allocated its own
01664 // depth buffer range. However, this will not correctly handle
01665 // overlapping objects. If two objects overlap in depth, we attempt
01666 // to coalesce their depth buckets. Coalescing will succeed as long
01667 // as the far / near plane ratio is not too large. If it does exceed
01668 // the limit, coaslescing fails and the objects may not be rendered
01669 // correctly, though the result should be superior to throwing away
01670 // depth buffer precision by allowing the far / near ratio to get too
01671 // large.
01672 int nDepthBuckets = 1;
01673 int i;
01674 {
01675 float lastNear = 0.0f;
01676 float lastFar = 0.0f;
01677 int firstCoalesced = 0;
01678
01679 for (i = 0; i < nEntries; i++)
01680 {
01681 // Don't worry about objects that are smaller than a pixel,
01682 // as they'll just be rendered as points.
01683 if (renderList[i].discSizeInPixels > 1)
01684 {
01685 if (nDepthBuckets == 1 || renderList[i].nearZ <= lastFar)
01686 {
01687 // This object doesn't overlap any others in depth,
01688 // no need to coaslesce.
01689 nDepthBuckets++;
01690 firstCoalesced = i;
01691 lastNear = renderList[i].nearZ;
01692 lastFar = renderList[i].farZ;
01693 }
01694 else
01695 {
01696 // Consider coalescing this object with the previous
01697 // one.
01698 float farthest = min(lastFar, renderList[i].farZ);
01699 float nearest = max(lastNear, renderList[i].nearZ);
01700 static int blah = 0;
01701
01702 // Need just a bit of slack in the farthest/nearest
01703 // ratio test.
01704 if (farthest / nearest < MaxFarNearRatio * 1.01f)
01705 {
01706 // Far/near ratio is acceptable, so coalesce
01707 // this object's depth bucket with the previous
01708 // one.
01709 for (int j = firstCoalesced; j <= i; j++)
01710 {
01711 renderList[j].farZ = farthest;
01712 renderList[j].nearZ = nearest;
01713 }
01714 #if DEBUG_COALESCE
01715 clog << "Coalesce #" << i << ": " <<
01716 renderList[i].body->getName() << ", " <<
01717 nearest << ", " << farthest << " -- " << blah++ << '\n';
01718 #endif
01719 lastNear = nearest;
01720 lastFar = farthest;
01721 }
01722 else
01723 {
01724 // Coalesce failed, so create a new depth bucket
01725 // for this object.
01726 nDepthBuckets++;
01727 firstCoalesced = i;
01728 lastNear = renderList[i].nearZ;
01729 lastFar = renderList[i].farZ;
01730 #if DEBUG_COALESCE
01731 clog << "Coalesce #" << i << ": " <<
01732 renderList[i].body->getName() << " failed! " <<
01733 nearest << ", " << farthest << " -- " << blah++ << '\n';
01734 #endif
01735 }
01736 }
01737 renderList[i].depthBucket = nDepthBuckets - 1;
01738 }
01739 }
01740 }
01741
01742 float depthRange = 1.0f / (float) nDepthBuckets;
01743
01744 int depthBucket = nDepthBuckets - 1;
01745 i = nEntries - 1;
01746
01747 // Set up the depth bucket.
01748 glDepthRange(depthBucket * depthRange, (depthBucket + 1) * depthRange);
01749
01750 // Set the initial near and far plane distance; any reasonable choice
01751 // for these will do, since different values will be chosen as soon
01752 // as we need to render a body as a mesh.
01753 float nearPlaneDistance = 1.0f;
01754 float farPlaneDistance = 10.0f;
01755 glMatrixMode(GL_PROJECTION);
01756 glLoadIdentity();
01757 gluPerspective(fov, (float) windowWidth / (float) windowHeight,
01758 nearPlaneDistance, farPlaneDistance);
01759 glMatrixMode(GL_MODELVIEW);
01760
01761 vector<Label>::iterator label = depthSortedLabels.begin();
01762
01763 // Render all the bodies in the render list.
01764 for (i = nEntries - 1; i >= 0; i--)
01765 {
01766 label = renderSortedLabels(label, -renderList[i].farZ);
01767
01768 if (renderList[i].discSizeInPixels > 1)
01769 {
01770 depthBucket = renderList[i].depthBucket;
01771 glDepthRange(depthBucket * depthRange, (depthBucket + 1) * depthRange);
01772
01773 nearPlaneDistance = renderList[i].nearZ * -0.9f;
01774 farPlaneDistance = renderList[i].farZ * -1.5f;
01775 if (nearPlaneDistance < MinNearPlaneDistance)
01776 nearPlaneDistance = MinNearPlaneDistance;
01777 if (farPlaneDistance / nearPlaneDistance > MaxFarNearRatio)
01778 farPlaneDistance = nearPlaneDistance * MaxFarNearRatio;
01779
01780 glMatrixMode(GL_PROJECTION);
01781 glLoadIdentity();
01782 gluPerspective(fov, (float) windowWidth / (float) windowHeight,
01783 nearPlaneDistance, farPlaneDistance);
01784 glMatrixMode(GL_MODELVIEW);
01785 }
01786
01787 if (renderList[i].body != NULL)
01788 {
01789 if (renderList[i].isCometTail)
01790 {
01791 renderCometTail(*renderList[i].body,
01792 renderList[i].position,
01793 renderList[i].distance,
01794 renderList[i].appMag,
01795 now,
01796 observer.getOrientation(),
01797 lightSourceLists[renderList[i].solarSysIndex],
01798 nearPlaneDistance, farPlaneDistance);
01799 }
01800 else
01801 {
01802 renderPlanet(*renderList[i].body,
01803 renderList[i].position,
01804 renderList[i].distance,
01805 renderList[i].appMag,
01806 now,
01807 observer.getOrientation(),
01808 lightSourceLists[renderList[i].solarSysIndex],
01809 nearPlaneDistance, farPlaneDistance);
01810
01811 renderForegroundOrbits(renderList[i].body->getSatellites(),
01812 renderList[i].position,
01813 renderList[i].distance,
01814 renderList[i].discSizeInPixels,
01815 sel,
01816 now);
01817 }
01818 }
01819 else if (renderList[i].star != NULL)
01820 {
01821 renderStar(*renderList[i].star,
01822 renderList[i].position,
01823 renderList[i].distance,
01824 renderList[i].appMag,
01825 observer.getOrientation(),
01826 now,
01827 nearPlaneDistance, farPlaneDistance);
01828 }
01829
01830 // If this body is larger than a pixel, we rendered it as a mesh
01831 // instead of just a particle. We move to the next depth buffer
01832 // bucket before proceeding with further rendering.
01833 if (renderList[i].discSizeInPixels > 1)
01834 {
01835 depthBucket--;
01836 glDepthRange(depthBucket * depthRange, (depthBucket + 1) * depthRange);
01837 }
01838 }
01839
01840 renderSortedLabels(label, 0.0f);
01841
01842 // reset the depth range
01843 glDepthRange(0, 1);
01844 }
01845
01846 glPopMatrix();
01847
01848 glEnable(GL_TEXTURE_2D);
01849 glDisable(GL_LIGHTING);
01850 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
01851
01852 glPolygonMode(GL_FRONT, GL_FILL);
01853 glPolygonMode(GL_BACK, GL_FILL);
01854
01855 {
01856 Mat3f m = observer.getOrientation().toMatrix3();
01857 for (int i = 0; i < (int) labels.size(); i++)
01858 {
01859
01860 }
01861 }
01862
01863 if ((renderFlags & ShowMarkers) != 0)
01864 {
01865 renderMarkers(*universe.getMarkers(),
01866 observer.getPosition(),
01867 observer.getOrientation(),
01868 now);
01869 }
01870
01871 glDisable(GL_BLEND);
01872 glDepthMask(GL_TRUE);
01873 glEnable(GL_LIGHTING);
01874
01875 #if 0
01876 int errCode = glGetError();
01877 if (errCode != GL_NO_ERROR)
01878 {
01879 cout << "glError: " << (char*) gluErrorString(errCode) << '\n';
01880 }
01881 #endif
01882 }
|
|
||||||||||||||||||||||||||||||||||||
|
Definition at line 1915 of file render.cpp. References abs(), Texture::bind(), brightnessBias, brightnessScale, clamp(), conjugate(), corrFac, fov, FOV, glareTex, glColor(), glVertex(), MaxScaledDiscStarSize, min, pixelSize, saturationMag, ScaledDiscStars, starStyle, starTex, Point3< T >::x, Point3< T >::y, and Point3< T >::z. Referenced by renderPlanet(), and renderStar(). 01923 {
01924 float maxDiscSize = (starStyle == ScaledDiscStars) ? MaxScaledDiscStarSize : 1.0f;
01925 float maxBlendDiscSize = maxDiscSize + 3.0f;
01926 float discSize = 1.0f;
01927
01928 if (discSizeInPixels < maxBlendDiscSize || useHaloes)
01929 {
01930 float a = 1;
01931 float fade = 1.0f;
01932
01933 if (discSizeInPixels > maxDiscSize)
01934 {
01935 fade = (maxBlendDiscSize - discSizeInPixels) /
01936 (maxBlendDiscSize - maxDiscSize - 1.0f);
01937 if (fade > 1)
01938 fade = 1;
01939 }
01940
01941 a = (_faintestMag - appMag) * brightnessScale + brightnessBias;
01942 if (starStyle == ScaledDiscStars && a > 1.0f)
01943 discSize = min(discSize * (2.0f * a - 1.0f), maxDiscSize);
01944 a = clamp(a) * fade;
01945
01946 // We scale up the particle by a factor of 1.6 (at fov = 45deg)
01947 // so that it's more
01948 // visible--the texture we use has fuzzy edges, and if we render it
01949 // in just one pixel, it's likely to disappear. Also, the render
01950 // distance is scaled by a factor of 0.1 so that we're rendering in
01951 // front of any mesh that happens to be sharing this depth bucket.
01952 // What we really want is to render the particle with the frontmost
01953 // z value in this depth bucket, and scaling the render distance is
01954 // just hack to accomplish this. There are cases where it will fail
01955 // and a more robust method should be implemented.
01956
01957 float size = discSize * pixelSize * 1.6f * renderZ / corrFac;
01958 float posScale = abs(renderZ / (position * conjugate(orientation).toMatrix3()).z);
01959
01960 Point3f center(position.x * posScale,
01961 position.y * posScale,
01962 position.z * posScale);
01963 Mat3f m = orientation.toMatrix3();
01964 Vec3f v0 = Vec3f(-1, -1, 0) * m;
01965 Vec3f v1 = Vec3f( 1, -1, 0) * m;
01966 Vec3f v2 = Vec3f( 1, 1, 0) * m;
01967 Vec3f v3 = Vec3f(-1, 1, 0) * m;
01968
01969 starTex->bind();
01970 glColor(color, a);
01971 glBegin(GL_QUADS);
01972 glTexCoord2f(0, 0);
01973 glVertex(center + (v0 * size));
01974 glTexCoord2f(1, 0);
01975 glVertex(center + (v1 * size));
01976 glTexCoord2f(1, 1);
01977 glVertex(center + (v2 * size));
01978 glTexCoord2f(0, 1);
01979 glVertex(center + (v3 * size));
01980 glEnd();
01981
01982 // If the object is brighter than magnitude 1, add a halo around it to
01983 // make it appear more brilliant. This is a hack to compensate for the
01984 // limited dynamic range of monitors.
01985 //
01986 // TODO: Currently, this is extremely broken. Stars look fine,
01987 // but planets look ridiculous with bright haloes.
01988 if (useHaloes && appMag < saturationMag)
01989 {
01990 a = 0.4f * clamp((appMag - saturationMag) * -0.8f);
01991 float s = renderZ * 0.001f * (3 - (appMag - saturationMag)) * 2;
01992 if (s > size * 3)
01993 size = s * 2.0f/(1.0f +FOV/fov);
01994 else
01995 size = size * 3;
01996 float realSize = discSizeInPixels * pixelSize * renderZ;
01997 if (size < realSize * 10)
01998 size = realSize * 10;
01999 glareTex->bind();
02000 glColor(color, a);
02001 glBegin(GL_QUADS);
02002 glTexCoord2f(0, 0);
02003 glVertex(center + (v0 * size));
02004 glTexCoord2f(1, 0);
02005 glVertex(center + (v1 * size));
02006 glTexCoord2f(1, 1);
02007 glVertex(center + (v2 * size));
02008 glTexCoord2f(0, 1);
02009 glVertex(center + (v3 * size));
02010 glEnd();
02011 }
02012 }
02013 }
|
|
|
Definition at line 6702 of file render.cpp. References addLabel(), conjugate(), coordLabels, astro::equatorialToCelestialCart(), glVertex(), and nCoordLabels. Referenced by render(). 06703 {
06704 int raDivisions = 12;
06705 int decDivisions = 12;
06706 int nSections = 60;
06707 float radius = 10.0f;
06708
06709 int i;
06710 for (i = 0; i < raDivisions; i++)
06711 {
06712 float ra = (float) i / (float) raDivisions * 24.0f;
06713
06714 glBegin(GL_LINE_STRIP);
06715 for (int j = 0; j <= nSections; j++)
06716 {
06717 float dec = ((float) j / (float) nSections) * 180 - 90;
06718 glVertex(astro::equatorialToCelestialCart(ra, dec, radius));
06719 }
06720 glEnd();
06721 }
06722
06723 for (i = 1; i < decDivisions; i++)
06724 {
06725 float dec = (float) i / (float) decDivisions * 180 - 90;
06726 glBegin(GL_LINE_LOOP);
06727 for (int j = 0; j < nSections; j++)
06728 {
06729 float ra = (float) j / (float) nSections * 24.0f;
06730 glVertex(astro::equatorialToCelestialCart(ra, dec, radius));
06731 }
06732 glEnd();
06733 }
06734
06735 for (i = 0; i < nCoordLabels; i++)
06736 {
06737 Point3f pos = astro::equatorialToCelestialCart(coordLabels[i].ra,
06738 coordLabels[i].dec,
06739 radius);
06740 if ((pos * conjugate(observer.getOrientation()).toMatrix3()).z < 0)
06741 {
06742 addLabel(coordLabels[i].label, Color(0.3f, 0.7f, 0.7f, 0.85f), pos);
06743 }
06744 }
06745 }
|
|
||||||||||||||||||||||||||||||||||||||||
|
Definition at line 5863 of file render.cpp. References abs(), CometTailVertex::brightness, CometTailSlices, cometTailVertices, cos(), distance(), glTranslate(), glVertex(), Vector3< T >::length(), MaxCometTailPoints, CometTailVertex::normal, Vector3< T >::normalize(), CometTailVertex::paraboloidPoint, PI, CometTailVertex::point, ProcessCometTailVertex(), sin(), sqrt(), square(), Quaternion< T >::w, Quaternion< T >::x, Point3< T >::x, Vector3< T >::x, X0_SOL, Quaternion< T >::y, Point3< T >::y, Vector3< T >::y, Quaternion< T >::z, Point3< T >::z, and Vector3< T >::z. Referenced by render(). 05872 {
05873 Point3f cometPoints[MaxCometTailPoints];
05874 Point3d pos0 = body.getOrbit()->positionAtTime(now);
05875 Point3d pos1 = body.getOrbit()->positionAtTime(now - 0.01);
05876 Vec3d vd = pos1 - pos0;
05877 double t = now;
05878 float f = 1.0e15f;
05879 int nSteps = MaxCometTailPoints;
05880 float dt = 10000000.0f / (nSteps * (float) vd.length() * 100.0f);
05881 float distanceFromSun, irradiance_max = 0.0f;
05882 unsigned int li_eff;
05883
05884 // Find the sun with the largest irrradiance of light onto the comet
05885 // as function of the comet's position;
05886 // irradiance = sun's luminosity / square(distanceFromSun);
05887
05888 for (unsigned int li = 0; li < lightSources.size(); li++)
05889 {
05890 distanceFromSun = (float)(body.getHeliocentricPosition(now) -
05891 lightSources[li].position).length();
05892 float irradiance = lightSources[li].luminosity / square(distanceFromSun);
05893 if (irradiance > irradiance_max )
05894 {
05895 li_eff = li;
05896 irradiance_max = irradiance;
05897 }
05898 }
05899 float fadeDistance = 1.0f / (X0_SOL * sqrt(irradiance_max));
05900
05901 // direction to sun with dominant light irradiance:
05902
05903 Vec3d sd = body.getHeliocentricPosition(now) - lightSources[li_eff].position;
05904 Vec3f sunDir = Vec3f((float) sd.x, (float) sd.y, (float) sd.z);
05905 sunDir.normalize();
05906
05907 // cout<<astro::kilometersToAU(X0_SOL*sqrt(lightSources[li_eff].luminosity))<<" "<<fadeDistance<<" "<<astro::kilometersToAU(sd.length())<<endl;
05908
05909 int i;
05910 #if 0
05911 for (i = 0; i < MaxCometTailPoints; i++)
05912 {
05913 Vec3d pd = body.getOrbit()->positionAtTime(t) - pos0;
05914 Point3f p = Point3f((float) pd.x, (float) pd.y, (float) pd.z);
05915 Vec3f r(p.x + (float) pos0.x,
05916 p.y + (float) pos0.y,
05917 p.z + (float) pos0.z);
05918 float distance = r.length();
05919
05920 Vec3f a = r * ((1 / square(distance)) * f * dt);
05921 Vec3f dx = a * (square(i * dt) * 0.5f);
05922
05923 cometPoints[i] = p + dx;
05924
05925 t -= dt;
05926 }
05927 #endif
05928 // Compute a rough estimate of the visible length of the dust tail
05929
05930 float dustTailLength = (1.0e8f / (float) pos0.distanceFromOrigin()) *
05931 (body.getRadius() / 5.0f) * 1.0e7f;
05932 float dustTailRadius = dustTailLength * 0.1f;
05933 float comaRadius = dustTailRadius * 0.5f;
05934
05935 Point3f origin(0, 0, 0);
05936 origin -= sunDir * (body.getRadius() * 100);
05937 for (i = 0; i < MaxCometTailPoints; i++)
05938 {
05939 float alpha = (float) i / (float) MaxCometTailPoints;
05940 alpha = alpha * alpha;
05941 cometPoints[i] = origin + sunDir * (dustTailLength * alpha);
05942 }
05943
05944 // We need three axes to define the coordinate system for rendering the
05945 // comet. The first axis is the velocity. We choose the second one
05946 // based on the orientation of the comet. And the third is just the cross
05947 // product of the first and second axes.
05948 Quatd qd = body.getEclipticalToEquatorial(t);
05949 Quatf q((float) qd.w, (float) qd.x, (float) qd.y, (float) qd.z);
05950 Vec3f v = cometPoints[1] - cometPoints[0];
05951 v.normalize();
05952 Vec3f u0 = Vec3f(0, 1, 0) * q.toMatrix3();
05953 Vec3f u1 = Vec3f(1, 0, 0) * q.toMatrix3();
05954 Vec3f u;
05955 if (abs(u0 * v) < abs(u1 * v))
05956 u = v ^ u0;
05957 else
05958 u = v ^ u1;
05959 u.normalize();
05960 Vec3f w = u ^ v;
05961
05962 glColor4f(0.0f, 1.0f, 1.0f, 0.5f);
05963 glPushMatrix();
05964 glTranslate(pos);
05965
05966 // glx::glActiveTextureARB(GL_TEXTURE0_ARB);
05967 glDisable(GL_TEXTURE_2D);
05968 glDisable(GL_LIGHTING);
05969 glDepthMask(GL_FALSE);
05970 glEnable(GL_BLEND);
05971 glBlendFunc(GL_SRC_ALPHA, GL_ONE);
05972
05973 for (i = 0; i < MaxCometTailPoints; i++)
05974 {
05975 float brightness = 1.0f - (float) i / (float) (MaxCometTailPoints - 1);
05976 Vec3f v0, v1;
05977 float sectionLength;
05978 if (i != 0 && i != MaxCometTailPoints - 1)
05979 {
05980 v0 = cometPoints[i] - cometPoints[i - 1];
05981 v1 = cometPoints[i + 1] - cometPoints[i];
05982 sectionLength = v0.length();
05983 v0.normalize();
05984 v1.normalize();
05985 Vec3f axis = v1 ^ v0;
05986 float axisLength = axis.length();
05987 if (axisLength > 1e-5f)
05988 {
05989 axis *= 1.0f / axisLength;
05990 q.setAxisAngle(axis, (float) asin(axisLength));
05991 Mat3f m = q.toMatrix3();
05992
05993 u = u * m;
05994 v = v * m;
05995 w = w * m;
05996 }
05997 }
05998 else if (i == 0)
05999 {
06000 v0 = cometPoints[i + 1] - cometPoints[i];
06001 sectionLength = v0.length();
06002 v0.normalize();
06003 v1 = v0;
06004 }
06005 else
06006 {
06007 v0 = v1 = cometPoints[i] - cometPoints[i - 1];
06008 sectionLength = v0.length();
06009 v0.normalize();
06010 v1 = v0;
06011 }
06012
06013 float radius = (float) i / (float) MaxCometTailPoints *
06014 dustTailRadius;
06015 float dr = (dustTailRadius / (float) MaxCometTailPoints) /
06016 sectionLength;
06017 float w0 = (float) atan(dr);
06018 float w1 = (float) sqrt(1.0f - square(w0));
06019
06020 for (int j = 0; j < CometTailSlices; j++)
06021 {
06022 float theta = (float) (2 * PI * (float) j / CometTailSlices);
06023 float s = (float) sin(theta);
06024 float c = (float) cos(theta);
06025 CometTailVertex* vtx = &cometTailVertices[i * CometTailSlices + j];
06026 vtx->normal = u * (s * w1) + w * (c * w1) + v * w0;
06027 s *= radius;
06028 c *= radius;
06029
06030 vtx->point = Point3f(cometPoints[i].x + u.x * s + w.x * c,
06031 cometPoints[i].y + u.y * s + w.y * c,
06032 cometPoints[i].z + u.z * s + w.z * c);
06033 vtx->brightness = brightness;
06034 vtx->paraboloidPoint =
06035 Point3f(c, s, square((float) i / (float) MaxCometTailPoints));
06036 }
06037 }
06038
06039 Vec3f viewDir = pos - Point3f(0.0f, 0.0f, 0.0f);
06040 viewDir.normalize();
06041
06042 glDisable(GL_CULL_FACE);
06043 for (i = 0; i < MaxCometTailPoints - 1; i++)
06044 {
06045 glBegin(GL_QUAD_STRIP);
06046 int n = i * CometTailSlices;
06047 for (int j = 0; j < CometTailSlices; j++)
06048 {
06049 ProcessCometTailVertex(cometTailVertices[n + j], viewDir, fadeDistance);
06050 ProcessCometTailVertex(cometTailVertices[n + j + CometTailSlices],
06051 viewDir, fadeDistance);
06052 }
06053 ProcessCometTailVertex(cometTailVertices[n], viewDir, fadeDistance);
06054 ProcessCometTailVertex(cometTailVertices[n + CometTailSlices],
06055 viewDir, fadeDistance);
06056 glEnd();
06057 }
06058 glEnable(GL_CULL_FACE);
06059
06060 glBegin(GL_LINE_STRIP);
06061 for (i = 0; i < MaxCometTailPoints; i++)
06062 {
06063 glVertex(cometPoints[i]);
06064 }
06065 glEnd();
06066
06067 glDepthMask(GL_TRUE);
06068 glEnable(GL_TEXTURE_2D);
06069 glEnable(GL_BLEND);
06070
06071 glPopMatrix();
06072 }
|
|
||||||||||||||||
|
Definition at line 6644 of file render.cpp. References DSORenderer::avgAbsMag, brightnessBias, ObjectRenderer< OBJ, PREC >::brightnessBias, brightnessScale, ObjectRenderer< OBJ, PREC >::brightnessScale, conjugate(), context, ObjectRenderer< OBJ, PREC >::context, corrFac, degToRad(), disableSmoothLines(), DSORenderer::dsoDB, enableSmoothLines(), faintestMag, ObjectRenderer< OBJ, PREC >::faintestMag, ObjectRenderer< OBJ, PREC >::faintestMagNight, DSODatabase::findVisibleDSOs(), fov, ObjectRenderer< OBJ, PREC >::fov, DSORenderer::frustum, DSODatabase::getAverageAbsoluteMagnitude(), labelMode, ObjectRenderer< OBJ, PREC >::labelMode, MinNearPlaneDistance, ObjectRenderer< OBJ, PREC >::observer, DSORenderer::obsPos, DSORenderer::orientationMatrix, ObjectRenderer< OBJ, PREC >::pixelSize, pixelSize, ObjectRenderer< OBJ, PREC >::renderer, renderFlags, ObjectRenderer< OBJ, PREC >::renderFlags, saturationMag, ObjectRenderer< OBJ, PREC >::saturationMag, ShowSmoothLines, ObjectRenderer< OBJ, PREC >::size, ObjectRenderer< OBJ, PREC >::viewNormal, DSORenderer::wHeight, windowHeight, windowWidth, DSORenderer::wWidth, Point3< T >::x, Point3< T >::y, and Point3< T >::z. Referenced by render(). 06647 {
06648 DSORenderer dsoRenderer;
06649
06650 Point3d obsPos = (Point3d) observer.getPosition();
06651 obsPos.x *= 1e-6;
06652 obsPos.y *= 1e-6;
06653 obsPos.z *= 1e-6;
06654
06655 DSODatabase* dsoDB = universe.getDSOCatalog();
06656
06657 dsoRenderer.context = context;
06658 dsoRenderer.renderer = this;
06659 dsoRenderer.dsoDB = dsoDB;
06660 dsoRenderer.orientationMatrix = conjugate(observer.getOrientation()).toMatrix3();
06661 dsoRenderer.observer = &observer;
06662 dsoRenderer.obsPos = obsPos;
06663 dsoRenderer.viewNormal = Vec3f(0, 0, -1) * observer.getOrientation().toMatrix3();
06664 dsoRenderer.fov = fov;
06665 // size/pixelSize =0.86 at 120deg, 1.43 at 45deg and 1.6 at 0deg.
06666 dsoRenderer.size = pixelSize * 1.6f / corrFac;
06667 dsoRenderer.pixelSize = pixelSize;
06668 dsoRenderer.brightnessScale = brightnessScale * corrFac;
06669 dsoRenderer.brightnessBias = brightnessBias;
06670 dsoRenderer.avgAbsMag = dsoDB->getAverageAbsoluteMagnitude();
06671 dsoRenderer.faintestMag = faintestMag;
06672 dsoRenderer.faintestMagNight = faintestMagNight;
06673 dsoRenderer.saturationMag = saturationMag;
06674 dsoRenderer.renderFlags = renderFlags;
06675 dsoRenderer.labelMode = labelMode;
06676 dsoRenderer.wWidth = windowWidth;
06677 dsoRenderer.wHeight = windowHeight;
06678
06679 dsoRenderer.frustum = Frustum(degToRad(fov),
06680 (float) windowWidth / (float) windowHeight,
06681 MinNearPlaneDistance);
06682
06683 // Render any line primitives with smooth lines
06684 // (mostly to make graticules look good.)
06685 if ((renderFlags & ShowSmoothLines) != 0)
06686 enableSmoothLines();
06687
06688 glBlendFunc(GL_SRC_ALPHA, GL_ONE);
06689
06690 dsoDB->findVisibleDSOs(dsoRenderer,
06691 obsPos,
06692 observer.getOrientation(),
06693 degToRad(fov),
06694 (float) windowWidth / (float) windowHeight,
06695 2*faintestMagNight);
06696
06697 if ((renderFlags & ShowSmoothLines) != 0)
06698 disableSmoothLines();
06699 }
|
|
||||||||||||||||||||||||||||||||||||
|
Definition at line 2405 of file render.cpp. References abs(), Renderer::SkyContourPoint::centerDist, clamp(), Renderer::SkyVertex::color, conjugate(), cos(), Renderer::SkyContourPoint::cosSkyCapAltitude, ellipsoidTangent(), Renderer::SkyContourPoint::eyeDir, Renderer::SkyContourPoint::eyeDist, Vector3< T >::length(), Math< T >::lerp(), max, MaxSkySlices, min, MinSkySlices, Vector3< T >::normalize(), PI, pow(), Matrix3< float >::scaling(), sin(), skyContour, skyIndices, skyVertices, sqrt(), square(), Renderer::SkyContourPoint::v, Renderer::SkyVertex::x, Point3< T >::x, Vector3< T >::x, Renderer::SkyVertex::y, Point3< T >::y, Vector3< T >::y, Renderer::SkyVertex::z, Point3< T >::z, and Vector3< T >::z. Referenced by renderObject(). 02413 {
02414 if (atmosphere.height == 0.0f)
02415 return;
02416
02417 glDepthMask(GL_FALSE);
02418
02419 // Gradually fade in the atmosphere if it's thickness on screen is just
02420 // over one pixel.
02421 float fade = clamp(pixSize - 2);
02422
02423 Mat3f rot = orientation.toMatrix3();
02424 Mat3f irot = conjugate(orientation).toMatrix3();
02425
02426 Point3f eyePos(0.0f, 0.0f, 0.0f);
02427 float radius = max(semiAxes.x, max(semiAxes.y, semiAxes.z));
02428 Vec3f eyeVec = center - eyePos;
02429 eyeVec = eyeVec * irot;
02430 double centerDist = eyeVec.length();
02431
02432 float height = atmosphere.height / radius;
02433 Vec3f recipSemiAxes(1.0f / semiAxes.x, 1.0f / semiAxes.y, 1.0f / semiAxes.z);
02434
02435 Vec3f recipAtmSemiAxes = recipSemiAxes / (1.0f + height);
02436 Mat3f A = Mat3f::scaling(recipAtmSemiAxes);
02437 Mat3f A1 = Mat3f::scaling(recipSemiAxes);
02438
02439 // ellipDist is not the true distance from the surface unless the
02440 // planet is spherical. Computing the true distance requires finding
02441 // the roots of a sixth degree polynomial, and isn't actually what we
02442 // want anyhow since the atmosphere region is just the planet ellipsoid
02443 // multiplied by a uniform scale factor. The value that we do compute
02444 // is the distance to the surface along a line from the eye position to
02445 // the center of the ellipsoid.
02446 float ellipDist = (float) sqrt((eyeVec * A1) * (eyeVec * A1)) - 1.0f;
02447 bool within = ellipDist < height;
02448
02449 // Adjust the tesselation of the sky dome/ring based on distance from the
02450 // planet surface.
02451 int nSlices = MaxSkySlices;
02452 if (ellipDist < 0.25f)
02453 {
02454 nSlices = MinSkySlices + max(0, (int) ((ellipDist / 0.25f) * (MaxSkySlices - MinSkySlices)));
02455 nSlices &= ~1;
02456 }
02457
02458 int nRings = min(1 + (int) pixSize / 5, 6);
02459 int nHorizonRings = nRings;
02460 if (within)
02461 nRings += 12;
02462
02463 float horizonHeight = height;
02464 if (within)
02465 {
02466 if (ellipDist <= 0.0f)
02467 horizonHeight = 0.0f;
02468 else
02469 horizonHeight *= max((float) pow(ellipDist / height, 0.33f), 0.001f);
02470 }
02471
02472 Vec3f e = -eyeVec;
02473 Vec3f e_(e.x * recipSemiAxes.x, e.y * recipSemiAxes.y, e.z * recipSemiAxes.z);
02474 float ee = e_ * e_;
02475
02476 // Compute the cosine of the altitude of the sun. This is used to compute
02477 // the degree of sunset/sunrise coloration.
02478 float cosSunAltitude = 0.0f;
02479 {
02480 // Check for a sun either directly behind or in front of the viewer
02481 float cosSunAngle = (float) ((sunDirection * e) / centerDist);
02482 if (cosSunAngle < -1.0f + 1.0e-6f)
02483 {
02484 cosSunAltitude = 0.0f;
02485 }
02486 else if (cosSunAngle > 1.0f - 1.0e-6f)
02487 {
02488 cosSunAltitude = 0.0f;
02489 }
02490 else
02491 {
02492 Point3f tangentPoint = center +
02493 ellipsoidTangent(recipSemiAxes,
02494 (-sunDirection * irot) * (float) centerDist,
02495 e, e_, ee) * rot;
02496 Vec3f tangentDir = tangentPoint - eyePos;
02497 tangentDir.normalize();
02498 cosSunAltitude = sunDirection * tangentDir;
02499 }
02500 }
02501
02502 Vec3f normal = eyeVec;
02503 normal = normal / (float) centerDist;
02504
02505 Vec3f uAxis, vAxis;
02506 if (abs(normal.x) < abs(normal.y) && abs(normal.x) < abs(normal.z))
02507 {
02508 uAxis = Vec3f(1, 0, 0) ^ normal;
02509 uAxis.normalize();
02510 }
02511 else if (abs(eyeVec.y) < abs(normal.z))
02512 {
02513 uAxis = Vec3f(0, 1, 0) ^ normal;
02514 uAxis.normalize();
02515 }
02516 else
02517 {
02518 uAxis = Vec3f(0, 0, 1) ^ normal;
02519 uAxis.normalize();
02520 }
02521 vAxis = uAxis ^ normal;
02522
02523 // Compute the contour of the ellipsoid
02524 int i;
02525 for (i = 0; i <= nSlices; i++)
02526 {
02527 // We want rays with an origin at the eye point and tangent to the the
02528 // ellipsoid.
02529 float theta = (float) i / (float) nSlices * 2 * (float) PI;
02530 Vec3f w = (float) cos(theta) * uAxis + (float) sin(theta) * vAxis;
02531 w = w * (float) centerDist;
02532
02533 Vec3f toCenter = ellipsoidTangent(recipSemiAxes, w, e, e_, ee);
02534 skyContour[i].v = toCenter * rot;
02535 skyContour[i].centerDist = skyContour[i].v.length();
02536 skyContour[i].eyeDir = skyContour[i].v + (center - eyePos);
02537 skyContour[i].eyeDist = skyContour[i].eyeDir.length();
02538 skyContour[i].eyeDir.normalize();
02539
02540 float skyCapDist = (float) sqrt(square(skyContour[i].eyeDist) +
02541 square(horizonHeight * radius));
02542 skyContour[i].cosSkyCapAltitude = skyContour[i].eyeDist /
02543 skyCapDist;
02544 }
02545
02546
02547 Vec3f botColor(atmosphere.lowerColor.red(),
02548 atmosphere.lowerColor.green(),
02549 atmosphere.lowerColor.blue());
02550 Vec3f topColor(atmosphere.upperColor.red(),
02551 atmosphere.upperColor.green(),
02552 atmosphere.upperColor.blue());
02553 Vec3f sunsetColor(atmosphere.sunsetColor.red(),
02554 atmosphere.sunsetColor.green(),
02555 atmosphere.sunsetColor.blue());
02556 if (within)
02557 {
02558 Vec3f skyColor(atmosphere.skyColor.red(),
02559 atmosphere.skyColor.green(),
02560 atmosphere.skyColor.blue());
02561 if (ellipDist < 0.0f)
02562 topColor = skyColor;
02563 else
02564 topColor = skyColor + (topColor - skyColor) * (ellipDist / height);
02565 }
02566
02567 Vec3f zenith = (skyContour[0].v + skyContour[nSlices / 2].v);
02568 zenith.normalize();
02569 zenith *= skyContour[0].centerDist * (1.0f + horizonHeight * 2.0f);
02570
02571 float minOpacity = within ? (1.0f - ellipDist / height) * 0.75f : 0.0f;
02572 float sunset = cosSunAltitude < 0.9f ? 0.0f : (cosSunAltitude - 0.9f) * 10.0f;
02573
02574 // Build the list of vertices
02575 SkyVertex* vtx = skyVertices;
02576 for (i = 0; i <= nRings; i++)
02577 {
02578 float h = min(1.0f, (float) i / (float) nHorizonRings);
02579 float hh = (float) sqrt(h);
02580 float u = i <= nHorizonRings ? 0.0f :
02581 (float) (i - nHorizonRings) / (float) (nRings - nHorizonRings);
02582 float r = Mathf::lerp(h, 1.0f - (horizonHeight * 0.05f), 1.0f + horizonHeight);
02583 float atten = 1.0f - hh;
02584
02585 for (int j = 0; j < nSlices; j++)
02586 {
02587 Vec3f v;
02588 if (i <= nHorizonRings)
02589 v = skyContour[j].v * r;
02590 else
02591 v = (skyContour[j].v * (1.0f - u) + zenith * u) * r;
02592 Point3f p = center + v;
02593
02594
02595 Vec3f viewDir(p.x, p.y, p.z);
02596 viewDir.normalize();
02597 float cosSunAngle = viewDir * sunDirection;
02598 float cosAltitude = viewDir * skyContour[j].eyeDir;
02599 float brightness = 1.0f;
02600 float coloration = 0.0f;
02601 if (lit)
02602 {
02603 if (sunset > 0.0f && cosSunAngle > 0.7f && cosAltitude > 0.98f)
02604 {
02605 coloration = (1.0f / 0.30f) * (cosSunAngle - 0.70f);
02606 coloration *= 50.0f * (cosAltitude - 0.98f);
02607 coloration *= sunset;
02608 }
02609
02610 cosSunAngle = (skyContour[j].v * sunDirection) / skyContour[j].centerDist;
02611 if (cosSunAngle > -0.2f)
02612 {
02613 if (cosSunAngle < 0.3f)
02614 brightness = (cosSunAngle + 0.2f) * 2.0f;
02615 else
02616 brightness = 1.0f;
02617 }
02618 else
02619 {
02620 brightness = 0.0f;
02621 }
02622 }
02623
02624 vtx->x = p.x;
02625 vtx->y = p.y;
02626 vtx->z = p.z;
02627
02628 #if 0
02629 // Better way of generating sky color gradients--based on
02630 // altitude angle.
02631 if (!within)
02632 {
02633 hh = (1.0f - cosAltitude) / (1.0f - skyContour[j].cosSkyCapAltitude);
02634 }
02635 else
02636 {
02637 float top = pow((ellipDist / height), 0.125f) * skyContour[j].cosSkyCapAltitude;
02638 if (cosAltitude < top)
02639 hh = 1.0f;
02640 else
02641 hh = (1.0f - cosAltitude) / (1.0f - top);
02642 }
02643 hh = sqrt(hh);
02644 //hh = (float) pow(hh, 0.25f);
02645 #endif
02646
02647 atten = 1.0f - hh;
02648 Vec3f color = (1.0f - hh) * botColor + hh * topColor;
02649 brightness *= minOpacity + (1.0f - minOpacity) * fade * atten;
02650 if (coloration != 0.0f)
02651 color = (1.0f - coloration) * color + coloration * sunsetColor;
02652
02653 Color(brightness * color.x,
02654 brightness * color.y,
02655 brightness * color.z,
02656 fade * (minOpacity + (1.0f - minOpacity)) * atten).get(vtx->color);
02657 vtx++;
02658 }
02659 }
02660
02661 // Create the index list
02662 int index = 0;
02663 for (i = 0; i < nRings; i++)
02664 {
02665 int baseVertex = i * nSlices;
02666 for (int j = 0; j < nSlices; j++)
02667 {
02668 skyIndices[index++] = baseVertex + j;
02669 skyIndices[index++] = baseVertex + nSlices + j;
02670 }
02671 skyIndices[index++] = baseVertex;
02672 skyIndices[index++] = baseVertex + nSlices;
02673 }
02674
02675 glEnableClientState(GL_VERTEX_ARRAY);
02676 glVertexPointer(3, GL_FLOAT, sizeof(SkyVertex), &skyVertices[0].x);
02677 glEnableClientState(GL_COLOR_ARRAY);
02678 glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(SkyVertex),
02679 static_cast<void*>(&skyVertices[0].color));
02680
02681 for (i = 0; i < nRings; i++)
02682 {
02683 glDrawElements(GL_QUAD_STRIP,
02684 (nSlices + 1) * 2,
02685 GL_UNSIGNED_INT,
02686 &skyIndices[(nSlices + 1) * 2 * i]);
02687 }
02688
02689 glDisableClientState(GL_COLOR_ARRAY);
02690 }
|
|
||||||||||||||||||||||||||||
|
Definition at line 1115 of file render.cpp. References disableSmoothLines(), distance(), enableSmoothLines(), fov, Body::getClassification(), astro::kilometersToAU(), max, minOrbitSize, orbitMask, renderFlags, renderOrbit(), renderOrbitColor(), ShowOrbits, ShowSmoothLines, transformOrbits(), windowHeight, and windowWidth. Referenced by render(). 01121 {
01122 // Render orbit paths
01123
01124 if ((renderFlags & ShowOrbits) == 0 || orbitMask == 0)
01125 return;
01126 if (system == NULL)
01127 return;
01128 if (discSizeInPixels < minOrbitSize)
01129 return;
01130
01131 distance = astro::kilometersToAU(distance);
01132 double scale = astro::kilometersToAU(1.0);
01133 glPushMatrix();
01134 glTranslated(center.x * scale,
01135 center.y * scale,
01136 center.z * scale);
01137
01138 glDisable(GL_LIGHTING);
01139 glDisable(GL_TEXTURE_2D);
01140 if ((renderFlags & ShowSmoothLines) != 0)
01141 enableSmoothLines();
01142 transformOrbits(system);
01143
01144 glMatrixMode(GL_PROJECTION);
01145 glLoadIdentity();
01146 gluPerspective(fov,
01147 (float) windowWidth / (float) windowHeight,
01148 max( distance * 1e-6f,
01149 (float)(1e-5/2./tan(fov*3.14159/360.0)) ),
01150 distance);
01151
01152 glMatrixMode(GL_MODELVIEW);
01153
01154 int nBodies = system->getSystemSize();
01155 for (int i = 0; i < nBodies; i++)
01156 {
01157 Body* body = system->getBody(i);
01158
01159 // Only show orbits for major bodies or selected objects
01160 if ((body->getClassification() & orbitMask) == 0 &&
01161 body != sel.body())
01162 continue;
01163 renderOrbitColor(body, body == sel.body());
01164 renderOrbit(body, t);
01165 }
01166
01167 if ((renderFlags & ShowSmoothLines) != 0)
01168 disableSmoothLines();
01169 glPopMatrix();
01170 }
|
|
|
Definition at line 6856 of file render.cpp. References TextureFont::bind(), font, glColor(), labels, PixelOffset, TextureFont::render(), windowHeight, and windowWidth. Referenced by render(). 06857 {
06858 if (font == NULL)
06859 return;
06860
06861 //glEnable(GL_DEPTH_TEST);
06862 glEnable(GL_TEXTURE_2D);
06863 font->bind();
06864 glEnable(GL_BLEND);
06865 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
06866
06867 glMatrixMode(GL_PROJECTION);
06868 glPushMatrix();
06869 glLoadIdentity();
06870 gluOrtho2D(0, windowWidth, 0, windowHeight);
06871 glMatrixMode(GL_MODELVIEW);
06872 glPushMatrix();
06873 glLoadIdentity();
06874 glTranslatef(GLfloat((int) (windowWidth / 2)),
06875 GLfloat((int) (windowHeight / 2)), 0);
06876
06877 for (int i = 0; i < (int) labels.size(); i++)
06878 {
06879 glColor(labels[i].color);
06880 glPushMatrix();
06881 glTranslatef((int) labels[i].position.x + PixelOffset + 2.0f,
06882 (int) labels[i].position.y + PixelOffset,
06883 0.0f);
06884 // EK TODO: Check where to replace (see '_(' above)
06885 font->render(labels[i].text.c_str());
06886 glPopMatrix();
06887 }
06888
06889 glPopMatrix();
06890 glMatrixMode(GL_PROJECTION);
06891 glPopMatrix();
06892 glMatrixMode(GL_MODELVIEW);
06893 glDisable(GL_DEPTH_TEST);
06894 }
|
|
||||||||||||||||||||||||
|
Definition at line 4729 of file render.cpp. References TextureFont::bind(), Point3< T >::distanceFromOrigin(), font, locationFilter, minFeatureSize, PixelOffset, pixelSize, TextureFont::render(), testIntersection(), windowHeight, windowWidth, Vector3< T >::x, Vector3< T >::y, and Vector3< T >::z. Referenced by renderObject(). 04734 {
04735 if (font == NULL)
04736 return;
04737
04738 double winX, winY, winZ;
04739 int view[4] = { 0, 0, 0, 0 };
04740 view[0] = -windowWidth / 2;
04741 view[1] = -windowHeight / 2;
04742 view[2] = windowWidth;
04743 view[3] = windowHeight;
04744
04745 Vec3f viewNormal = Vec3f(0.0f, 0.0f, -1.0f) *
04746 cameraOrientation.toMatrix3();
04747 Vec3d viewNormald = Vec3d(viewNormal.x, viewNormal.y, viewNormal.z);
04748
04749 double modelview[16];
04750 double projection[16];
04751 glGetDoublev(GL_MODELVIEW_MATRIX, modelview);
04752 glGetDoublev(GL_PROJECTION_MATRIX, projection);
04753
04754 glEnable(GL_DEPTH_TEST);
04755 glEnable(GL_TEXTURE_2D);
04756 font->bind();
04757 glEnable(GL_BLEND);
04758 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
04759 glDisable(GL_LIGHTING);
04760
04761 glMatrixMode(GL_PROJECTION);
04762 glPushMatrix();
04763 glLoadIdentity();
04764 glOrtho(0, windowWidth, 0, windowHeight, 1.0f, -1.0f);
04765 glMatrixMode(GL_MODELVIEW);
04766 glPushMatrix();
04767 glLoadIdentity();
04768
04769 // Render the labels very close to the near plane with z=-0.999f. In fact,
04770 // z=-1.0f should work, but I'm concerned that some OpenGL implementations
04771 // might clip things placed right on the near plane.
04772 glTranslatef(GLfloat((int) (windowWidth / 2)),
04773 GLfloat((int) (windowHeight / 2)), -0.999f);
04774
04775 Point3d position(positionf.x, positionf.y, positionf.z);
04776 Point3d origin(0.0, 0.0, 0.0);
04777
04778 Ellipsoidd ellipsoid(position, Vec3d(scale, scale, scale));
04779
04780 float iScale = 1.0f / scale;
04781 Mat3f mat = orientation.toMatrix3();
04782
04783 for (vector<Location*>::const_iterator iter = locations.begin();
04784 iter != locations.end(); iter++)
04785 {
04786 if ((*iter)->getFeatureType() & locationFilter)
04787 {
04788 // Get the position of the label with respect to the planet center
04789 Vec3f ppos = (*iter)->getPosition();
04790 // Get the rotated position
04791 Vec3f pposRotated = ppos * mat;
04792 // Double precision required for stable intersection calculations
04793 Vec3d pposd(pposRotated.x, pposRotated.y, pposRotated.z);
04794 // Get the position in camera space. Add a slight scale factor
04795 // to keep the point from being exactly on the surface.
04796 Point3d cpos(position + pposd * 1.0001);
04797
04798 float effSize = (*iter)->getImportance();
04799 if (effSize < 0.0f)
04800 effSize = (*iter)->getSize();
04801 float pixSize = effSize / (float) (cpos.distanceFromOrigin() * pixelSize);
04802
04803 if (pixSize > minFeatureSize &&
04804 (cpos - origin) * viewNormald > 0.0)
04805 {
04806 double r = pposd.length();
04807 if (r < scale * 0.99)
04808 cpos = position + pposd * (scale * 1.01 / r);
04809
04810 double t = 0.0f;
04811
04812 // Test for a intersection of the eye-to-location ray with
04813 // the planet ellipsoid. If we hit the planet first, then
04814 // the label is obscured by the planet. An exact calculation
04815 // for irregular objects would be too expensive, and the
04816 // ellipsoid approximation works reasonably well for them.
04817 bool hit = testIntersection(Ray3d(origin, cpos - origin),
04818 ellipsoid, t);
04819 if (!hit || t >= 1.0)
04820 {
04821 if (gluProject(ppos.x * iScale, ppos.y * iScale, ppos.z * iScale,
04822 modelview,
04823 projection,
04824 (const GLint*) view,
04825 &winX, &winY, &winZ) != GL_FALSE)
04826 {
04827 glColor4f(0.0f, 1.0f, 0.0f, 1.0f);
04828 glPushMatrix();
04829 glTranslatef((int) winX + PixelOffset,
04830 (int) winY + PixelOffset,
04831 0.0f);
04832 font->render((*iter)->getName(true));
04833 glPopMatrix();
04834 }
04835 }
04836 }
04837 }
04838 }
04839
04840 glPopMatrix();
04841 glMatrixMode(GL_PROJECTION);
04842 glPopMatrix();
04843 glMatrixMode(GL_MODELVIEW);
04844 }
|
|
||||||||||||||||||||
|
Definition at line 6940 of file render.cpp. References conjugate(), glColor(), Vector3< T >::normalize(), projMatrix, windowHeight, windowWidth, Vector3< T >::x, Vector3< T >::y, and Vector3< T >::z. Referenced by render(). 06944 {
06945 double identity4x4[16] = { 1.0, 0.0, 0.0, 0.0,
06946 0.0, 1.0, 0.0, 0.0,
06947 0.0, 0.0, 1.0, 0.0,
06948 0.0, 0.0, 0.0, 1.0
06949 };
06950 int view[4] = { 0, 0, 0, 0 };
06951 view[0] = -windowWidth / 2;
06952 view[1] = -windowHeight / 2;
06953 view[2] = windowWidth;
06954 view[3] = windowHeight;
06955
06956 glDisable(GL_DEPTH_TEST);
06957 glEnable(GL_BLEND);
06958 glDisable(GL_LIGHTING);
06959 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
06960 glDisable(GL_TEXTURE_2D);
06961
06962 glMatrixMode(GL_PROJECTION);
06963 glPushMatrix();
06964 glLoadIdentity();
06965 gluOrtho2D(0, windowWidth, 0, windowHeight);
06966 glMatrixMode(GL_MODELVIEW);
06967 glPushMatrix();
06968 glLoadIdentity();
06969 glTranslatef(GLfloat((int) (windowWidth / 2)),
06970 GLfloat((int) (windowHeight / 2)), 0);
06971
06972 Mat3f rot = conjugate(orientation).toMatrix3();
06973
06974 for (MarkerList::const_iterator iter = markers.begin();
06975 iter != markers.end(); iter++)
06976 {
06977 UniversalCoord uc = iter->getPosition(jd);
06978 Vec3d offset = uc - position;
06979 Vec3f eyepos = Vec3f((float) offset.x, (float) offset.y, (float) offset.z) * rot;
06980 eyepos.normalize();
06981 eyepos *= 1000.0f;
06982
06983 double winX, winY, winZ;
06984 if (gluProject(eyepos.x, eyepos.y, eyepos.z,
06985 identity4x4,
06986 projMatrix,
06987 (const GLint*) view,
06988 &winX, &winY, &winZ) != GL_FALSE)
06989 {
06990 if (eyepos.z < 0.0f)
06991 {
06992 glPushMatrix();
06993 glTranslatef((GLfloat) winX, (GLfloat) winY, 0.0f);
06994
06995 glColor(iter->getColor());
06996 iter->render();
06997
06998 glPopMatrix();
06999 }
07000 }
07001 }
07002
07003 glPopMatrix();
07004 glMatrixMode(GL_PROJECTION);
07005 glPopMatrix();
07006 glMatrixMode(GL_MODELVIEW);
07007 glDisable(GL_DEPTH_TEST);
07008 }
|
|
||||||||||||||||||||||||||||||||||||
|
Definition at line 4961 of file render.cpp. References ambientColor, RenderInfo::ambientColor, RenderInfo::baseTex, Texture::bind(), Color::blue(), GLContext::bumpMappingSupported(), RenderInfo::bumpTex, clamp(), Atmosphere::cloudHeight, Atmosphere::cloudSpeed, Atmosphere::cloudTexture, DirectionalLight::color, RenderInfo::color, context, degToRad(), detailOptions, VertexProcessor::disable(), distance(), VertexProcessor::enable(), RenderInfo::eyeDir_obj, RenderInfo::eyePos_obj, MultiResTexture::find(), ResourceManager< T >::find(), fov, GLContext::getFragmentProcessor(), GLContext::getMaxTextures(), GetModelManager(), GLContext::getRenderPath(), GLContext::getVertexPath(), GLContext::getVertexProcessor(), glLightColor(), glLightDirection(), RenderInfo::glossTex, glRotate(), glScale(), glTranslate(), Color::green(), GLContext::hasMultitexture(), RenderInfo::hazeColor, Atmosphere::height, InvalidResource, DirectionalLight::irradiance, labelMode, LocationLabels, lodSphere, max, RenderInfo::nightTex, Vector3< T >::normalize(), RenderInfo::orientation, RenderInfo::overlayTex, VertexProcessor::parameter(), pfmod(), PI, pixelSize, RenderInfo::pixWidth, Color::red(), LODSphereMesh::render(), renderAtmosphere(), renderClouds_GLSL(), renderEclipseShadows(), renderEclipseShadows_Shaders(), renderEllipsoidAtmosphere(), renderFlags, renderLocations(), renderModelDefault(), renderRings(), renderRings_GLSL(), renderRingShadowsVS(), renderSphere_Combiners(), renderSphere_Combiners_VP(), renderSphere_DOT3_VP(), renderSphere_FP_VP(), renderSphere_GLSL(), renderSphereDefault(), Renderer::DetailOptions::ringSystemSections, Matrix4< float >::scaling(), setLightParameters_VP(), ShowAtmospheres, ShowCloudMaps, ShowNightMaps, ShowRingShadows, RenderInfo::specularColor, RenderInfo::specularPower, RenderInfo::sunColor, RenderInfo::sunDir_eye, RenderInfo::sunDir_obj, MultiResTexture::tex, textureResolution, Quaternion< T >::toMatrix4(), Frustum::transform(), Matrix4< float >::translation(), VertexProcessor::use(), useClampToBorder, useRescaleNormal, RenderInfo::useTexEnvCombine, windowHeight, windowWidth, Vector3< T >::x, Point3< T >::x, Vector3< T >::y, Point3< T >::y, Vector3< T >::z, and Point3< T >::z. Referenced by renderPlanet(), and renderStar(). 04969 {
04970 RenderInfo ri;
04971
04972 float altitude = distance - obj.radius;
04973 float discSizeInPixels = obj.radius /
04974 (max(nearPlaneDistance, altitude) * pixelSize);
04975
04976 ri.sunDir_eye = Vec3f(0.0f, 1.0f, 0.0f);
04977 ri.sunDir_obj = Vec3f(0.0f, 1.0f, 0.0f);
04978 ri.sunColor = Color(0.0f, 0.0f, 0.0f);
04979 if (ls.nLights > 0)
04980 {
04981 ri.sunDir_eye = ls.lights[0].direction_eye;
04982 ri.sunDir_obj = ls.lights[0].direction_obj;
04983 ri.sunColor = ls.lights[0].color;// * ls.lights[0].intensity;
04984 }
04985
04986 // Enable depth buffering
04987 glEnable(GL_DEPTH_TEST);
04988 glDepthMask(GL_TRUE);
04989
04990 glDisable(GL_BLEND);
04991
04992 // Get the textures . . .
04993 if (obj.surface->baseTexture.tex[textureResolution] != InvalidResource)
04994 ri.baseTex = obj.surface->baseTexture.find(textureResolution);
04995 if ((obj.surface->appearanceFlags & Surface::ApplyBumpMap) != 0 &&
04996 context->bumpMappingSupported() &&
04997 obj.surface->bumpTexture.tex[textureResolution] != InvalidResource)
04998 ri.bumpTex = obj.surface->bumpTexture.find(textureResolution);
04999 if ((obj.surface->appearanceFlags & Surface::ApplyNightMap) != 0 &&
05000 (renderFlags & ShowNightMaps) != 0)
05001 ri.nightTex = obj.surface->nightTexture.find(textureResolution);
05002 if ((obj.surface->appearanceFlags & Surface::SeparateSpecularMap) != 0)
05003 ri.glossTex = obj.surface->specularTexture.find(textureResolution);
05004 if ((obj.surface->appearanceFlags & Surface::ApplyOverlay) != 0)
05005 ri.overlayTex = obj.surface->overlayTexture.find(textureResolution);
05006
05007 // Apply the modelview transform for the object
05008 glPushMatrix();
05009 glTranslate(pos);
05010 glRotate(~obj.orientation);
05011
05012 // Apply a scale factor which depends on the size of the planet and
05013 // its oblateness. Since the oblateness is usually quite
05014 // small, the potentially nonuniform scale factor shouldn't mess up
05015 // the lighting calculations enough to be noticeable.
05016 // TODO: Figure out a better way to render ellipsoids than applying
05017 // a nonunifom scale factor to a sphere.
05018 float radius = obj.radius;
05019 Vec3f semiAxes = obj.radius * obj.semiAxes;
05020 glScale(semiAxes);
05021
05022 Mat4f planetMat = (~obj.orientation).toMatrix4();
05023 ri.eyeDir_obj = (Point3f(0, 0, 0) - pos) * planetMat;
05024 ri.eyeDir_obj.normalize();
05025 ri.eyePos_obj = Point3f(-pos.x / semiAxes.x,
05026 -pos.y / semiAxes.y,
05027 -pos.z / semiAxes.z) * planetMat;
05028
05029 ri.orientation = cameraOrientation;
05030
05031 ri.pixWidth = discSizeInPixels;
05032
05033 // Set up the colors
05034 if (ri.baseTex == NULL ||
05035 (obj.surface->appearanceFlags & Surface::BlendTexture) != 0)
05036 {
05037 ri.color = obj.surface->color;
05038 }
05039
05040 ri.ambientColor = ambientColor;
05041 ri.hazeColor = obj.surface->hazeColor;
05042 ri.specularColor = obj.surface->specularColor;
05043 ri.specularPower = obj.surface->specularPower;
05044 ri.useTexEnvCombine = context->getRenderPath() != GLContext::GLPath_Basic;
05045
05046 // See if the surface should be lit
05047 bool lit = (obj.surface->appearanceFlags & Surface::Emissive) == 0;
05048
05049 // Set the OpenGL light state
05050 unsigned int i;
05051 for (i = 0; i < ls.nLights; i++)
05052 {
05053 const DirectionalLight& light = ls.lights[i];
05054
05055 glLightDirection(GL_LIGHT0 + i, ls.lights[i].direction_obj);
05056
05057 // RANT ALERT!
05058 // This sucks, but it's necessary. glScale is used to scale a unit
05059 // sphere up to planet size. Since normals are transformed by the
05060 // inverse transpose of the model matrix, this means they end up
05061 // getting scaled by a factor of 1.0 / planet radius (in km). This
05062 // has terrible effects on lighting: the planet appears almost
05063 // completely dark. To get around this, the GL_rescale_normal
05064 // extension was introduced and eventually incorporated into into the
05065 // OpenGL 1.2 standard. Of course, not everyone implemented this
05066 // incredibly simple and essential little extension. Microsoft is
05067 // notorious for half-assed support of OpenGL, but 3dfx should have
05068 // known better: no Voodoo 1/2/3 drivers seem to support this
05069 // extension. The following is an attempt to get around the problem by
05070 // scaling the light brightness by the planet radius. According to the
05071 // OpenGL spec, this should work fine, as clamping of colors to [0, 1]
05072 // occurs *after* lighting. It works fine on my GeForce3 when I
05073 // disable EXT_rescale_normal, but I'm not certain whether other
05074 // drivers are as well behaved as nVidia's.
05075 //
05076 // Addendum: Unsurprisingly, using color values outside [0, 1] produces
05077 // problems on Savage4 cards.
05078
05079 Vec3f lightColor = Vec3f(light.color.red(),
05080 light.color.green(),
05081 light.color.blue()) * light.irradiance;
05082 if (useRescaleNormal)
05083 {
05084 glLightColor(GL_LIGHT0 + i, GL_DIFFUSE, lightColor);
05085 glLightColor(GL_LIGHT0 + i, GL_SPECULAR, lightColor);
05086 }
05087 else
05088 {
05089 glLightColor(GL_LIGHT0 + i, GL_DIFFUSE, lightColor * radius);
05090 }
05091 glEnable(GL_LIGHT0 + i);
05092 }
05093
05094 // Compute the inverse model/view matrix
05095 Mat4f invMV = (cameraOrientation.toMatrix4() *
05096 Mat4f::translation(Point3f(-pos.x, -pos.y, -pos.z)) *
05097 planetMat *
05098 Mat4f::scaling(1.0f / radius));
05099
05100 // Transform the frustum into object coordinates using the
05101 // inverse model/view matrix.
05102 Frustum viewFrustum(degToRad(fov),
05103 (float) windowWidth / (float) windowHeight,
05104 nearPlaneDistance, farPlaneDistance);
05105 viewFrustum.transform(invMV);
05106
05107 // Temporary hack until we fix culling for ringed planets
05108 if (obj.rings != NULL)
05109 {
05110 if (ri.pixWidth > 5000)
05111 ri.pixWidth = 5000;
05112 }
05113
05114 Model* model = NULL;
05115 if (obj.model == InvalidResource)
05116 {
05117 // A null model indicates that this body is a sphere
05118 if (lit)
05119 {
05120 switch (context->getRenderPath())
05121 {
05122 case GLContext::GLPath_GLSL:
05123 renderSphere_GLSL(ri, ls, obj.rings, obj.radius,
05124 planetMat, viewFrustum, *context);
05125 break;
05126
05127 case GLContext::GLPath_NV30:
05128 renderSphere_FP_VP(ri, viewFrustum, *context);
05129 break;
05130
05131 case GLContext::GLPath_NvCombiner_ARBVP:
05132 case GLContext::GLPath_NvCombiner_NvVP:
05133 renderSphere_Combiners_VP(ri, ls, viewFrustum, *context);
05134 break;
05135
05136 case GLContext::GLPath_NvCombiner:
05137 renderSphere_Combiners(ri, viewFrustum, *context);
05138 break;
05139
05140 case GLContext::GLPath_DOT3_ARBVP:
05141 renderSphere_DOT3_VP(ri, ls, viewFrustum, *context);
05142 break;
05143
05144 default:
05145 renderSphereDefault(ri, viewFrustum, true, *context);
05146 }
05147 }
05148 else
05149 {
05150 renderSphereDefault(ri, viewFrustum, false, *context);
05151 }
05152 }
05153 else
05154 {
05155 // This is a model loaded from a file
05156 model = GetModelManager()->find(obj.model);
05157 if (model != NULL)
05158 renderModelDefault(model, ri, lit);
05159 }
05160
05161 if (obj.rings != NULL && distance <= obj.rings->innerRadius)
05162 {
05163 if (context->getRenderPath() == GLContext::GLPath_GLSL)
05164 {
05165 renderRings_GLSL(*obj.rings, ri, ls,
05166 radius, 1.0f - obj.semiAxes.y,
05167 textureResolution,
05168 (renderFlags & ShowRingShadows) != 0 && lit,
05169 detailOptions.ringSystemSections);
05170 }
05171 else
05172 {
05173 renderRings(*obj.rings, ri, radius, 1.0f - obj.semiAxes.y,
05174 textureResolution,
05175 context->getMaxTextures() > 1 &&
05176 (renderFlags & ShowRingShadows) != 0 && lit,
05177 *context,
05178 detailOptions.ringSystemSections);
05179 }
05180 }
05181
05182 if (obj.atmosphere != NULL)
05183 {
05184 Atmosphere* atmosphere = const_cast<Atmosphere *>(obj.atmosphere);
05185
05186 // Compute the apparent thickness in pixels of the atmosphere.
05187 // If it's only one pixel thick, it can look quite unsightly
05188 // due to aliasing. To avoid popping, we gradually fade in the
05189 // atmosphere as it grows from two to three pixels thick.
05190 float fade;
05191 float thicknessInPixels = 0.0f;
05192 if (distance - radius > 0.0f)
05193 {
05194 thicknessInPixels = atmosphere->height /
05195 ((distance - radius) * pixelSize);
05196 fade = clamp(thicknessInPixels - 2);
05197 }
05198 else
05199 {
05200 fade = 1.0f;
05201 }
05202
05203 if (fade > 0 && (renderFlags & ShowAtmospheres) != 0)
05204 {
05205 glPushMatrix();
05206 glLoadIdentity();
05207 glDisable(GL_LIGHTING);
05208 glDisable(GL_TEXTURE_2D);
05209 glEnable(GL_BLEND);
05210 glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
05211
05212 #ifdef OLD_ATMOSPHERE
05213 renderAtmosphere(*atmosphere,
05214 pos * (~cameraOrientation).toMatrix3(),
05215 radius,
05216 ri.sunDir_eye * (~cameraOrientation).toMatrix3(),
05217 ri.ambientColor,
05218 fade,
05219 lit);
05220 #else
05221 glRotate(cameraOrientation);
05222 renderEllipsoidAtmosphere(*atmosphere,
05223 pos,
05224 obj.orientation,
05225 semiAxes,
05226 ri.sunDir_eye,
05227 ri.ambientColor,
05228 thicknessInPixels,
05229 lit);
05230 #endif // OLD_ATMOSPHERE
05231 glEnable(GL_TEXTURE_2D);
05232 glPopMatrix();
05233 }
05234
05235 // If there's a cloud layer, we'll render it now.
05236 Texture* cloudTex = NULL;
05237 if ((renderFlags & ShowCloudMaps) != 0 &&
05238 atmosphere->cloudTexture.tex[textureResolution] != InvalidResource)
05239 cloudTex = atmosphere->cloudTexture.find(textureResolution);
05240
05241 if (cloudTex != NULL)
05242 {
05243 glPushMatrix();
05244
05245 float cloudScale = 1.0f + atmosphere->cloudHeight / radius;
05246 glScalef(cloudScale, cloudScale, cloudScale);
05247
05248 // If we're beneath the cloud level, render the interior of
05249 // the cloud sphere.
05250 if (distance - radius < atmosphere->cloudHeight)
05251 glFrontFace(GL_CW);
05252
05253 float texOffset = (float) (-pfmod(now * atmosphere->cloudSpeed / (2 * PI), 1.0));
05254 if (atmosphere->cloudSpeed != 0.0f)
05255 {
05256 // Make the clouds appear to rotate above the surface of
05257 // the planet. This is easier to do with the texture
05258 // matrix than the model matrix because changing the
05259 // texture matrix doesn't require us to compute a second
05260 // set of model space rendering parameters.
05261 glMatrixMode(GL_TEXTURE);
05262 glTranslatef(texOffset, 0.0f, 0.0f);
05263 glMatrixMode(GL_MODELVIEW);
05264 }
05265
05266 glEnable(GL_LIGHTING);
05267 glDepthMask(GL_FALSE);
05268 cloudTex->bind();
05269 glEnable(GL_BLEND);
05270 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
05271 glColor4f(1, 1, 1, 1);
05272
05273 if (lit)
05274 {
05275 if (context->getRenderPath() == GLContext::GLPath_GLSL)
05276 {
05277 renderClouds_GLSL(ri, ls,
05278 cloudTex,
05279 texOffset,
05280 obj.rings,
05281 radius * cloudScale,
05282 planetMat,
05283 viewFrustum,
05284 *context);
05285 }
05286 else
05287 {
05288 VertexProcessor* vproc = context->getVertexProcessor();
05289 if (vproc != NULL)
05290 {
05291 vproc->enable();
05292 vproc->parameter(vp::AmbientColor, ri.ambientColor * ri.color);
05293 vproc->parameter(vp::TextureTranslation,
05294 texOffset, 0.0f, 0.0f, 0.0f);
05295 if (ls.nLights > 1)
05296 vproc->use(vp::diffuseTexOffset_2light);
05297 else
05298 vproc->use(vp::diffuseTexOffset);
05299 setLightParameters_VP(*vproc, ls, ri.color, Color::Black);
05300 }
05301
05302 lodSphere->render(*context,
05303 LODSphereMesh::Normals | LODSphereMesh::TexCoords0,
05304 viewFrustum,
05305 ri.pixWidth,
05306 cloudTex);
05307
05308 if (vproc != NULL)
05309 vproc->disable();
05310 }
05311 }
05312 else
05313 {
05314 glDisable(GL_LIGHTING);
05315 lodSphere->render(*context,
05316 LODSphereMesh::Normals | LODSphereMesh::TexCoords0,
05317 viewFrustum,
05318 ri.pixWidth,
05319 cloudTex);
05320 glEnable(GL_LIGHTING);
05321 }
05322
05323 // Reset the texture matrix
05324 glMatrixMode(GL_TEXTURE);
05325 glLoadIdentity();
05326 glMatrixMode(GL_MODELVIEW);
05327
05328 glDepthMask(GL_TRUE);
05329 glFrontFace(GL_CCW);
05330
05331 glPopMatrix();
05332 }
05333 }
05334
05335 // No separate shadow rendering pass required for GLSL path
05336 if (ls.shadows[0] != NULL &&
05337 ls.shadows[0]->size() != 0 &&
05338 (obj.surface->appearanceFlags & Surface::Emissive) == 0 &&
05339 context->getRenderPath() != GLContext::GLPath_GLSL)
05340 {
05341 #if 1
05342 // renderEclipseShadows_Shaders() still needs some more work.
05343 if (context->getVertexProcessor() != NULL &&
05344 context->getFragmentProcessor() != NULL)
05345 {
05346 renderEclipseShadows_Shaders(model,
05347 *ls.shadows[0],
05348 ri,
05349 radius, planetMat, viewFrustum,
05350 *context);
05351 }
05352 else
05353 #endif
05354 {
05355 renderEclipseShadows(model,
05356 *ls.shadows[0],
05357 ri,
05358 radius, planetMat, viewFrustum,
05359 *context);
05360 }
05361 }
05362
05363 if (obj.rings != NULL &&
05364 (obj.surface->appearanceFlags & Surface::Emissive) == 0 &&
05365 (renderFlags & ShowRingShadows) != 0)
05366 {
05367 Texture* ringsTex = obj.rings->texture.find(textureResolution);
05368 if (ringsTex != NULL)
05369 {
05370 Vec3f sunDir = pos - Point3f(0, 0, 0);
05371 sunDir.normalize();
05372
05373 ringsTex->bind();
05374
05375 if (useClampToBorder &&
05376 context->getVertexPath() != GLContext::VPath_Basic &&
05377 context->getRenderPath() != GLContext::GLPath_GLSL)
05378 {
05379 renderRingShadowsVS(model,
05380 *obj.rings,
05381 sunDir,
05382 ri,
05383 radius, 1.0f - obj.semiAxes.y,
05384 planetMat, viewFrustum,
05385 *context);
05386 }
05387 }
05388 }
05389
05390 if (obj.rings != NULL && distance > obj.rings->innerRadius)
05391 {
05392 glDepthMask(GL_FALSE);
05393 if (context->getRenderPath() == GLContext::GLPath_GLSL)
05394 {
05395 renderRings_GLSL(*obj.rings, ri, ls,
05396 radius, 1.0f - obj.semiAxes.y,
05397 textureResolution,
05398 (renderFlags & ShowRingShadows) != 0 && lit,
05399 detailOptions.ringSystemSections);
05400 }
05401 else
05402 {
05403 renderRings(*obj.rings, ri, radius, 1.0f - obj.semiAxes.y,
05404 textureResolution,
05405 (context->hasMultitexture() &&
05406 (renderFlags & ShowRingShadows) != 0 && lit),
05407 *context,
05408 detailOptions.ringSystemSections);
05409 }
05410 }
05411
05412 // Disable all light sources other than the first
05413 for (i = 0; i < ls.nLights; i++)
05414 glDisable(GL_LIGHT0 + i);
05415
05416
05417 if (obj.locations != NULL && (labelMode & LocationLabels) != 0)
05418 renderLocations(*obj.locations,
05419 cameraOrientation,
05420 pos, obj.orientation, radius);
05421
05422 glPopMatrix();
05423 glDisable(GL_DEPTH_TEST);
05424 glDepthMask(GL_FALSE);
05425 glDisable(GL_LIGHTING);
05426 glEnable(GL_BLEND);
05427 }
|
|
||||||||||||
|
Definition at line 918 of file render.cpp. References Renderer::CachedOrbit::body, detailOptions, Renderer::CachedOrbit::keep, max, min, orbitCache, Renderer::DetailOptions::orbitPathSamplePoints, renderFlags, ShowPartialTrajectories, Renderer::CachedOrbit::trajectory, Point3< T >::x, Point3< T >::y, and Point3< T >::z. Referenced by renderForegroundOrbits(), and renderOrbits(). 00919 {
00920 vector<OrbitSample>* trajectory = NULL;
00921 for (vector<CachedOrbit*>::const_iterator iter = orbitCache.begin();
00922 iter != orbitCache.end(); iter++)
00923 {
00924 if ((*iter)->body == body)
00925 {
00926 (*iter)->keep = true;
00927 trajectory = &((*iter)->trajectory);
00928 break;
00929 }
00930 }
00931
00932 // If it's not in the cache already
00933 if (trajectory == NULL)
00934 {
00935 CachedOrbit* orbit = NULL;
00936
00937 // Search the cache an see if we can reuse an old orbit
00938 for (vector<CachedOrbit*>::const_iterator iter = orbitCache.begin();
00939 iter != orbitCache.end(); iter++)
00940 {
00941 if ((*iter)->body == NULL)
00942 {
00943 orbit = *iter;
00944 orbit->trajectory.clear();
00945 break;
00946 }
00947 }
00948
00949 // If we can't reuse an old orbit, allocate a new one.
00950 bool reuse = true;
00951 if (orbit == NULL)
00952 {
00953 orbit = new CachedOrbit();
00954 reuse = false;
00955 }
00956
00957 double startTime = t;
00958 int nSamples = detailOptions.orbitPathSamplePoints;
00959
00960 // Adjust the number of samples used for aperiodic orbits--these aren't
00961 // true orbits, but are sampled trajectories, generally of spacecraft.
00962 // Better control is really needed--some sort of adaptive sampling would
00963 // be ideal.
00964 if (!body->getOrbit()->isPeriodic())
00965 {
00966 double begin = 0.0, end = 0.0;
00967 body->getOrbit()->getValidRange(begin, end);
00968
00969 if (begin != end)
00970 {
00971 startTime = begin;
00972 nSamples = (int) (body->getOrbit()->getPeriod() * 100.0);
00973 nSamples = max(min(nSamples, 1000), 100);
00974 }
00975 }
00976
00977 orbit->body = body;
00978 orbit->keep = true;
00979 OrbitSampler sampler(&orbit->trajectory);
00980 body->getOrbit()->sample(startTime,
00981 body->getOrbit()->getPeriod(),
00982 nSamples,
00983 sampler);
00984 trajectory = &orbit->trajectory;
00985
00986 // If the orbit is new, put it back in the cache
00987 if (!reuse)
00988 orbitCache.insert(orbitCache.end(), orbit);
00989 }
00990
00991 // Actually render the orbit
00992 if (body->getOrbit()->isPeriodic())
00993 glBegin(GL_LINE_LOOP);
00994 else
00995 glBegin(GL_LINE_STRIP);
00996
00997 if ((renderFlags & ShowPartialTrajectories) == 0 ||
00998 body->getOrbit()->isPeriodic())
00999 {
01000 // Show the complete trajectory
01001 for (vector<OrbitSample>::const_iterator p = trajectory->begin();
01002 p != trajectory->end(); p++)
01003 {
01004 glVertex3f(astro::kilometersToAU(p->pos.x),
01005 astro::kilometersToAU(p->pos.y),
01006 astro::kilometersToAU(p->pos.z));
01007 }
01008 }
01009 else
01010 {
01011 vector<OrbitSample>::const_iterator p;
01012
01013 // Show the portion of the trajectory travelled up to this point
01014 for (p = trajectory->begin(); p != trajectory->end() && p->t < t; p++)
01015 {
01016 glVertex3f(astro::kilometersToAU(p->pos.x),
01017 astro::kilometersToAU(p->pos.y),
01018 astro::kilometersToAU(p->pos.z));
01019 }
01020
01021 // If we're midway through a non-periodic trajectory, we will need
01022 // to render a partial orbit segment.
01023 if (p != trajectory->end())
01024 {
01025 Point3d pos = body->getOrbit()->positionAtTime(t);
01026 glVertex3f((float) astro::kilometersToAU(pos.x),
01027 (float) astro::kilometersToAU(pos.y),
01028 (float) astro::kilometersToAU(pos.z));
01029 }
01030 }
01031
01032
01033 glEnd();
01034 }
|
|
||||||||||||||||||||||||
|
Definition at line 1037 of file render.cpp. References RotationElements::ascendingNode, distance(), fov, Orbit::getBoundingRadius(), Body::getClassification(), Body::getHeliocentricPosition(), Body::getOrbit(), Body::getRotationElements(), Body::getSatellites(), glRotate(), astro::kilometersToAU(), max, minOrbitSize, RotationElements::obliquity, orbitMask, pixelSize, Orbit::positionAtTime(), renderOrbit(), renderOrbitColor(), windowHeight, windowWidth, Point3< T >::x, Quaternion< double >::xrotation(), Point3< T >::y, Quaternion< double >::yrotation(), and Point3< T >::z. Referenced by render(). 01042 {
01043 if (planets == NULL)
01044 return;
01045
01046 double distance = (center - observerPos).length();
01047
01048 int nBodies = planets->getSystemSize();
01049 for (int i = 0; i < nBodies; i++)
01050 {
01051 Body* body = planets->getBody(i);
01052
01053 // Only show orbits for major bodies or selected objects
01054 if ((body->getClassification() & orbitMask) != 0 || body == sel.body())
01055 {
01056 renderOrbitColor(body, body == sel.body());
01057
01058 float orbitRadiusInPixels =
01059 (float) (body->getOrbit()->getBoundingRadius() /
01060 (distance * pixelSize));
01061 if (orbitRadiusInPixels > minOrbitSize)
01062 {
01063 float farDistance =
01064 (float) (body->getOrbit()->getBoundingRadius() + distance);
01065 farDistance = astro::kilometersToAU(farDistance);
01066
01067 // Set up the projection matrix so that the far plane is
01068 // distant enough that the orbit won't be clipped.
01069 glMatrixMode(GL_PROJECTION);
01070 glLoadIdentity();
01071 gluPerspective(fov,
01072 (float) windowWidth / (float) windowHeight,
01073 max( farDistance * 1e-6f, (float)(1e-5/2./tan(fov*3.14159/360.0)) ),
01074 farDistance * 1.1f );
01075 glMatrixMode(GL_MODELVIEW);
01076 renderOrbit(body, t);
01077
01078 if (body->getSatellites() != NULL)
01079 {
01080 Point3d localPos = body->getOrbit()->positionAtTime(t);
01081 Quatd rotation =
01082 Quatd::yrotation(body->getRotationElements().ascendingNode) *
01083 Quatd::xrotation(body->getRotationElements().obliquity);
01084 double scale = astro::kilometersToAU(1.0);
01085 glPushMatrix();
01086 glTranslated(localPos.x * scale,
01087 localPos.y * scale,
01088 localPos.z * scale);
01089 glRotate(rotation);
01090 renderOrbits(body->getSatellites(), sel, t,
01091 observerPos,
01092 body->getHeliocentricPosition(t));
01093 glPopMatrix();
01094 }
01095 }
01096 }
01097 }
01098 }
|
|
||||||||||||
|
Definition at line 6825 of file render.cpp. References glColor(), glVertex(), and Quaternion< T >::toMatrix3(). Referenced by renderStars(). 06827 {
06828 int nParticles = particles.size();
06829
06830 Mat3f m = orientation.toMatrix3();
06831 Vec3f v0 = Vec3f(-1, -1, 0) * m;
06832 Vec3f v1 = Vec3f( 1, -1, 0) * m;
06833 Vec3f v2 = Vec3f( 1, 1, 0) * m;
06834 Vec3f v3 = Vec3f(-1, 1, 0) * m;
06835
06836 glBegin(GL_QUADS);
06837 for (int i = 0; i < nParticles; i++)
06838 {
06839 Point3f center = particles[i].center;
06840 float size = particles[i].size;
06841
06842 glColor(particles[i].color);
06843 glTexCoord2f(0, 0);
06844 glVertex(center + (v0 * size));
06845 glTexCoord2f(1, 0);
06846 glVertex(center + (v1 * size));
06847 glTexCoord2f(1, 1);
06848 glVertex(center + (v2 * size));
06849 glTexCoord2f(0, 1);
06850 glVertex(center + (v3 * size));
06851 }
06852 glEnd();
06853 }
|
|
||||||||||||||||||||||||||||||||||||||||
|
Definition at line 5511 of file render.cpp. References Renderer::RenderProperties::atmosphere, disableSmoothLines(), displayedSurface, distance(), eclipseShadows, enableSmoothLines(), RotationElements::epoch, faintestPlanetMag, PlanetarySystem::getBody(), PlanetarySystem::getPrimaryBody(), Body::getSatellites(), PlanetarySystem::getSystemSize(), glRotate(), InvalidResource, labelMode, LightingState::lights, LocationLabels, Renderer::RenderProperties::locations, max, Renderer::RenderProperties::model, LightingState::nLights, RotationElements::offset, Renderer::RenderProperties::orientation, RotationElements::period, PI, pixelSize, Renderer::RenderProperties::radius, renderBodyAsParticle(), renderCompass(), renderFlags, renderObject(), Renderer::RenderProperties::rings, Renderer::RenderProperties::semiAxes, setupObjectLighting(), LightingState::shadows, ShowCelestialSphere, ShowEclipseShadows, ShowSmoothLines, Renderer::RenderProperties::surface, testEclipse(), Quaternion< T >::w, Quaternion< T >::x, Quaternion< T >::y, Quaternion< T >::yrotate(), and Quaternion< T >::z. Referenced by render(). 05520 {
05521 float altitude = distance - body.getRadius();
05522 float discSizeInPixels = body.getRadius() /
05523 (max(nearPlaneDistance, altitude) * pixelSize);
05524
05525 if (discSizeInPixels > 1)
05526 {
05527 RenderProperties rp;
05528
05529 if (displayedSurface.empty())
05530 {
05531 rp.surface = const_cast<Surface*>(&body.getSurface());
05532 }
05533 else
05534 {
05535 rp.surface = body.getAlternateSurface(displayedSurface);
05536 if (rp.surface == NULL)
05537 rp.surface = const_cast<Surface*>(&body.getSurface());
05538 }
05539 rp.atmosphere = body.getAtmosphere();
05540 rp.rings = body.getRings();
05541 rp.radius = body.getRadius();
05542 rp.semiAxes = Vec3f(1.0f, 1.0f - body.getOblateness(), 1.0f);
05543 rp.model = body.getModel();
05544
05545 // Compute the orientation of the planet before axial rotation
05546 Quatd q = body.getEclipticalToEquatorial(now);
05547
05548 double rotation = 0.0;
05549 // Watch out for the precision limits of floats when computing
05550 // rotation . . .
05551 {
05552 RotationElements re = body.getRotationElements();
05553 double rotations = (now - re.epoch) / (double) re.period;
05554 double wholeRotations = floor(rotations);
05555 double remainder = rotations - wholeRotations;
05556
05557 // Add an extra half rotation because of the convention in all
05558 // planet texture maps where zero deg long. is in the middle of
05559 // the texture.
05560 remainder += 0.5;
05561
05562 rotation = remainder * 2 * PI + re.offset;
05563 }
05564 q.yrotate(-rotation);
05565 rp.orientation = body.getOrientation() *
05566 Quatf((float) q.w, (float) q.x, (float) q.y, (float) q.z);
05567
05568 rp.locations = body.getLocations();
05569 if (rp.locations != NULL && (labelMode & LocationLabels) != 0)
05570 body.computeLocations();
05571
05572 LightingState lights;
05573 setupObjectLighting(lightSources,
05574 body.getHeliocentricPosition(now),
05575 rp.orientation,
05576 rp.semiAxes,
05577 pos,
05578 lights);
05579 assert(lights.nLights < MaxLights);
05580
05581 {
05582 // Clear out the list of eclipse shadows
05583 for (unsigned int li = 0; li < lights.nLights; li++)
05584 {
05585 eclipseShadows[li].clear();
05586 lights.shadows[li] = &eclipseShadows[li];
05587 }
05588 }
05589
05590
05591 // Calculate eclipse circumstances
05592 if ((renderFlags & ShowEclipseShadows) != 0 &&
05593 body.getClassification() != Body::Invisible &&
05594 body.getSystem() != NULL)
05595 {
05596 PlanetarySystem* system = body.getSystem();
05597
05598 if (system->getPrimaryBody() == NULL &&
05599 body.getSatellites() != NULL)
05600 {
05601 // The body is a planet. Check for eclipse shadows
05602 // from all of its satellites.
05603 PlanetarySystem* satellites = body.getSatellites();
05604 if (satellites != NULL)
05605 {
05606 int nSatellites = satellites->getSystemSize();
05607 for (unsigned int li = 0; li < lights.nLights; li++)
05608 {
05609 for (int i = 0; i < nSatellites; i++)
05610 testEclipse(body, *satellites->getBody(i),
05611 lights.lights[li],
05612 now, *lights.shadows[li]);
05613 }
05614 }
05615 }
05616 else if (system->getPrimaryBody() != NULL)
05617 {
05618 for (unsigned int li = 0; li < lights.nLights; li++)
05619 {
05620 // The body is a moon. Check for eclipse shadows from
05621 // the parent planet and all satellites in the system.
05622 Body* planet = system->getPrimaryBody();
05623 testEclipse(body, *planet, lights.lights[li],
05624 now, *lights.shadows[li]);
05625
05626 int nSatellites = system->getSystemSize();
05627 for (int i = 0; i < nSatellites; i++)
05628 {
05629 if (system->getBody(i) != &body)
05630 {
05631 testEclipse(body, *system->getBody(i),
05632 lights.lights[li],
05633 now, *lights.shadows[li]);
05634 }
05635 }
05636 }
05637 }
05638 }
05639
05640 renderObject(pos, distance, now,
05641 orientation, nearPlaneDistance, farPlaneDistance,
05642 rp, lights);
05643
05644 // Render the horizon compass for spherical and ellipsoidal bodies
05645 if ((renderFlags & ShowCelestialSphere) != 0 &&
05646 rp.model == InvalidResource &&
05647 discSizeInPixels > 100.0f)
05648 {
05649 glPushMatrix();
05650 glLoadIdentity();
05651 glDisable(GL_TEXTURE_2D);
05652 glRotate(orientation);
05653
05654 Vec3f semiAxes = rp.semiAxes * rp.radius;
05655
05656 // Compute the orientation of the planet before axial rotation
05657 Quatd q = body.getEclipticalToEquatorial(now);
05658 Quatf qf = Quatf((float) q.w, (float) q.x, (float) q.y,
05659 (float) q.z);
05660
05661 if ((renderFlags & ShowSmoothLines) != 0)
05662 enableSmoothLines();
05663 renderCompass(pos, qf, semiAxes, pixelSize / rp.radius);
05664 if ((renderFlags & ShowSmoothLines) != 0)
05665 disableSmoothLines();
05666
05667 glEnable(GL_TEXTURE_2D);
05668 glPopMatrix();
05669 }
05670 }
05671
05672 glEnable(GL_TEXTURE_2D);
05673 glEnable(GL_BLEND);
05674 glBlendFunc(GL_SRC_ALPHA, GL_ONE);
05675 renderBodyAsParticle(pos,
05676 appMag,
05677 faintestPlanetMag,
05678 discSizeInPixels,
05679 body.getSurface().color,
05680 orientation,
05681 (nearPlaneDistance + farPlaneDistance) / 2.0f,
05682 false);
05683 }
|
|
||||||||||||||||||||||||||||
|
Definition at line 6075 of file render.cpp. References addSortedLabel(), RenderListEntry::appMag, AsteroidLabels, astrocentricPosition(), RenderListEntry::body, CometLabels, conjugate(), RenderListEntry::discSizeInPixels, RenderListEntry::distance, Body::extant(), faintestPlanetMag, Body::getApparentMagnitude(), Orbit::getBoundingRadius(), Body::getClassification(), Body::getHeliocentricPosition(), Body::getName(), Body::getOrbit(), Body::getRadius(), Body::getSatellites(), RenderListEntry::isCometTail, labelMode, Vector3< T >::length(), lightSourceLists, min, minOrbitSize, MoonLabels, pixelSize, PlanetLabels, RenderListEntry::position, Orbit::positionAtTime(), RenderListEntry::radius, renderFlags, renderList, ShowCometTails, RenderListEntry::solarSysIndex, SpacecraftLabels, RenderListEntry::star, RenderListEntry::sun, Point3< T >::x, Vector3< T >::x, Point3< T >::y, Vector3< T >::y, Point3< T >::z, and Vector3< T >::z. Referenced by render(). 06081 {
06082 Point3f starPos = sun.getPosition();
06083 Point3d observerPos = astrocentricPosition(observer.getPosition(),
06084 sun, now);
06085
06086 int nBodies = solSystem.getSystemSize();
06087 for (int i = 0; i < nBodies; i++)
06088 {
06089 Body* body = solSystem.getBody(i);
06090 if (!body->extant(now))
06091 continue;
06092
06093 Point3d localPos = body->getOrbit()->positionAtTime(now);
06094 Point3d bodyPos = body->getHeliocentricPosition(now);
06095
06096 // We now have the positions of the observer and the planet relative
06097 // to the sun. From these, compute the position of the planet
06098 // relative to the observer.
06099 Vec3d posd = bodyPos - observerPos;
06100
06101 vector<LightSource>& lightSources = lightSourceLists[solarSysIndex];
06102
06103 // Compute the apparent magnitude; instead of summing the reflected
06104 // light from all nearby stars, we just consider the one with the
06105 // highest apparent brightness.
06106 float appMag = 100.0f;
06107 for (unsigned int li = 0; li < lightSources.size(); li++)
06108 {
06109 Vec3d sunPos = bodyPos - lightSources[li].position;
06110 appMag = min(appMag, body->getApparentMagnitude(lightSources[li].luminosity, sunPos, posd));
06111 }
06112
06113 Vec3f pos((float) posd.x, (float) posd.y, (float) posd.z);
06114
06115 // Compute the size of the planet/moon disc in pixels
06116 double distanceFromObserver = posd.length();
06117 float discSize = (body->getRadius() / (float) distanceFromObserver) / pixelSize;
06118
06119 // if (discSize > 1 || appMag < 1.0f / brightnessScale)
06120 if ((discSize > 1 || appMag < faintestPlanetMag) &&
06121 body->getClassification() != Body::Invisible)
06122 {
06123 RenderListEntry rle;
06124 rle.body = body;
06125 rle.star = NULL;
06126 rle.isCometTail = false;
06127 rle.position = Point3f(pos.x, pos.y, pos.z);
06128 rle.sun = Vec3f((float) -bodyPos.x, (float) -bodyPos.y, (float) -bodyPos.z);
06129 rle.distance = (float) distanceFromObserver;
06130 rle.radius = body->getRadius();
06131 rle.discSizeInPixels = discSize;
06132 rle.appMag = appMag;
06133 rle.solarSysIndex = solarSysIndex;
06134 renderList.insert(renderList.end(), rle);
06135 }
06136
06137 if (body->getClassification() == Body::Comet &&
06138 (renderFlags & ShowCometTails) != 0)
06139 {
06140 float radius = 10000000.0f; // body->getRadius() * 1000000.0f;
06141 discSize = (radius / (float) distanceFromObserver) / pixelSize;
06142 if (discSize > 1)
06143 {
06144 RenderListEntry rle;
06145 rle.body = body;
06146 rle.star = NULL;
06147 rle.isCometTail = true;
06148 rle.position = Point3f(pos.x, pos.y, pos.z);
06149 rle.radius = radius;
06150 rle.sun = Vec3f((float) -bodyPos.x, (float) -bodyPos.y, (float) -bodyPos.z);
06151 rle.distance = (float) distanceFromObserver;
06152 rle.radius = radius;
06153 rle.discSizeInPixels = discSize;
06154 rle.appMag = appMag;
06155 rle.solarSysIndex = solarSysIndex;
06156 renderList.insert(renderList.end(), rle);
06157 }
06158 }
06159
06160 if (showLabels && (pos * conjugate(observer.getOrientation()).toMatrix3()).z < 0)
06161 {
06162 float boundingRadiusSize = (float) (body->getOrbit()->getBoundingRadius() / distanceFromObserver) / pixelSize;
06163 if (boundingRadiusSize > minOrbitSize)
06164 {
06165 Color labelColor;
06166 bool showLabel = false;
06167
06168 switch (body->getClassification())
06169 {
06170 case Body::Planet:
06171 if ((labelMode & PlanetLabels) != 0)
06172 {
06173 labelColor = Color(0.0f, 1.0f, 0.0f);
06174 showLabel = true;
06175 }
06176 break;
06177 case Body::Moon:
06178 if ((labelMode & MoonLabels) != 0)
06179 {
06180 labelColor = Color(0.0f, 0.65f, 0.0f);
06181 showLabel = true;
06182 }
06183 break;
06184 case Body::Asteroid:
06185 if ((labelMode & AsteroidLabels) != 0)
06186 {
06187 labelColor = Color(0.7f, 0.4f, 0.0f);
06188 showLabel = true;
06189 }
06190 break;
06191 case Body::Comet:
06192 if ((labelMode & CometLabels) != 0)
06193 {
06194 labelColor = Color(0.0f, 1.0f, 1.0f);
06195 showLabel = true;
06196 }
06197 break;
06198 case Body::Spacecraft:
06199 if ((labelMode & SpacecraftLabels) != 0)
06200 {
06201 labelColor = Color(0.6f, 0.6f, 0.6f);
06202 showLabel = true;
06203 }
06204 break;
06205 }
06206
06207 if (showLabel)
06208 {
06209 addSortedLabel(body->getName(), labelColor,
06210 Point3f(pos.x, pos.y, pos.z));
06211 }
06212 }
06213 }
06214
06215 if (appMag < faintestPlanetMag)
06216 {
06217 const PlanetarySystem* satellites = body->getSatellites();
06218 if (satellites != NULL)
06219 {
06220 renderPlanetarySystem(sun, *satellites, observer,
06221 now, solarSysIndex, showLabels);
06222 }
06223 }
06224 }
06225 }
|
|
||||||||||||
|
Definition at line 6898 of file render.cpp. References TextureFont::bind(), depthSortedLabels, font, glColor(), PixelOffset, TextureFont::render(), windowHeight, and windowWidth. Referenced by render(). 06899 {
06900 if (font == NULL)
06901 return iter;
06902
06903 glDisable(GL_DEPTH_TEST);
06904 glEnable(GL_TEXTURE_2D);
06905 font->bind();
06906 glEnable(GL_BLEND);
06907 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
06908
06909 glMatrixMode(GL_PROJECTION);
06910 glPushMatrix();
06911 glLoadIdentity();
06912 gluOrtho2D(0, windowWidth, 0, windowHeight);
06913 glMatrixMode(GL_MODELVIEW);
06914 glPushMatrix();
06915 glLoadIdentity();
06916 glTranslatef(GLfloat((int) (windowWidth / 2)),
06917 GLfloat((int) (windowHeight / 2)), 0);
06918
06919 for (; iter != depthSortedLabels.end() && iter->position.z > depth; iter++)
06920 {
06921 glColor(iter->color);
06922 glPushMatrix();
06923 glTranslatef((int) iter->position.x + PixelOffset + 2.0f,
06924 (int) iter->position.y + PixelOffset,
06925 0.0f);
06926 font->render(iter->text);
06927 glPopMatrix();
06928 }
06929
06930 glPopMatrix();
06931 glMatrixMode(GL_PROJECTION);
06932 glPopMatrix();
06933 glMatrixMode(GL_MODELVIEW);
06934 glDisable(GL_DEPTH_TEST);
06935
06936 return iter;
06937 }
|
|
||||||||||||||||||||||||||||||||||||
|
Definition at line 5686 of file render.cpp. References Surface::appearanceFlags, Renderer::RenderProperties::atmosphere, Surface::baseTexture, Surface::color, colorTemp, CoronaHeight, distance(), RotationElements::eclipticalToEquatorial(), RotationElements::epoch, faintestMag, Atmosphere::height, InvalidResource, ColorTemperatureTable::lookupColor(), Atmosphere::lowerColor, Renderer::RenderProperties::model, RotationElements::offset, Renderer::RenderProperties::orientation, RotationElements::period, PI, pixelSize, Renderer::RenderProperties::radius, renderBodyAsParticle(), renderObject(), Renderer::RenderProperties::rings, Renderer::RenderProperties::semiAxes, Atmosphere::skyColor, Renderer::RenderProperties::surface, MultiResTexture::tex, textureResolution, Atmosphere::upperColor, Quaternion< T >::w, Quaternion< T >::x, Quaternion< T >::y, Quaternion< T >::yrotate(), and Quaternion< T >::z. Referenced by render(). 05694 {
05695 if (!star.getVisibility())
05696 return;
05697
05698 //Color color = star.getStellarClass().getApparentColor();
05699 Color color = colorTemp->lookupColor(star.getTemperature());
05700 float radius = star.getRadius();
05701 float discSizeInPixels = radius / (distance * pixelSize);
05702
05703 if (discSizeInPixels > 1)
05704 {
05705 Surface surface;
05706 RenderProperties rp;
05707
05708 surface.color = color;
05709
05710 MultiResTexture mtex = star.getTexture();
05711 if (mtex.tex[textureResolution] != InvalidResource)
05712 {
05713 surface.baseTexture = mtex;
05714 }
05715 else
05716 {
05717 surface.baseTexture = InvalidResource;
05718 }
05719 surface.appearanceFlags |= Surface::ApplyBaseTexture;
05720 surface.appearanceFlags |= Surface::Emissive;
05721
05722 rp.surface = &surface;
05723 rp.rings = NULL;
05724 rp.radius = star.getRadius();
05725 rp.semiAxes = star.getEllipsoidSemiAxes();
05726 rp.model = star.getModel();
05727
05728 Atmosphere atmosphere;
05729 atmosphere.height = radius * CoronaHeight;
05730 atmosphere.lowerColor = color;
05731 atmosphere.upperColor = color;
05732 atmosphere.skyColor = color;
05733 if (rp.model == InvalidResource)
05734 rp.atmosphere = &atmosphere;
05735 else
05736 rp.atmosphere = NULL;
05737
05738 const RotationElements& re = star.getRotationElements();
05739 Quatd q = re.eclipticalToEquatorial(now);
05740
05741 double rotation = 0.0;
05742 // Watch out for the precision limits of floats when computing
05743 // rotation . . .
05744 {
05745 const RotationElements& re = star.getRotationElements();
05746 double rotations = (now - re.epoch) / (double) re.period;
05747 double wholeRotations = floor(rotations);
05748 double remainder = rotations - wholeRotations;
05749
05750 // Add an extra half rotation because of the convention in all
05751 // planet texture maps where zero deg long. is in the middle of
05752 // the texture.
05753 remainder += 0.5;
05754
05755 rotation = remainder * 2 * PI + re.offset;
05756 }
05757 q.yrotate(-rotation);
05758 rp.orientation = Quatf((float) q.w, (float) q.x, (float) q.y, (float) q.z);
05759
05760 renderObject(pos, distance, now,
05761 orientation, nearPlaneDistance, farPlaneDistance,
05762 rp, LightingState());
05763
05764 glEnable(GL_TEXTURE_2D);
05765 }
05766
05767 glBlendFunc(GL_SRC_ALPHA, GL_ONE);
05768 renderBodyAsParticle(pos,
05769 appMag,
05770 faintestMag,
05771 discSizeInPixels,
05772 color,
05773 orientation,
05774 (nearPlaneDistance + farPlaneDistance) / 2.0f,
05775 true);
05776 }
|
|
||||||||||||||||
|
||||||||||||
|
Definition at line 570 of file render.cpp. References windowHeight, and windowWidth. Referenced by CelestiaCore::draw(), init(), and CelestiaCore::resize(). 00571 {
00572 windowWidth = width;
00573 windowHeight = height;
00574 // glViewport(windowWidth, windowHeight);
00575 }
|
|
|
Definition at line 699 of file render.cpp. References ambientLightLevel. Referenced by celestia_setambient(), CelestiaCore::charEntered(), KdeGlWidget::initializeGL(), MainWindowProc(), CommandSet::process(), CommandSetAmbientLight::process(), KdeApp::slotAmbientLightLevel(), KdePreferencesDialog::slotCancel(), and WinMain(). 00700 {
00701 ambientLightLevel = level;
00702 }
|
|
|
Definition at line 7029 of file render.cpp. References brightnessBias. Referenced by CelestiaCore::initRenderer(), CommandSetVisibilityLimit::process(), CelestiaCore::setFaintest(), and CelestiaCore::setFaintestAutoMag(). 07030 {
07031 brightnessBias = bias;
07032 }
|
|
|
Definition at line 736 of file render.cpp. References distanceLimit. Referenced by celestia_setstardistancelimit(), CommandSet::process(), and ViewOptionsProc(). 00737 {
00738 distanceLimit = distanceLimit_;
00739 }
|
|
|
Definition at line 598 of file render.cpp. References faintestAutoMag45deg. Referenced by celestia_setfaintestvisible(), CelestiaCore::charEntered(), CelestiaCore::initRenderer(), and CommandSetFaintestAutoMag45deg::process(). 00599 {
00600 faintestAutoMag45deg = _faintestAutoMag45deg;
00601 }
|
|
|
Definition at line 582 of file render.cpp. References corrFac, FOV, and fov. Referenced by render().
|
|
|
Definition at line 626 of file render.cpp. References font. Referenced by CelestiaCore::initRenderer(). 00627 {
00628 font = txf;
00629 }
|
|
|
Definition at line 747 of file render.cpp. References fragmentShaderEnabled, and fragmentShaderSupported(). 00748 {
00749 fragmentShaderEnabled = enable && fragmentShaderSupported();
00750 }
|
|
|
|
Definition at line 711 of file render.cpp. References minFeatureSize. Referenced by celestia_setminfeaturesize(), KdeGlWidget::initializeGL(), LocationsProc(), KdePreferencesDialog::slotCancel(), and KdeApp::slotMinFeatureSize(). 00712 {
00713 minFeatureSize = pixels;
00714 }
|
|
|
Definition at line 724 of file render.cpp. References minOrbitSize. Referenced by celestia_setminorbitsize(), and CommandSet::process(). 00725 {
00726 minOrbitSize = pixels;
00727 }
|
|
|
Definition at line 661 of file render.cpp. References orbitMask. Referenced by celestia_setorbitflags(), KdeGlWidget::initializeGL(), CommandOrbitFlags::process(), KdePreferencesDialog::slotCancel(), KdeApp::slotShowAsteroidOrbits(), KdeApp::slotShowCometOrbits(), KdeApp::slotShowMoonOrbits(), KdeApp::slotShowPlanetOrbits(), KdeApp::slotShowSpacecraftOrbits(), ViewOptionsProc(), and WinMain(). 00662 {
00663 orbitMask = mask;
00664 }
|
|
|
|
Definition at line 631 of file render.cpp. References renderMode. Referenced by CelestiaCore::charEntered(), and KdeApp::slotWireframeMode(). 00632 {
00633 renderMode = _renderMode;
00634 }
|
|
|
Definition at line 614 of file render.cpp. References TEXTURE_RESOLUTION, and textureResolution. Referenced by CelestiaCore::charEntered(), and WinMain(). 00615 {
00616 if (resolution < TEXTURE_RESOLUTION)
00617 textureResolution = resolution;
00618 }
|
|
|
Definition at line 7017 of file render.cpp. References saturationMag. Referenced by CelestiaCore::initRenderer(), CommandSetVisibilityLimit::process(), and CelestiaCore::setFaintest(). 07018 {
07019 saturationMag = mag;
07020 }
|
|
|
Definition at line 593 of file render.cpp. References screenDpi. Referenced by CelestiaCore::setScreenDpi(). 00594 {
00595 screenDpi = _dpi;
00596 }
|
|
|
Definition at line 675 of file render.cpp. References colorTemp. Referenced by CelestiaCore::charEntered(). 00676 {
00677 colorTemp = ct;
00678 }
|
|
|
Definition at line 7035 of file render.cpp. References starStyle. Referenced by celestia_setstarstyle(), CelestiaCore::charEntered(), MainWindowProc(), CommandSet::process(), and WinMain(). 07036 {
07037 starStyle = style;
07038 }
|
|
|
Definition at line 762 of file render.cpp. References vertexShaderEnabled, and vertexShaderSupported(). 00763 {
00764 vertexShaderEnabled = enable && vertexShaderSupported();
00765 }
|
|
|
Definition at line 60 of file render.h. 00060 {};
|
|
||||||||||||||||||||||||
|
Definition at line 5430 of file render.cpp. References EclipseShadow::direction, distance(), InvalidResource, Vector3< T >::length(), Vector3< T >::normalize(), EclipseShadow::origin, EclipseShadow::penumbraRadius, EclipseShadow::umbraRadius, Vector3< T >::x, Vector3< T >::y, and Vector3< T >::z. Referenced by renderPlanet(). 05435 {
05436
05437 // Ignore situations where the shadow casting body is much smaller than
05438 // the receiver, as these shadows aren't likely to be relevant. Also,
05439 // ignore eclipses where the caster is not an ellipsoid, since we can't
05440 // generate correct shadows in this case.
05441 if (caster.getRadius() * 100 >= receiver.getRadius() &&
05442 caster.getClassification() != Body::Invisible &&
05443 caster.extant(now) &&
05444 caster.getModel() == InvalidResource)
05445 {
05446 // All of the eclipse related code assumes that both the caster
05447 // and receiver are spherical. Irregular receivers will work more
05448 // or less correctly, but casters that are sufficiently non-spherical
05449 // will produce obviously incorrect shadows. Another assumption we
05450 // make is that the distance between the caster and receiver is much
05451 // less than the distance between the sun and the receiver. This
05452 // approximation works everywhere in the solar system, and likely
05453 // works for any orbitally stable pair of objects orbiting a star.
05454 Point3d posReceiver = receiver.getHeliocentricPosition(now);
05455 Point3d posCaster = caster.getHeliocentricPosition(now);
05456
05457 //const Star* sun = receiver.getSystem()->getStar();
05458 //assert(sun != NULL);
05459 //double distToSun = posReceiver.distanceFromOrigin();
05460 //float appSunRadius = (float) (sun->getRadius() / distToSun);
05461 float appSunRadius = light.apparentSize;
05462
05463 Vec3d dir = posCaster - posReceiver;
05464 double distToCaster = dir.length() - receiver.getRadius();
05465 float appOccluderRadius = (float) (caster.getRadius() / distToCaster);
05466
05467 // The shadow radius is the radius of the occluder plus some additional
05468 // amount that depends upon the apparent radius of the sun. For
05469 // a sun that's distant/small and effectively a point, the shadow
05470 // radius will be the same as the radius of the occluder.
05471 float shadowRadius = (1 + appSunRadius / appOccluderRadius) *
05472 caster.getRadius();
05473
05474 // Test whether a shadow is cast on the receiver. We want to know
05475 // if the receiver lies within the shadow volume of the caster. Since
05476 // we're assuming that everything is a sphere and the sun is far
05477 // away relative to the caster, the shadow volume is a
05478 // cylinder capped at one end. Testing for the intersection of a
05479 // singly capped cylinder is as simple as checking the distance
05480 // from the center of the receiver to the axis of the shadow cylinder.
05481 // If the distance is less than the sum of the caster's and receiver's
05482 // radii, then we have an eclipse.
05483 float R = receiver.getRadius() + shadowRadius;
05484 double dist = distance(posReceiver,
05485 Ray3d(posCaster, posCaster - light.position));
05486 if (dist < R)
05487 {
05488 Vec3d sunDir = posCaster - light.position;
05489 sunDir.normalize();
05490
05491 EclipseShadow shadow;
05492 shadow.origin = Point3f((float) dir.x,
05493 (float) dir.y,
05494 (float) dir.z);
05495 shadow.direction = Vec3f((float) sunDir.x,
05496 (float) sunDir.y,
05497 (float) sunDir.z);
05498 shadow.penumbraRadius = shadowRadius;
05499 shadow.umbraRadius = caster.getRadius() *
05500 (appOccluderRadius - appSunRadius) / appOccluderRadius;
05501 shadows.push_back(shadow);
05502
05503 return true;
05504 }
05505 }
05506
05507 return false;
05508 }
|
|
|
Definition at line 767 of file render.cpp. References useVertexPrograms. Referenced by setVertexShaderEnabled(). 00768 {
00769 return useVertexPrograms;
00770 }
|
|
|
Definition at line 449 of file render.h. Referenced by render(), and renderObject(). |
|
|
Definition at line 437 of file render.h. Referenced by getAmbientLightLevel(), render(), and setAmbientLightLevel(). |
|
|
Definition at line 440 of file render.h. Referenced by getBrightnessBias(), renderBodyAsParticle(), renderDeepSkyObjects(), renderStars(), and setBrightnessBias(). |
|
|
Definition at line 442 of file render.h. Referenced by render(), renderBodyAsParticle(), renderDeepSkyObjects(), and renderStars(). |
|
|
Definition at line 502 of file render.h. Referenced by getStarColorTable(), Renderer(), renderStar(), renderStars(), and setStarColorTable(). |
|
|
Definition at line 422 of file render.h. Referenced by fragmentShaderSupported(), getGLContext(), init(), loadTextures(), renderDeepSkyObjects(), renderObject(), and renderStars(). |
|
|
Definition at line 428 of file render.h. Referenced by renderBodyAsParticle(), renderDeepSkyObjects(), renderStars(), and setFieldOfView(). |
|
|
Definition at line 456 of file render.h. Referenced by addSortedLabel(), clearLabels(), render(), and renderSortedLabels(). |
|
|
Definition at line 475 of file render.h. Referenced by init(), renderObject(), and renderOrbit(). |
|
|
Definition at line 450 of file render.h. Referenced by render(), and renderPlanet(). |
|
|
Definition at line 494 of file render.h. Referenced by getDistanceLimit(), labelStars(), renderStars(), and setDistanceLimit(). |
|
|
Definition at line 457 of file render.h. Referenced by renderPlanet(). |
|
|
Definition at line 430 of file render.h. Referenced by autoMag(), getFaintestAM45deg(), and setFaintestAM45deg(). |
|
|
Definition at line 443 of file render.h. Referenced by autoMag(), labelStars(), render(), renderDeepSkyObjects(), renderStar(), and renderStars(). |
|
|
Definition at line 444 of file render.h. Referenced by render(), renderPlanet(), and renderPlanetarySystem(). |
|
|
Definition at line 431 of file render.h. Referenced by getFont(), renderLabels(), renderLocations(), renderSortedLabels(), and setFont(). |
|
|
Definition at line 426 of file render.h. Referenced by autoMag(), render(), renderBodyAsParticle(), renderDeepSkyObjects(), renderForegroundOrbits(), renderObject(), renderOrbits(), renderStars(), and setFieldOfView(). |
|
|
Definition at line 438 of file render.h. Referenced by getFragmentShaderEnabled(), and setFragmentShaderEnabled(). |
|
|
Definition at line 454 of file render.h. Referenced by renderStars(). |
|
|
|
|
|
Definition at line 462 of file render.h. Referenced by addLabelledStar(), clearLabelledStars(), labelStars(), and render(). |
|
|
Definition at line 434 of file render.h. Referenced by GetCurrentPreferences(), getLabelMode(), labelConstellations(), render(), renderDeepSkyObjects(), renderObject(), renderPlanet(), renderPlanetarySystem(), and setLabelMode(). |
|
|
Definition at line 455 of file render.h. Referenced by addLabel(), clearLabels(), render(), and renderLabels(). |
|
|
Definition at line 460 of file render.h. Referenced by render(), and renderPlanetarySystem(). |
|
|
Definition at line 496 of file render.h. Referenced by render(), and renderLocations(). |
|
|
Definition at line 495 of file render.h. Referenced by getMinimumFeatureSize(), renderLocations(), and setMinimumFeatureSize(). |
|
|
Definition at line 493 of file render.h. Referenced by getMinimumOrbitSize(), renderForegroundOrbits(), renderOrbits(), renderPlanetarySystem(), and setMinimumOrbitSize(). |
|
|
Definition at line 465 of file render.h. Referenced by addLabel(), addSortedLabel(), and render(). |
|
|
Definition at line 458 of file render.h. Referenced by render(). |
|
|
Definition at line 491 of file render.h. Referenced by render(), and renderOrbit(). |
|
|
Definition at line 436 of file render.h. Referenced by GetCurrentPreferences(), getOrbitMask(), render(), renderForegroundOrbits(), renderOrbits(), and setOrbitMask(). |
|
|
Definition at line 429 of file render.h. Referenced by render(), renderBodyAsParticle(), renderDeepSkyObjects(), renderLocations(), renderObject(), renderOrbits(), renderPlanet(), renderPlanetarySystem(), renderStar(), and renderStars(). |
|
|
Definition at line 466 of file render.h. Referenced by addLabel(), addSortedLabel(), render(), and renderMarkers(). |
|
|
|