Main Content

Interact with a Virtual World withMATLAB

设置节点的值

In the life cycle of avrworld目的you can set new values for all the available virtual world nodes and their fields usingvrnode对象方法。这样,您可以从MATLAB内部改变和控制虚拟世界的自由度®环境。

An object of typevrworld包含使用DEF语句中虚拟世界3D文件中命名的节点。这些节点类型vrnode。有关更多信息,请参阅vrworldandvrnodefunctions.

打开后vrworld目的,,,,you can get a list of available nodes in the virtual world. This procedure uses thevrworld目的我的世界and the virtual worldvrmount.x3d举个例子。创建我的世界, 看Create vrworld Object for a Virtual World

  1. 在MATLAB命令窗口中,键入

    节点(myworld);

    这MATLABCommand Window displays a list of thevrnode目的s and their fields that are accessible from the金宝app®3D Animation™软件。

    Tunnel (Transform) [My first virtual world] Road (Shape) [My first virtual world] Bridge (Shape) [My first virtual world] River (Shape) [My first virtual world] ElevApp (Appearance) [My first virtual world] Canal (Shape) [My first virtual world] Wood (Group) [My first virtual world] Tree1 (Group) [My first virtual world] Wheel (Shape) [My first virtual world] Automobile (Transform) [My first virtual world] VPfollow (Viewpoint) [My first virtual world] Camera_car (Transform) [My first virtual world] View1 (Viewpoint) [My first virtual world]
  2. Type

    mynodes = get(myworld,'nodes')

    MATLAB软件创建了一个数组vrnode目的s corresponding to the virtual world nodes and displays

    mynodes = vrnode对象:13-by-1隧道(转换)[我的第一个虚拟世界]路(Shape)[我的第一个虚拟世界]桥(Shape)[我的第一个虚拟世界]河(Shape)[我的第一个虚拟世界]leverapp(外观)[我的第一个虚拟世界]运河(形状)[我的第一个虚拟世界]木材(group)[我的第一个虚拟世界] tree1(group)[我的第一个虚拟世界]轮子(Shape)[我的第一个虚拟世界]汽车(转换)[我的第一个虚拟世界] vpfollow(viewpoint)[我的第一个虚拟世界] camera_car(transform)[我的第一个虚拟世界] view1(viewpoint)[我的第一个虚拟世界]
  3. Type

    谁是

    MATLAB命令窗口显示消息

    Name Size Bytes Class ans 1x1 132 vrfigure object mynodes 13x1 3564 vrnode object myworld 1x1 132 vrworld object

    Now you can get node characteristics and set new values for certain node properties. For example, you can change the position of the automobile by using汽车,,,,这是虚拟世界中的第四个节点。

  4. 访问汽车通过键入节点

    字段(myworld.automobile)

    or

    fields(mynodes(10));

    MATLAB命令窗口显示有关汽车节点。

    现场访问类型同步----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- addChildren eventIn MFNode off removeChildren eventIn MFNode off children exposedField MFNode off center exposedField SFVec3f off rotation exposedField SFRotation off scale exposedField SFVec3f off scaleOrientation exposedField SFRotation off translation exposedField SFVec3f off bboxCenter field SFVec3f off bboxSize现场SFVEC3F关闭

    汽车节点是类型Transform。该节点使您可以通过更改其位置来改变其位置翻译字段值。从列表中,您可以看到翻译需要三个值,代表对象的[x y z]坐标。

  5. Type

    查看(myworld)

    您的默认查看器打开并显示虚拟世界vrmount.x3d

  6. 并排移动MATLAB窗口和浏览器窗口,以便同时查看。在MATLAB命令窗口中,键入

    myworld.automobile.translation = [15 0.25 20];

    MATLAB为汽车节点。您可以观察到汽车在虚拟世界浏览器窗口中重新定位。

You can change the node fields listed by using the functionvrnode/setfield

笔记

点符号是访问节点的首选方法。

Read Sensor Values Using MATLAB

读取可读字段的值(要么裸露的菲尔德orEventOut), first synchronize that field with theVRNODE/SYNCmethod. After synchronization, each time the field changes in the scene, the field value updates on the host. You can then read the value of the field with thevrnode/getfieldmethod or directly access the field value using dot notation.

这virtual scene for the磁悬浮模型example,maglev.x3d,包含一个planesensor(带有DEF姓名'Grab_Sensor'). The PlaneSensor is attached to the ball geometry to register your attempts to move the ball up or down when grabbing it using the mouse. The example uses the sensor fieldsminpositionand最大值限制运动朝其他方向限制。您可以将传感器翻译字段的输出用作球位置控制器的新设定点。您可以将传感器输出值读取到MATLAB变量设定点中。

  1. Create the vrworld object and open the world.

    wh = vrworld('maglev.x3d');打开(WH);
  2. Get the node handle.

    nh = vrnode(wh,'Grab_Sensor');
  3. 同步翻译字段。

    sync(nh,'translation',,,,'上');
  4. 使用以下三个替代方案之一读取同步字段值:

    setpoint = getfield(nh,'translation');setPoint = nh.translation;setPoint = wh.grab_sensor.translation;

Global Coordinates for Rotation and Translation

旋转和翻译值Transform目的are specified in local coordinates, relative to the parent object of the object.Simulink 3D Animationprovides two extensions for converting rotation and translation values into global coordinates:rotation_absandtranslation_abs。要访问这些全局坐标,请在翻译或旋转字段中使用点符号,添加_absto the field name. This example shows the difference between the local and global coordinates for translation:

w = vrview('vrmanipul.x3d');n = get(w,“节点”);n = w.Grip_Reference; n.translation n.translation_abs
ans 0 ans = -3.0406 -3.0000 2.3334 -0.1000 = 0

也可以看看

功能

Related Topics