Show / Hide Table of Contents

Camera Properties Example

This example shows you how to use the Camera. A camera is the view point of the station, and can be set to follow an object. In this example we create a box and follow the box when it moves. Try to freehand move the box and see how the box stays in the same position (relative the screen) but the floor moves relative the box.

You can lock the view by setting myCam.LockRotate, myCam.LockTranslate and myCam.LockZoom to zero or a positive number. Release the lock by setting the same properties to a negative number.

Example

Project.UndoContext.BeginUndoStep("CameraProperties");
try
{
    Station station = Station.ActiveStation;

    // Create a Camera.
    Camera myCam = new Camera();

    // Set the camera to look at a specific point.
    myCam.LookAt = new Vector3(0, 0, 0);

    // Set the camera to view from a specific point.
    myCam.LookFrom = new Vector3(10, 10, 10);

    // Fix the camera to this point.
    myCam.LockRotate = 0.0;
    myCam.LockTranslate = 0.0;
    myCam.LockZoom = 0.0;

    // Add it to the stations camera collection.
    station.Cameras.Add(myCam);

    // Sync the current view to the camera view.
    GraphicControl.ActiveGraphicControl.SyncCamera(myCam, true, 0);

    // Use the camera as the true camera.
    // This make sure that the constraints on the movement kicks in.
    GraphicControl.ActiveGraphicControl.Camera = myCam;

    // Unlock the view (negative values removes the locks).
    myCam.LockRotate = -1.0;
    myCam.LockTranslate = -1.0;
    myCam.LockZoom = -1.0;

    // Create a solid box to follow.
    Part myPart = new Part();
    station.GraphicComponents.Add(myPart);
    Body box = Body.CreateSolidBox(new Matrix4(Vector3.XVector, 0.0), new Vector3(0.1, 0.1, 0.1));
    myPart.Bodies.Add(box);

    // Keep the direction in which the view of the box fixed.
    myCam.FollowBehavior = FollowObjectBehavior.FixDirection;

    // Follow the box.
    myCam.FollowObject = myPart;

    // Move the part in the GUI.
    // Observe how the part moves relative the floor,
    // but how the camera follows the part.
}
catch
{
    Project.UndoContext.CancelUndoStep(CancelUndoStepType.Rollback);
    throw;
}
finally
{
    Project.UndoContext.EndUndoStep();
}

See Also

  • Camera
  • GraphicControl
  • FollowObjectBehavior
  • RobotStudio Community
In this article
Back to top Copyright © 2025 ABB