Rotation enables you to do things like make a wheel from a Cylinder, make a funnel from a Cone, balance a Box on a corner, and so on. The Transform node is a grouping node, and has both rotation and center attributes for you to use.
Remember that xVRML uses a right-handed coordinate system, and that 3D has
3 axes (X and Y and Z).
Positions are specified by distances
along these three axes, and expressed through the translation attribute
of the Transform node. In the same fashion, orientations of objects can be
specified by using the rotation attribute of the Transform node.
The process of figuring out how a rotation will effect the objects in the
Transform group is similar to the process of figuring out the results of
a translation.
The axis of rotation (the imaginary line around which rotations happen) can re-orient the Transform group children to point in any direction. You specify the rotation value as four (4) floating-point numbers. These specify (in left-to-right order): the X-axis, Y-axis, and Z-axis settings and the number of radians to rotate around the axis/axes specified.
People often use more than one nested Transform node, and apply one rotation axis at a time to avoid confusion over which rotation happens first (X, or Y, or Z). Remember that Pi (approximately 3.14159) is 180 degrees (180°). Some commonly-used values include 1.57 (about 90°), 0.785 (about 45°), 0.524 (about 30°), and 0.175 (about 10°).
Remember, you can use the translation and rotation attributes of the same Transform node at the same time. Experiment with doing these within one Transform node, and you will be able to see the effects of doing both at once.
The center around which things rotate is the origin within that coordinate system. The origin of a particular Transform starts out being the center of the coordinate system inherited from the node's parents. The origin can be changed as much as you wish through the use of the center attribute of the Transform node. This attribute tells the system where to set the rotation center for the nodes enclosed in that Transform node. For example, you might want to rotate a robot arm around some center offset from the "natural center" of the entire robot object. This is how to make doors open properly, arms to swing properly, and so on.
A simple file with a red Cylinder might look like this:
<?xml version="1.0" encoding="UTF-8"?>
<World xmlns="http://www.xvrml.net/schemas/core"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.xvrml.net/schemas/core
http://www.xvrml.net/schemas/xVRML.xsd"
headlight="true">
<children>
<Shape name="basic">
<appearance>
<Material>
<emissiveColor red="1.0"/>
</Material>
</appearance>
<geometry>
<Cylinder/>
</geometry>
</Shape>
</children>
</World>
So, what would it look like to have a second copy of that Cylinder present,
but moved to our right by 5 meters and rotated around the positive Z axis by 90°
in the scene?
<?xml version="1.0" encoding="UTF-8"?>
<World xmlns="http://www.xvrml.net/schemas/core"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.xvrml.net/schemas/core
http://www.xvrml.net/schemas/xVRML.xsd"
headlight="true">
<children>
<Shape name="basic">
<appearance>
<Material>
<emissiveColor red="1.0"/>
</Material>
</appearance>
<geometry>
<Cylinder/>
</geometry>
</Shape>
<Transform translation="5.0 0.0 0.0"
rotation="0.0 0.0 1.0 1.57">
<children>
<Use target="basic"/>
</children>
</Transform>
</children>
</World>
Notice how the second object is now rotated 90° about the Z axis.
See if you can use your right hand to demonstrate to yourself what is happening.
We want to rotate around the Z axis, so you point your right thumb at yourself
(pointing down the positive Z axis) with your right fingers curling to the left
and you will see how the rotation follows the curve of your fingers. This should
look a lot like the picture we saw above. The thumb of your right hand is pointing down
the axis you wish to rotate around, and it is aimed in the positive direction for
that axis as we wish to rotate around. Positive rotation around the Z axis will
follow the curve of your fingers, and negative rotation would be in the direction
opposite the curve of your fingers.
You should try this out, until you are certain you understand how to visualize how rotation works. It is only if you can visualize the effects of your work that you are able to get reasonably fast at creating things and assembling them into more complex objects and scenes using the rotation and translation and center attributes
Create the base and arm and other parts of a desk lamp, using just the rotation
and translation and center attributes to turn the arms into realistic positions.
Here is an example of what a beginning to this desk-lamp assignment might look like the
picture to the right. Notice the use of the rotation and translation
and center attributes in the following code which makes the picture look
the way it does. Notice especially the combination of the rotation
and translation and center attributes. As you look at the code and the image
below, see if you can extract a generic idea about using rotation and translation
and center attributes together to get something into the right place.
Why the offsetting Y-axis entries for the translation and center attributes?
<?xml version="1.0" encoding="UTF-8"?>
<World xmlns="http://www.xvrml.net/schemas/core"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.xvrml.net/schemas/core
http://www.xvrml.net/schemas/xVRML.xsd">
<children>
<Group name="lampBase">
<children>
<Shape>
<appearance name="white">
<Material>
<emissiveColor red="1.0" green="1.0" blue="1.0"/>
</Material>
</appearance>
<geometry>
<Cylinder radius="0.1" height="0.01"/>
</geometry>
</Shape>
<Transform translation="0.0 0.15 0.0"
rotation="1.0 0.0 0.0 -0.7"
center="0.0 -0.15 0.0">
<children>
<Shape>
<appearance name="red">
<Material>
<emissiveColor red="1.0" green="0.3" blue="0.3"/>
</Material>
</appearance>
<geometry>
<Cylinder radius="0.01" height="0.3"/>
</geometry>
</Shape>
</children>
</Transform>
</children>
</Group>
</children>
</World>