~alexwolf/stellarium/equation-of-time

« back to all changes in this revision

Viewing changes to src/core/modules/Planet.cpp

  • Committer: Alexander Wolf
  • Date: 2014-02-05 17:02:03 UTC
  • mfrom: (6538.1.4 trunk)
  • Revision ID: alex.v.wolf@gmail.com-20140205170203-rjd6byggp6nwpp3u
sync with trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
#include "StelSkyDrawer.hpp"
31
31
#include "SolarSystem.hpp"
32
32
#include "Planet.hpp"
 
33
#include "PlanetShadows.hpp"
33
34
 
34
35
#include "StelProjector.hpp"
35
36
#include "sidereal_time.h"
443
444
        }
444
445
}
445
446
 
 
447
void Planet::computeModelMatrix(Mat4d &result) const
 
448
{
 
449
        result = Mat4d::translation(eclipticPos) * rotLocalToParent * Mat4d::zrotation(M_PI/180*(axisRotation + 90.));
 
450
        PlanetP p = parent;
 
451
        while (p && p->parent)
 
452
        {
 
453
                result = Mat4d::translation(p->eclipticPos) * result * p->rotLocalToParent;
 
454
                p = p->parent;
 
455
        }
 
456
}
 
457
 
446
458
Mat4d Planet::getRotEquatorialToVsop87(void) const
447
459
{
448
460
        Mat4d rval = rotLocalToParent;
892
904
 
893
905
                if (rings)
894
906
                {
 
907
                        rings->setupShadow(true);
895
908
                        const double dist = getEquinoxEquatorialPos(core).length();
896
909
                        double z_near = 0.9*(dist - rings->getSize());
897
910
                        double z_far  = 1.1*(dist + rings->getSize());
909
922
                        sPainter->getLight().enable();
910
923
                        glDisable(GL_DEPTH_TEST);
911
924
                        core->setClippingPlanes(n,f);  // Restore old clipping planes
 
925
                        rings->setupShadow(false);
912
926
                }
913
927
                else
914
928
                {
915
929
                        if (this==ssm->getMoon() && core->getCurrentLocation().planetName=="Earth" && ssm->nearLunarEclipse())
916
930
                        {
917
 
                                // Draw earth shadow over moon using stencil buffer if appropriate
918
 
                                // This effect curently only looks right from earth viewpoint
919
 
                                // TODO: moon magnitude label during eclipse isn't accurate...
920
 
                                glClearStencil(0x0);
921
 
                                glClear(GL_STENCIL_BUFFER_BIT);
922
 
                                glStencilFunc(GL_ALWAYS, 0x1, 0x1);
923
 
                                glStencilOp(GL_ZERO, GL_REPLACE, GL_REPLACE);
924
 
                                glEnable(GL_STENCIL_TEST);
925
 
                                drawSphere(sPainter, screenSz);
926
 
                                glDisable(GL_STENCIL_TEST);
927
 
 
928
 
                                sPainter->getLight().disable();
929
 
                                drawEarthShadow(core, sPainter);
 
931
                                PlanetShadows* shadows = PlanetShadows::getInstance();
 
932
 
 
933
                                if(shadows->isActive())
 
934
                                {
 
935
                                        shadows->setMoon(texEarthShadow);
 
936
                                        drawSphere(sPainter, screenSz);
 
937
                                        shadows->setMoon(StelTextureSP(NULL));
 
938
                                }
 
939
                                else
 
940
                                {
 
941
                                        // Draw earth shadow over moon using stencil buffer if appropriate
 
942
                                        // This effect curently only looks right from earth viewpoint
 
943
                                        // TODO: moon magnitude label during eclipse isn't accurate...
 
944
                                        glClearStencil(0x0);
 
945
                                        glClear(GL_STENCIL_BUFFER_BIT);
 
946
                                        glStencilFunc(GL_ALWAYS, 0x1, 0x1);
 
947
                                        glStencilOp(GL_ZERO, GL_REPLACE, GL_REPLACE);
 
948
                                        glEnable(GL_STENCIL_TEST);
 
949
                                        drawSphere(sPainter, screenSz);
 
950
                                        glDisable(GL_STENCIL_TEST);
 
951
 
 
952
                                        sPainter->getLight().disable();
 
953
                                        drawEarthShadow(core, sPainter);
 
954
                                }
930
955
                        }
931
956
                        else
932
957
                        {
979
1004
        // fits to the observers position. No idea why this is necessary,
980
1005
        // perhaps some openGl strangeness, or confusing sin/cos.
981
1006
 
982
 
        painter->sSphere(radius*sphereScale, oneMinusOblateness, nb_facet, nb_facet);
 
1007
        PlanetShadows* shadows = PlanetShadows::getInstance();
 
1008
 
 
1009
        if(shadows->isActive())
 
1010
        {
 
1011
                PlanetShadows::getInstance()->setupShading(painter, radius * sphereScale, oneMinusOblateness, false);
 
1012
 
 
1013
                painter->usePlanetShader(true);
 
1014
                painter->sSphere(radius*sphereScale, oneMinusOblateness, nb_facet, nb_facet);
 
1015
                painter->usePlanetShader(false);
 
1016
        }
 
1017
        else
 
1018
                painter->sSphere(radius*sphereScale, oneMinusOblateness, nb_facet, nb_facet);
 
1019
 
983
1020
        glDisable(GL_CULL_FACE);
984
1021
}
985
1022
 
1139
1176
        const double h = mat.r[ 8]*mat.r[12]
1140
1177
                                   + mat.r[ 9]*mat.r[13]
1141
1178
                                   + mat.r[10]*mat.r[14];
 
1179
 
1142
1180
        sPainter->sRing(radiusMin,radiusMax,(h<0.0)?slices:-slices,stacks, 0);
 
1181
 
1143
1182
        glDisable(GL_CULL_FACE);
1144
1183
}
1145
1184
 
 
1185
void Ring::setupShadow(bool setup)
 
1186
{
 
1187
        PlanetShadows* shadows = PlanetShadows::getInstance();
 
1188
 
 
1189
        if(shadows->isActive())
 
1190
        {
 
1191
                if(setup)
 
1192
                        shadows->setRings(tex, radiusMin, radiusMax);
 
1193
                else
 
1194
                        shadows->setRings(StelTextureSP(NULL), 0, 0);
 
1195
        }
 
1196
}
 
1197
 
1146
1198
 
1147
1199
// draw orbital path of Planet
1148
1200
void Planet::drawOrbit(const StelCore* core)