setView
Syntax
Description
Examples
Create a custom view of the 3D environment using the createViewpoint function. Use the setView function to set the view in the Simulation 3D Viewer window.
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 custom view using the createViewpoint function.
view = createViewpoint(world);
view.Name = 'View';
view.Translation = [-4 0 0];Set the view of the 3D environment to display in the Simulation 3D Viewer window. If you do not set the view, the software sets the default view.
setView(world,view);
Run the simulation.
sampletime = 0.01; stoptime = 10; run(world,sampletime,stoptime);

Create multiple views of the 3D environment using the createViewpoint function. Use the setView function to set the view in the Simulation 3D Viewer window.
Create a world object using the sim3d.World object.
world = sim3d.World(Output=@outputImpl);
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 multiple custom views using the createViewpoint function.
view1 = createViewpoint( ... world,Name='Front',Translation=[-4 0 0]); view2 = createViewpoint( ... world,Name='Right',Translation=[0 4 0],Rotation=[0 0 -pi/2]); view3 = createViewpoint( ... world,Name='Back',Translation=[4 0 0],Rotation=[0 0 pi]); view4 = createViewpoint( ... world,Name='Left',Translation=[0 -4 0],Rotation=[0 0 pi/2]);
Using the UserData property of the sim3d.World object, create a user data structure with a field named Step to store the simulation step during simulation.
world.UserData.Step = 1;
Run the simulation. The viewer displays the default view.
sampletime = 0.01; stoptime = 10; run(world,sampletime,stoptime);

Output Function
Use the output function to set the view in the Simulation 3D Viewer window at a specific simulation step. The Front and Back views display a square. The Right and Left views display a rectangle.
function outputImpl(world) if world.UserData.Step == 200 setView(world,world.Viewpoints.Front); elseif world.UserData.Step == 400 setView(world,world.Viewpoints.Right); elseif world.UserData.Step == 600 setView(world,world.Viewpoints.Back); elseif world.UserData.Step == 800 setView(world,world.Viewpoints.Left); end world.UserData.Step = world.UserData.Step + 1; end
Input Arguments
World object that defines the 3D environment, specified as a sim3d.World
object.
Example: world = sim3d.World()
Viewpoint object that defines the viewpoint created using the createViewpoint function, specified as a Viewpoint
object. The Viewpoint object is stored as a field in the viewpoint
structure. You can use the Viewpoints property of the sim3d.World
class to access the Viewpoint object. You can also modify the aspects
of the viewpoint object by setting values for the Name,
Translation, and Rotation
properties.
Example: viewpoint = View1
Version History
Introduced in R2024b
See Also
createViewpoint | deleteViewpoint | add | run | remove | load | pause | resume | close
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)