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

Method UpdateValue

trinity/Tr2ProjectBoundingBoxBracket.cpp:33–243  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

31
32
33void Tr2ProjectBoundingBoxBracket::UpdateValue( double time )
34{
35 if( !m_object )
36 {
37 return;
38 }
39
40 if( !m_object->IsBoundingBoxReady() )
41 {
42 return;
43 }
44
45 Vector3 bbMin, bbMax;
46 if( !m_object->GetWorldBoundingBox( bbMin, bbMax ) )
47 {
48 return;
49 }
50
51 Vector3 expansion( 0.5f, 0.5f, 0.5f );
52 Vector3 expandedMin = bbMin - expansion;
53 Vector3 expandedMax = bbMax + expansion;
54 if( BoundingBoxIsInside( expandedMin, expandedMax, Tr2Renderer::GetViewPosition() ) )
55 {
56 // Camera is inside bounding box - can't do any sensible projection
57 SetEmptyProjection();
58 return;
59 }
60
61 Vector3 center = ( bbMax + bbMin ) * 0.5f;
62 Vector3 projectedCenter;
63 Matrix viewProj;
64 projectedCenter = TransformCoord( center, Tr2Renderer::GetViewTransform() );
65 projectedCenter = TransformCoord( projectedCenter, Tr2Renderer::GetProjectionTransform() );
66 Vec3TransformByViewport( projectedCenter, Tr2Renderer::GetViewport() );
67 if( projectedCenter.z <= 0.0f || projectedCenter.z >= 1.0f )
68 {
69 SetEmptyProjection();
70 return;
71 }
72
73 Vector3 d = Tr2Renderer::GetViewPosition() - center;
74 m_cameraDistance = Length( d );
75
76 BoundingBoxProject(
77 bbMin,
78 bbMax,
79 Tr2Renderer::GetViewTransform(),
80 Tr2Renderer::GetProjectionTransform(),
81 Tr2Renderer::GetViewport() );
82
83 if( bbMin.z <= 0.0f || bbMax.z >= 1.0f )
84 {
85 SetEmptyProjection();
86 return;
87 }
88
89 m_projectedZ = std::min( bbMin.z, bbMax.z );
90

Callers

nothing calls this directly

Calls 14

BoundingBoxIsInsideFunction · 0.85
GetViewPositionFunction · 0.85
GetViewTransformFunction · 0.85
GetProjectionTransformFunction · 0.85
Vec3TransformByViewportFunction · 0.85
LengthFunction · 0.85
BoundingBoxProjectFunction · 0.85
SetDisplayXMethod · 0.80
SetDisplayYMethod · 0.80
SetDisplayWidthMethod · 0.80
SetDisplayHeightMethod · 0.80
IsBoundingBoxReadyMethod · 0.45

Tested by

no test coverage detected