Cameras
 
 
 

Creating a Camera

Cameras in the FBX SDK are abstracted by the KFbxCamera class. Stereocameras for 3D imaging are abstracted by the KFbxCameraStereo class. In this topic, we will only look at the basic ways to create and manipulate a KFbxCamera.

By default, a KFbxCamera points in the direction of the node's positive X axis.

// Create a node for our camera in the scene.
KFbxNode* lCameraNode = KFbxNode::Create(pScene, "cameraNode");

// Create a light.
KFbxCamera* lCamera = KFbxCamera::Create(pScene, "camera");

// Set the node attribute of the camera node.
lCameraNode->SetNodeAttribute(lCamera);

// Add the camera node to the root node in the scene.
KFbxNode* lRootNode = pScene->GetRootNode();
lRootNode->AddChild(lCameraNode);

Once a camera has been created, it can be set as the scene's default camera. A scene must have its default camera set explicitly, even if there is only one camera in the scene.

// Set the scene's default camera.
pScene->GetGlobalSettings().SetDefaultCamera((char *) lCamera->GetName());

Pointing a Camera

A camera can be forced to consistently point towards a specific target in the scene. To do this, the camera's node must have its target set using KFbxNode::SetTarget(). The KFbxMarker node attribute is used in the target node.

// Create a node to contain the marker. This will be our target node.
KFbxNode* lTargetNode = KFbxNode::Create(pScene, "targetNode");

// Create a marker node attribute.
KFbxMarker* lMarker = KFbxMarker::Create(pScene, "cameraMarker");

// Set the marker as the target node's attribute.
lTargetNode->SetNodeAttribute(lMarker);

// Set our camera node's target.
lCameraNode->SetTarget(lTargetNode);

NoteConsult the "Node Target Management" section in the KFbxNode class documentation for more information.

By default, the KFbxCamera::FocusSource property is set to ECameraFocusDistanceSource::eCAMERA_INTEREST to maintain focus on the camera's target. The focus source can also be set to a specific distance from the camera.

// Set the camera's focus source to a specific distance.
lCamera->FocusSource.Set(KFbxCamera::eSPECIFIC_DISTANCE);

// Set the distance to 100.0 units from the camera. 
// The default value for this distance is 200.0 units.
lCamera->FocusDistance.Set(100.0);

Camera Properties

Consult the KFbxCamera class documentation for more information on configuring cameras in a scene.