Virtual Reality Toolbox    

Interacting with a Virtual World

In the life cycle of a vrworld object you can set new values for all the available virtual world nodes and their fields using vrnode object methods. This way, you can change and control the degrees of freedom for the virtual world from within the MATLAB environment.

An object of type vrworld contains nodes named in the VRML file using the DEF statement. These nodes are of type vrnode. For more information, see vrworld Object Reference and vrnode Object Reference for the full description of these objects.

After you open a vrworld object, you can get a list of available nodes in the virtual world. This procedure uses the vrworld object myworld and the virtual world vrmount.wrl as an example:

  1. In the MATLAB Command Window, type
  1. MATLAB displays a list of the vrnode objects and their fields that are accessible from the Virtual Reality Toolbox.

  1. Type
  1. MATLAB creates an array of vrnode objects corresponding to the virtual world nodes and displays

  1. Type
  1. MATLAB displays the messages

    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 Automobile, which is the fourth node in the virtual world.

  1. Access the fields of the Automobile node by typing
  1. or

    Note that dot notation is the preferred method for accessing the nodes of the vrworld object myworld.

    MATLAB displays the following table.

    The Automobile node is of type Transform. This VRML node allows you to change its position by changing its translation field values. From the list, you can see that translation requires three values, representing the [x y z] coordinates of the object.

  1. Type
  1. Your default viewer opens and displays the virtual world vrmount.wrl.

  1. Move the MATLAB window and the browser window side by side so you can view both at the same time. In the MATLAB Command Window, type
  1. MATLAB sets a new position for the Automobile node, and you can observe that the car is repositioned in the VRML browser window.

It is possible to change the node fields listed by using the function vrnode/setfield.


  Opening a Virtual World Closing and Deleting a vrworld Object