Part 2: Hierarchical Motion Explained
Moving Along
 More of this Feature
• Part 1: Building a Solar System
 
 Join The Discussion
"...truly scaleable to the dynamic bandwidth availability?"
MORAB2
 
 Related Resources
• Tutorials
• FAQs
 
 From Other Guides
• Real Space Stuff
• Astronomy for Kids
• What is XHTML and XML?
 
 Elsewhere On The Web
• VRML Repository
• 3DEZine
 

In order to get the Earth to move we need to wire up the clock to the interpolator to the rotation. Speaking in VRML terms this means create a ROUTE from the TimeSensor to the OrientationInterpolator to the Transform Node.

The OrientationInterpolator specified a vector which is a direction around which to rotate. Our interpolator looks like:

DEF	EarthOrbit OrientationInterpolator {
	key	[0.0, 0.5, 1.0]
	keyValue [
		0.0 1.0 0.0 0.0,
		0.0 1.0 0.0 3.14,
		0.0 1.0 0.0 6.28
	]
}

Note that there are three key's and therefore there are three keyValues. The first three values specify a rotation axis. The 0 1 0 specifies an axis pointing up in the Y direction. The fourth value is the amount of rotation, which is expressed in radians. For radians 2pi = 6.28 which is equal to 360 degrees.

If we ROUTE the OrientationInterpolator to the Transform that controls the Earth what happens? The WRONG thing, the Earth simply spins on it's own axis, it doesn't rotate around the Sun. This is because the we haven't specified the correct Transformation hierarchy, the correct order of operations.

We need to create a sequence whereby the Earth is rotated and then translated (positioned) out to the correct orbit. We can do this by adding an extra Transformation. This looks like:

DEF Earth Transform {
	translation	0 0 0
	children [
		 Transform {
			translation	10 0 0
			children
				Shape {
					appearance Appearance {
					material Material {
						diffuseColor 0 0.7 0
					}
					}
				geometry Sphere	{ radius 0.5 }
				}
		}
	]
}

The main new concept here is the use of the children field to add an additional Transform node. The children field of the Transform Node let's you add an unlimited number of Nodes of any type. Those new nodes are going to be affected by the Transform that hold them. Since we need to apply the rotation first we ROUTE the rotation changes to the rotation field of the outer Transform. The complete file looks like:

#VRML V2.0 utf8

DEF Sun Transform {
	children Shape {
		appearance Appearance {
			material Material {
				diffuseColor 0.7 0.7 0
			}
		}
		geometry Sphere	{ radius 1.0 }
	}
}


 DEF Earth Transform {
	translation	0 0 0
	children [
		 Transform {
			translation	10 0 0
			children
				Shape {
					appearance Appearance {
					material Material {
						diffuseColor 0 0.7 0
					}
					}
				geometry Sphere	{ radius 0.5 }
				}
		}
	]
}


DEF	Year TimeSensor {
	cycleInterval 12
	loop TRUE 
}


DEF	EarthOrbit OrientationInterpolator {
	key	[0.0, 0.5, 1.0]
	keyValue [
		0.0 1.0 0.0 0.0,
		0.0 1.0 0.0 3.14,
		0.0 1.0 0.0 6.28
	]
}

	ROUTE Year.fraction_changed TO EarthOrbit.set_fraction
	ROUTE EarthOrbit.value_changed TO Earth.set_rotation

You can look at it in action at 101800a.wrl.

Let's repeat the process one more time and add the Moon. We create another clock which we'll call month and another OrientationInterpolator called MoonOrbit. This time we have to be careful to nest the Moon inside the Transform of the Earth so that as the Earth travels the Moon goes along for the ride. In addition we use the Month clock to cause the Moon to rotate again inside nested Transforms, causing it to rotate around the Earth.

The main part of the file looks like:

DEF Earth Transform {
	translation	0 0 0
	children [
		 DEF Moon Transform {
			translation	10 0 0
			children  [
				Shape {
					appearance Appearance {
					material Material {
						diffuseColor 0 0.7 0
					}
					}
				geometry Sphere	{ radius 0.5 }
				},
				 Transform {
					translation	1 0 0
					children Shape {
						appearance Appearance {
						material Material {
							diffuseColor 0.7 0.7 0.7
						}
						}
					geometry Sphere	{ radius 0.3 }
					}
				}

			]
		},

	]
}

You can play with this file live at 101800b.wrl.

In a few weeks let's look at how this type of hierarchical motion is used to create human type bodies, stay tuned!

ZZZNEWSLETTERSIGNUP1ZZZ
[Tutorials] [Web3D Technology Comparison] [Virtual Humans]
[Virtual Reality] [Art] [People of Web3D]
[Panoramic Imaging] [FAQs] [Companies]

Previous page > Building a Solar System > Page 1, 2