| 40 | } |
| 41 | |
| 42 | void Tr2Transform::UpdateViewDependentData( const TriFrustum& frustum, const Matrix& parentTransform ) |
| 43 | { |
| 44 | Vector3 finalScale; |
| 45 | if( m_useDistanceBasedScale ) |
| 46 | { |
| 47 | Vector3 myPos = TransformCoord( m_translation, parentTransform ); |
| 48 | |
| 49 | const Vector3& camPos = Tr2Renderer::GetViewPosition(); |
| 50 | Vector3 d = myPos - camPos; |
| 51 | const float dist = Length( d ); |
| 52 | const float fov = Tr2Renderer::GetFieldOfView(); |
| 53 | |
| 54 | //fovHeight is the thing to multiply with to let the object |
| 55 | //always keep the same height on screen |
| 56 | const float fovHeight = sinf( fov / 2.0f ) * dist; |
| 57 | |
| 58 | //this is the number we want to reduce it by |
| 59 | const float scaler = m_distanceBasedScaleArg1 / powf( fovHeight, m_distanceBasedScaleArg2 ); |
| 60 | const float scale = scaler * fovHeight; |
| 61 | |
| 62 | finalScale = m_scaling * scale; |
| 63 | } |
| 64 | else |
| 65 | { |
| 66 | finalScale = m_scaling; |
| 67 | } |
| 68 | m_lastWorldTransform = m_worldTransform; |
| 69 | m_localTransform = TransformationMatrix( finalScale, m_rotation, m_translation ); |
| 70 | m_worldTransform = m_localTransform * parentTransform; |
| 71 | |
| 72 | switch( m_modifier ) |
| 73 | { |
| 74 | case TR2TM_BILLBOARD: |
| 75 | case TR2TM_SIMPLE_HALO: { |
| 76 | float parentScaleX = Length( parentTransform.GetX() ); |
| 77 | float parentScaleY = Length( parentTransform.GetY() ); |
| 78 | float parentScaleZ = Length( parentTransform.GetZ() ); |
| 79 | finalScale.x *= parentScaleX; |
| 80 | finalScale.y *= parentScaleY; |
| 81 | finalScale.z *= parentScaleZ; |
| 82 | |
| 83 | if( m_modifier == TR2TM_SIMPLE_HALO ) |
| 84 | { |
| 85 | const Vector3& myPos = m_worldTransform.GetTranslation(); |
| 86 | const Vector3& camPos = Tr2Renderer::GetViewPosition(); |
| 87 | Vector3 d = camPos - myPos; |
| 88 | |
| 89 | Vector3 backward; |
| 90 | |
| 91 | float scale = Dot( |
| 92 | Normalize( d ), |
| 93 | Normalize( *TriVectorRotatedBasisMatrix( &backward, TRITA_Z, &m_worldTransform ) ) ); |
| 94 | |
| 95 | if( scale < 0.0f ) |
| 96 | { |
| 97 | scale = 0.0f; |
| 98 | } |
| 99 |
nothing calls this directly
no test coverage detected