FBX SDK Programmer's Guide > Nodes and the Scene Graph > FBX Node Attributes >

# Cameras

Creating a Camera

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

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

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

    // Create a light.
    FbxCamera* lCamera = FbxCamera::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.
    FbxNode* 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 FbxNode::SetTarget(). The FbxMarker node attribute is used in the target node.

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

    // Create a marker node attribute.
    FbxMarker* lMarker = FbxMarker::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 FbxNode class documentation for more information.

By default, the FbxCamera::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(FbxCamera::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 FbxCamera class documentation for more information on configuring cameras in a scene.