| 31 | |
| 32 | |
| 33 | void 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 |
nothing calls this directly
no test coverage detected