User Guide
66
Creating effects with JavaScript
Transforming objects
The Vector, Rotation, and Transform modules provide methods and properties for trans-
forming subworlds and imported Viewpoint objects. You can use the Vector module to
move (translate) objects, the Rotation module to rotate objects, and the Transform
module to translate and rotate objects at the same time. For example, you can write a
script that rotates a subworld around its y axis while moving the subworld to a different
position in the world. Vector, Rotation, and Transform objects are values which you can
query as well as apply, so they are useful for finding the current position or orientation of
a subworld or Viewpoint object.
There is an important distinction between setting a position and orientation directly and
using the moveTo() and rotateTo() functions. When setting the position variables the
change happens at that time, and discontinuously. This is good for setting up the initial
position of an object in a scene when it is loaded.
It is important to provide smooth motions between frames for the collisions to be
computed correctly. This is achieved in the system using moveTo() and rotateTo() which
smoothly transform the object between frames allowing for correct collisions with other
objects in the scene. A moveTo() function schedules an update of the position but does not
do the change at that time. For this reason the updated position can only be read-back
during the next time step.
For example, the following code changes the position and orientation of a subworld
named “table”:
// Set the position the first time
// Same as table.setPosition(30.0, 2.0, 0.0);
table.position = Vector (30.0, 2.0, 0.0);
table.orientation =Rotation('Y', firstAngle); // Rotate about the y axis
// From now on any position changes for table will collide with
// other objects and other objects will collide with it
table.collide = 3;
// Now schedule the smooth transition during the next time step
table.moveTo(Vector(31.0, 2.0, 0.0));
table.rotateTo(Rotation('Y', secondAngle));
For more information on the Transform, Vector, and Rotation modules, see the
Atmosphere JavaScript API documentation.
atmosphere.book Page 66 Wednesday, March 21, 2001 6:14 PM










