CameraObject Manual

About

A CameraObject represents a camera in Cinema 4D. It is based on BaseObject (see BaseObject Manual).

CameraObject objects are an instance of Ocamera.

Access

A CameraObject is typically obtained from a BaseDraw representing a viewport window. This BaseDraw is obtained from the a BaseDocument.

See also BaseDocument Editor Windows.

// This example gets the currently used camera.
if (!bd)
return false;
BaseObject* camera = bd->GetSceneCamera(doc);
if (!camera)
camera = bd->GetEditorCamera();
GePrint("Camera name: " + camera->GetName());
Note
Cinema 4D can use any object as a "camera" so the returned BaseObject may or may not be a CameraObject. One can check if it is a CameraObject with C4DAtom::IsInstanceOf().

Also a generator can contain a CameraObject. To get the real camera from that generator a message has to be sent to that generator:

// This example tries to get the internal camera from a generator.
// Typically used with the Alembic Generator camera.
// send the message to the object to get the "real camera"
// and check the result
if (camera->Message(MSG_GETREALCAMERADATA, &data) && data.res)
camera = data.res;

Allocation/Deallocation

CameraObject objects are created with the usual tools:

A new or existing camera can be set as the active scene camera:

// This example creates a new camera object and uses it as the scene camera.
if (!camera)
return false;
doc->InsertObject(camera, nullptr, nullptr);
camera->SetName("The new camera");
const Matrix mg = MatrixMove(Vector(0, 0, -500));
camera->SetMg(mg);
if (bd)
bd->SetSceneCamera(camera);

Properties

The parameters of a CameraObject are edited as usual with C4DAtom::GetParameter() and C4DAtom::SetParameter(). The parameter IDs are defined in Ocamera.h.

Warning
Some parameters of the camera are "virtual" (CAMERAOBJECT_FOV and CAMERAOBJECT_FOV_VERTICAL) and cannot be accessed in any situation.

For some parameters dedicated functions exist.

Projection

These functions access the camera projection setting:

// This example stets the projection of the given camera object to "Parallel".
CameraObject* camera = static_cast<CameraObject*>(obj);

Zoom

These functions set the camera zoom value:

Offset

These functions set the camera position. This is the midpoint for orthogonal projections (Front/Back/Top/Bottom etc.).

Note
This is the same as setting the position with BaseObject::SetAbsPos().

Aperture

These functions set the camera aperture value:

Focus

These functions set the camera focus value:

Stereoscopic Camera

A CameraObject can also store information about the stereoscopic cameras it represents.

The stereo camera information is stored in a StereoCameraInfo struct object:

// This example loops through the stereo cameras of the given camera object.
const Int32 stereoCount = camera->StereoGetCameraCount(doc, bd, renderData, 0);
for (Int32 i = 0; i < stereoCount; ++i)
{
camera->StereoGetCameraInfo(doc, bd, renderData, i, info, 0);
GePrint("Stereo Camera name: " + info.strName);
}

Further Reading