Valid Camera Ratio

Camera Setup Guidelines (in 3DF and HPS) recommend “the distance from the camera position to the camera target should be 2.5 times the field width.” This is known as the camera ratio.

When the camera ratio is much greater than 2.5, the scene’s visual integrity may degrade (artifacts including edge stitching and edge shine-through). For example, the strange rendering in the scene below comes from a very large camera ratio. The inset scene uses a very similar camera with a valid camera ratio.

The documentation describes a processes for computing valid camera settings.

The following code illustrates how to validate camera settings in the 3DF Part Viewer

// 3DF - ...\demo\mfc\partviewer_common\CSolidHoopsView.cpp
bool IsValidCamera(HC_KEY sceneKey, float *cameraRatio)
{
    HPoint camera, target;
    float width, h;
    HC_Open_Segment_By_Key(sceneKey);
    HC_Show_Camera_Position(&camera.x, &camera.y, &camera.z);
    HC_Show_Camera_Target(&target.x, &target.y, &target.z);
    HC_Show_Camera_Field(&width, &h);
    HC_Close_Segment();
    HVector viewVector = target - camera;
    *cameraRatio = (float)HC_Compute_Vector_Length(&viewVector) / width;
    return (abs(2.5 - *cameraRatio) < 0.01);
}

void CSolidHoopsView::OnExtraSlot1()
{
    float cameraRatio = 0;
    if (!IsValidCamera(GetSceneKey(), &cameraRatio))
    {
        wchar_t message[MVO_BUFFER_SIZE + 1] = { L"" };
        swprintf(message, MVO_BUFFER_SIZE, L"INVALID CAMERA\n%g.", cameraRatio);
        MessageBox(H_TEXT(message), _T("ERROR!"), MB_OK);
    }
}

and the HPS MFC Sandbox

// HPS - ...\samples\mfc_sandbox\CHPSView.cpp
bool IsValidCamera(HPS::CameraKit camera, float *cameraRatio)
{
	HPS::Point position, target;
	float width, height;
	camera.ShowPosition(position);
	camera.ShowTarget(target);
	camera.ShowField(width, height);
	HPS::Vector viewVector = target - position;
	*cameraRatio = viewVector.Length() / width;
	return (abs(2.5 - *cameraRatio) < 0.01);
}

void CHPSView::OnUserCode1()
{
	HPS::CameraKit theCamera;
	GetCanvas().GetFrontView().GetSegmentKey().ShowCamera(theCamera);
	float cameraRatio = 0;
	if (!IsValidCamera(theCamera, &cameraRatio))
	{
		CString message;
		message.Append(L"INVALID CAMERA\n");
		message.AppendFormat(L"%g", cameraRatio);
		MessageBox(message, _T("ERROR!"), MB_OK);
	}
}