Hi all,
Here my code to compute a bounding sphere from camera + near + far :
void ExtractFrustumSphere( CCameraActor* Camera, const float Near, const float Far, CVector3* Center, float* Radius )
{
// Get the camera component.
CCameraComponent* CameraComponent = static_cast< CCameraComponent* >( Camera->GetComponent( 0 ) );
// Camera params.
const CVector3 CameraPos = Camera->GetWorldTranslationVector();
const CVector3 CameraRight = Camera->GetRightVector();
const CVector3 CameraForward = Camera->GetForwardVector();
const CVector3 CameraUp = Camera->GetUpVector();
// Tangent values.
const float TanFOVX = CMath::Tan( CameraComponent->GetAspectRatio() * CameraComponent->GetFieldOfView() * 0.5f );
const float TanFOVY = CMath::Tan( CameraComponent->GetAspectRatio() );
// Compute the half distance.
const float HalfDistance = 0.5f * ( Far - Near );
// Compute the center.
*Center = CameraPos + CameraForward * ( Near + HalfDistance );
// Compute the radius.
*Radius = ( ( CameraRight * TanFOVX + CameraUp * TanFOVY + CameraForward ) * HalfDistance ).Length();
}
I'm not sure if I use the correct way to compute the radius.
I think this is wrong because for a near of 0.1f and a far of 100.0f with a FOV of QUATER_PI, I have 246 of radius.
What is wrong in the calcule of the radius ?
Thanks for the help.
EDIT :
I saw I used a bad value for TanFOVY, I have changed to use :
const float TanFOVX = CMath::Tan( CameraComponent->GetAspectRatio() * CameraComponent->GetFieldOfView() * 0.5f );
const float TanFOVY = CMath::Tan( CameraComponent->GetFieldOfView() * 0.5f );
I Have a radius of 68 for the same values I said before, Is it the correct answer ?