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

Method UpdateViewDependentData

trinity/Particle/Tr2ParticleSystem.cpp:1021–1065  ·  view source on GitHub ↗

-------------------------------------------------------------------------------------- Description: Called before particle system is used for rendering. Optionally sorts particles and updates vertex buffer if needed. --------------------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

1019// and updates vertex buffer if needed.
1020// --------------------------------------------------------------------------------------
1021void Tr2ParticleSystem::UpdateViewDependentData( const TriFrustum* frustum, const Matrix& worldTransform )
1022{
1023 CCP_STATS_ZONE( __FUNCTION__ );
1024
1025 m_shouldSortVisible = false;
1026
1027 m_worldTransform = worldTransform;
1028
1029 if( !m_bufferDirty && !m_requiresSorting )
1030 {
1031 return;
1032 }
1033
1034 if( !m_vertexBuffer.IsValid() )
1035 {
1036 return;
1037 }
1038
1039 m_shouldSortVisible = true;
1040 m_updatePeriod = 1;
1041 if( frustum )
1042 {
1043 Vector3 minB, maxB;
1044 //If we were about to sort, first check that this system is visible and large enough to warrant sorting
1045 if( GetBoundingBox( minB, maxB ) )
1046 {
1047 Vector3 centre( ( maxB + minB ) * 0.5f );
1048 const Vector3 extent( ( maxB - minB ) * 0.5f );
1049
1050 //use the contained sphere rather than circumscribing sphere, just to be a little conservative
1051 float radius = std::max( std::abs( extent.x ), std::max( std::abs( extent.y ), std::abs( extent.z ) ) );
1052 radius *= Length( m_worldTransform.GetX() );
1053
1054 centre = Vector3( XMVector3TransformCoord( centre, m_worldTransform ) );
1055 const Vector4 boundingSphere = Vector4( centre.x, centre.y, centre.z, radius );
1056
1057 if( !frustum->IsSphereVisible( &boundingSphere ) )
1058 {
1059 m_shouldSortVisible = false;
1060 // update every fourth frame
1061 m_updatePeriod = 4;
1062 }
1063 }
1064 }
1065}
1066
1067void Tr2ParticleSystem::SortParticles()
1068{

Callers

nothing calls this directly

Calls 6

LengthFunction · 0.85
IsSphereVisibleMethod · 0.80
Vector3Class · 0.50
Vector4Class · 0.50
IsValidMethod · 0.45
GetXMethod · 0.45

Tested by

no test coverage detected