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

Method UpdateViewDependentData

trinity/Tr2Transform.cpp:42–248  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

40}
41
42void 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

Callers

nothing calls this directly

Calls 15

GetViewPositionFunction · 0.85
LengthFunction · 0.85
GetFieldOfViewFunction · 0.85
TransposeFunction · 0.85
TriVectorRotateMatrixFunction · 0.85
LengthSqFunction · 0.85
GetViewTransformFunction · 0.85
CrossFunction · 0.85
TriMatrixChangeBaseFunction · 0.85
TriMatrixRotateFunction · 0.85
GetTranslationMethod · 0.80

Tested by

no test coverage detected