| Transform
and Coordinate Spaces
Cartesian coordinates are used to define locations
in VRML Scenes. X and Y coordinate values place the object in its
screen location, and the Z value specifies the proximity to the
front of the screen. A world coordinate system is used, and once
the initial image is rendered all further coordinates use this as
the origin for future coordinate specifications. For the cube shown
in figure 1 this would work like this:

Figure 3. World coordinate system.
A Transform
creates a coordinate system that is:
· Positioned
· Rotated
· Scaled (relative to a parent coordinate system)
Shapes
built in the new coordinate system are positioned, rotated, and
scaled along with it.
The Transform node allows objects to be placed with respect to specified
locations that relate to the origin. If no parent/children relationships
are established, this transformation relates to the original origin
of a VRML scene. If a parent/children relationship is established
the translation of a child is related to the origin of the parent.
A Transform
group node controls:
·
translation - position
· rotation - orientation
· scale - size
Transform
{
translation . . .
rotation . . .
scale . . .
children [ . . . ]
}
Translation positions a coordinate system in X, Y, and Z
Transform {
# X Y Z
translation 2.0 0.0 0.0
children [ . . . ]
}
Go
back and view the original file discussed previously to draw a green
cone.
Using
your Web browser view the cone and note its location on the screen.
Alter
the code for the green cone to move the object 5 metres to the right
from its default (x=0, y=0, z=0, or world origin). To re-locate
it the Shape node is placed into a Transform node and then translate
the Shape node to the required location.
Save
the file as movedcone.wrl
#VRML V2.0 utf8
#Draws green cone moved 5 metres to the right
Transform {
translation 5 0 0
children Shape {
appearance Appearance {
material Material {
diffuseColor 0 1 0
}
}
geometry Cone { }
}
}
The
translation field moves the children 5 units (metres) to the right
(x-axis) and zero units in the y- and z-directions. The Transform
node is similar to the Group node with the difference of their translation,
scale, and rotation fields. The translation should now be visible
between the two
Cones.
Note:
brackets were not necessary to enclose the contents of the children
field, as there was only one child in the list. If more than one
child is ‘grouped’ by brackets the transformation would
apply to them all.
|