MCPcopy Create free account
hub / github.com/carbonengine/trinity / SetupPlanetsAsShadowCaster

Method SetupPlanetsAsShadowCaster

trinity/Eve/EveSpaceScene.cpp:3923–3974  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3921}
3922
3923void EveSpaceScene::SetupPlanetsAsShadowCaster( CcpMath::Sphere* planets, size_t maxPlanets )
3924{
3925 Vector3 sunPosition = { 0, 0, 0 };
3926 if( m_sunBall )
3927 {
3928 m_sunBall->GetValueAt( &sunPosition, m_updateContext.GetTime() );
3929 }
3930
3931 std::vector<PlanetInfo> visiblePlanets;
3932 for( EvePlanet* obj : m_planets )
3933 {
3934 float pixelSize = obj->GetEstimatedPixelDiameter();
3935 if( pixelSize > 50.0f )
3936 {
3937 // we don't want the sun to be a shadow caster
3938 if( obj->GetTranslationCurve() != nullptr && obj->GetTranslationCurve() == m_sunBall )
3939 {
3940 continue;
3941 }
3942 if( obj->GetTranslationCurve() && m_sunBall )
3943 {
3944 // Check if the planet is behind the sun. The check is for an exotic case when a large
3945 // planet is close enogh to the sun and the player is at the opposite side of the sun.
3946 // In this case we can't treat the sun as an infinely far light source.
3947 Vector3 planetPosition = { 0, 0, 0 };
3948 obj->GetTranslationCurve()->GetValueAt( &planetPosition, m_updateContext.GetTime() );
3949
3950 if( Dot( planetPosition - sunPosition, Vector3( 0, 0, 0 ) - sunPosition ) < 0 )
3951 {
3952 continue;
3953 }
3954 }
3955 Vector3 planetWorldPos = obj->GetWorldPosition();
3956 float radius = obj->GetRadius();
3957 PlanetInfo p = { { Vector4( planetWorldPos, radius ) }, pixelSize };
3958 visiblePlanets.emplace_back( p );
3959 }
3960 }
3961
3962 // sort the visiblePlanet list by the pixelSize so we get the 2 largest ones
3963 std::sort( visiblePlanets.begin(), visiblePlanets.end(), []( const PlanetInfo& a, const PlanetInfo& b ) {
3964 return a.pixelSize > b.pixelSize;
3965 } );
3966
3967 // cut unnecessary objects from the list, or if we only have 1 planet the other index is just filled with 0 values
3968 visiblePlanets.resize( maxPlanets );
3969
3970 for( size_t i = 0; i < maxPlanets; i++ )
3971 {
3972 planets[i] = CcpMath::Sphere( visiblePlanets[i].sphere );
3973 }
3974}
3975
3976void EveSpaceScene::SetupPlanetsAsShadowCaster( Tr2RenderContext& renderContext )
3977{

Callers

nothing calls this directly

Calls 13

GetTranslationCurveMethod · 0.80
ApplyBufferMethod · 0.80
DotFunction · 0.50
Vector3Class · 0.50
Vector4Class · 0.50
GetValueAtMethod · 0.45
GetTimeMethod · 0.45
GetWorldPositionMethod · 0.45
GetRadiusMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected