メインコンテンツ

Camera

R2026b

Specify RoadRunner Viewer camera

Since R2026b

    Description

    The Camera object represents the RoadRunner Viewer camera. Use a Camera object to programmatically specify the position and orientation of the viewer camera. You can update the Transform property at each simulation step to specify for the camera to follow an actor during simulation.

    Creation

    To return the Camera object that represents the RoadRunner Viewer camera, extract the Camera property of your roadrunnerViewer object and assign it to a variable. For example, cam = rrViewer.Camera creates the Camera object cam.

    Properties

    expand all

    Transform matrix of the camera, in world coordinates, specified as a 4-by-4 matrix. The first three columns represent the right, up, and backward directions of the camera, respectively. The camera points in the direction opposite to the value in the third column. The fourth column represents the camera position.

    Examples

    collapse all

    Use a Camera object to programmatically move the RoadRunner Viewer camera. This example assumes you have already added the folder containing the RoadRunner API to your MATLAB® path. For information on getting started with RoadRunner Viewer, see Get Started with RoadRunner Viewer (RoadRunner Scenario).

    Open RoadRunner Viewer and create a roadrunnerViewer object rrViewer.

    rrViewer = roadrunnerViewer;

    Extract the object for the RoadRunner Viewer camera from the Camera property of the roadrunnerViewer object rrViewer. The extracted Camera object enables you to specify different camera positions and orientations.

    cam = rrViewer.Camera;

    To change the position of the RoadRunner Viewer camera, modify the Transform property of cam.

    This code modifies the transform matrix so the camera points down at the RoadRunner Viewer origin from a height of 100 meters. The eye function creates a 3-by-3 identity matrix that represents the camera orientation. This orientation points the camera straight down.

    camOrientation = eye(3); 
    camHeight = [0; 0; 100];
    cam.Transform = [camOrientation camHeight;[0 0 0 1]];

    To update the RoadRunner Viewer scene graph to show the new camera position, use the drawnow function.

    drawnow(rrViewer)

    Version History

    Introduced in R2026b