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

Method CalculateBoxPosition

trinity/Curves/Tr2FollowCurveKey.cpp:202–248  ·  view source on GitHub ↗

This function finds the place between two cones where xy object bounds can be placed. It sets two variables: - one how far down the view vector the front of the bounds are offset - one how far away from the view vector the bounds are offset Then it calculates the box position based on those variables */

Source from the content-addressed store, hash-verified

200 Then it calculates the box position based on those variables
201*/
202void Tr2CameraFollowCurveKey::CalculateBoxPosition()
203{
204 auto rotMatrix = Tr2Renderer::GetInverseViewTransform();
205 m_fov = Tr2Renderer::GetFieldOfView() * 0.5f;
206 m_frontClip = Tr2Renderer::GetFrontClip();
207
208 if( !m_enabled )
209 {
210 rotMatrix = m_lastEnabledInverseViewMatrix;
211 m_fov = m_lastEnabledFOV;
212 m_frontClip = m_lastEnabledFrontClip;
213 }
214
215
216 float tanOuterFov = tan( m_fov );
217 float tanInnerFov = tan( m_fov * m_fovMultiplication );
218
219 float nearClipPlaneSize = m_frontClip / tanOuterFov;
220 float aspectRatio = Tr2Renderer::GetAspectRatio();
221
222 float nearClipDistFromViewVector = max( nearClipPlaneSize * aspectRatio, nearClipPlaneSize / aspectRatio );
223 float radius = max( Length( m_objectBounds.GetXY() ), nearClipDistFromViewVector );
224
225 if( tanInnerFov == tanOuterFov )
226 {
227 m_minDistanceFromViewAngle = 0;
228 m_minDistanceAlongViewAngle = 0;
229 return;
230 }
231
232 m_minDistanceAlongViewAngle = 2.0f * radius / ( tanOuterFov - tanInnerFov );
233 m_minDistanceFromViewAngle = m_minDistanceAlongViewAngle * tanInnerFov;
234 if( m_minDistanceAlongViewAngle < m_frontClip + m_objectBounds.z )
235 {
236 m_minDistanceAlongViewAngle = m_frontClip + m_objectBounds.z;
237 m_minDistanceFromViewAngle = m_minDistanceAlongViewAngle * tanInnerFov;
238 }
239
240 auto boxCenter = Vector3( 0, 0, -m_minDistanceAlongViewAngle - m_objectBounds.z ) + m_offset * Vector3( 1, 1, -1 );
241 auto orientationMatrix = RotationMatrix( RotationQuaternion( Vector3( 0, 0, -1 ), m_angle + m_angleZero ) );
242
243 auto boxOffsetXY = TransformCoord( Vector3( radius + m_minDistanceFromViewAngle, 0, 0 ), orientationMatrix );
244
245 m_rotatedLeftTangent = TransformCoord( m_leftTangent, rotMatrix );
246 m_rotatedRightTangent = TransformCoord( m_rightTangent, rotMatrix );
247 m_boxPosition = TransformCoord( boxOffsetXY + boxCenter, rotMatrix );
248}
249
250Vector3 Tr2CameraFollowCurveKey::GetValue()
251{

Callers

nothing calls this directly

Calls 5

GetFieldOfViewFunction · 0.85
GetFrontClipFunction · 0.85
GetAspectRatioFunction · 0.85
LengthFunction · 0.85
Vector3Class · 0.50

Tested by

no test coverage detected