void ModelBrowserTool::SetCameraFocus() { BoundingBox boundingBox = mModel->GetBoundingBox(); Vector3f boxCenter = boundingBox.GetCenter(); // Cubify the bounding box. BoundingBox boundingCube = boundingBox; Float maxValue = Maths::Max(boundingCube.Max().x, Maths::Max(boundingCube.Max().y, boundingCube.Max().z)); Float minValue = Maths::Min(boundingCube.Min().x, Maths::Min(boundingCube.Min().y, boundingCube.Min().z)); boundingCube.SetMax( Vector3f(maxValue, maxValue, maxValue) ); boundingCube.SetMin( Vector3f(minValue, minValue, minValue) ); // Recenter Vector3f cubeCenter = boundingCube.GetCenter(); Vector3f offset = cubeCenter - boxCenter; cubeCenter -= offset; boundingCube(0) -= offset; boundingCube(1) -= offset; Float fovAngle = Maths::ToRadians(mCamera.GetFovAngle()); Float halfFov = fovAngle / 2.0f; Float sin = Maths::Sin(halfFov); Float cos = Maths::Cos(halfFov); // Compute the camera position and viewing position. Float halfPos = cubeCenter.y - boundingCube.Min().y; Float zPos = boundingBox.Max().z + (cos * halfPos / sin); mCamera.SetPosition(Vector3f(boxCenter.x, boxCenter.y, zPos)); mObjectCenter = Vector3f(boxCenter.x, boxCenter.y, boxCenter.z); }
void ObjectController::SetRayCastObjectBoundingBox( const BoundingBox& bound ) { if(m_pRayCastBox!=NULL){ Float3 vPos = bound.GetCenter(); Float3 vScale = bound.GetHalfSize(); m_pRayCastBox->m_WorldMatrix = Float44(vPos,vScale,Float4(0,0,0,1)); } }