Main Content

createViewport

Create custom view of 3D environment

Since R2022b

    Description

    createViewport(world) creates a view of the sim3d.World object specified by world with default values and saves the view as a field in the viewport structure.

    If you do not create a viewport, then the Simulation 3D Viewer window displays the default view of the 3D environment from the field Default in the viewport structure. You can use the arrow keys and pointer to navigate in the environment.

    createViewport(world,Name=Value) specifies additional options using one or more name-value arguments to create a custom view of the sim3d.World object specified by world. For example, to create a viewport named View1 at (5,0,2), set Name to View1 and Translation to [5 0 2].

    If you create multiple viewports, you can use the setView function to set one as the view for the 3D environment.

    example

    Examples

    collapse all

    Create a viewport to generate a custom view of the 3D environment.

    Create a world object using the sim3d.World object.

    world = sim3d.World();

    Create a box actor in the 3D environment using the sim3d.Actor object. Add the box actor to the world.

    box = sim3d.Actor(ActorName='Box');
    createShape(box,'box',[0.5 0.25 0.25]);
    box.Color = [1 0 0];
    add(world,box);

    Create a viewport to generate a view from the location [0 4 0] and with rotation [0 0 -pi/2].

    viewport1 = createViewport( ...
        world,Translation=[0 4 0],Rotation=[0 0 -pi/2]);

    Run the simulation.

    sampletime = 0.01;
    stoptime = 5;
    run(world,sampletime,stoptime);

    Box actor in the 3D environment

    Input Arguments

    collapse all

    World object where viewport is added, specified as a sim3d.World object. You can view the fields in the viewport structure from the Viewports property of the sim3d.World object.

    Name-Value Arguments

    Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

    Example: createViewport(world,Name='View1',Translation=[1 2 3])

    Name of viewport, specified as a character array or string. If you do not specify the name, then the software assigns the viewport an autogenerated name, Viewport1 and so on. Use this argument to set the field name of the viewport in the viewport structure.

    Note

    If you specify the same name as the viewport that already exists, then the software appends viewport name you specify with a unique identifier.

    Example: Name="View1"

    Relative translation (x,y,z) of the viewport to the Scene Origin at (0,0,0), specified as a real 1-by-3 vector, in m. Use Translation to change the position of the viewport in the 3D environment along the X, Y, and Z axes of the coordinate system.

    Example: Translation=[3 4 3]

    Data Types: double

    Relative rotation (roll, pitch, yaw) of the viewport to the Scene Origin at (0,0,0), specified as a real 1-by-3 vector, in rad. Use Rotation to rotate the viewport in the 3D environment.

    Example: Rotation=[0 pi/2 pi/4]

    Data Types: double

    Version History

    Introduced in R2022b

    expand all