Main Content

createViewport

Create viewport for world

Since R2022b

    Description

    example

    createViewport(world) creates a viewport with a single field, Main that contains a sim3d.sensors.MainCamera object.

    If you do not create a viewport, then the point of view is set to 0, 0 ,0, and you can use the arrow keys and pointer to navigate in the game.

    Examples

    collapse all

    This example shows how to create a 3D environment with an empty actor and view in the Simulation 3D Viewer window using MATLAB®. You can use the sim3d.World to create a world object and sim3d.Actor to create an empty actor object. You can then add the actor to the 3D environment and visualize the 3D environment in the Simulation 3D Viewer window. For an example that shows how to create a 3D environment with an actor using Simulink®, see Create World and Actor Using Simulink.

    This process does not build an appearance for the actor, so the Simulation 3D Viewer does not render a visualization of the actor. For an example that shows how to build an appearance for an empty actor, see Build Actor from 3D Graphic Primitives Using MATLAB.

    Create World

    Create a world object.

    world = sim3d.World();

    Create Actor

    Add an actor to the world.

    add(world,sim3d.Actor());

    Run Simulation

    Run a simulation set for 10 seconds with a sample time of 0.02 seconds.

    run(world,0.02,10)

    Empty virtual world scene

    Delete World

    Delete the world object.

    delete(world);

    Input Arguments

    collapse all

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

    Version History

    Introduced in R2022b