
![]()
|
Rotating Your ChildrenThe first installment of the series on the Transform node talked about using it to create new coordinate systems. Using the node, you could then add children to the system, and manipulate their position in the overall world as you pleased.This tutorial takes that one step further, covering another way to manipulate your objects: by rotating them. Rotation comes in lots of different varieties, including pivoting and rotation around a center point. Rotating things still falls within the same guidelines. You're still going to create a new coordinate system by using the highly-famed Transform node, put some objects in it with the help of the children field, and finally use another field, rotation, to do the desired task. So let's get right into it. Rotation Axes, Right Hands, and RadiansFirst off, let's take another look at the Transform node, without the fields we won't be using when rotating:
Transform {
children [] # We'll be putting the objects we want to rotate in here
rotation 0.0 0.0 0.0 0.0 # Where the main action happens
center 0.0 0.0 0.0 # Used in situations where you want to pivot
}
A good place to start is with the rotation axis, the imaginary line about which a coordinate system is rotated. For example, the earth rotates around its own axis. Go a step further and you could call it the earth's rotation axis. Let's say for just a moment that the earth's rotation axis is perfectly vertical (implying that in real life it's tilted, far from vertical, in fact). Now we need to apply this to the Transform node's rotation field.
The first three values are coordinates--that's right, your basic X, Y, Z coordinates. Those define to which direction the rotation axis will be pointing. Imagine that there is a point at the very center of that newly-created coordinate system. Now imagine another point at the coordinates that you'll put into the
Since the earth's rotation axis is pointing perfectly upwards, the axis that deals with vertical measurements has to be changed (hint: Y). So, all that's need is the second coordinate from above: insert
The fourth value of the A common way to remember this is the right-hand rule. To use it, imagine wrapping your right hand around a particular axis so that your thumb points in the positive direction. If you wrap your hand around the Y axis, for example, your thumb would be pointing upwards. The direction in which your fingers wrap around the axis is the positive direction, and the radian measure would rotate the coordinate system a certain distance in that direction. You could also insert negative radian measures, where the coordinate system would be rotated in the opposite direction as with a positive radian measure. Let's Rotate Some Stuff!Here's a relatively simple example to show off rotation:
The resulting world displays a cylinder tilted to the left by forty-five degrees. If you put in a different value for the Z axis, you'll get the same result, as explained before:
PivotingYou can also accomplish pivoting by using theTransform node's center field. When you define a point as a value for the center field, all rotation will be directed from that point alone, and the rotation will no longer be performed from the center of the object, like we were doing. It's useful for manipulating fixed shapes.The code below generates a world where two cylinders are centered around a single point. Because of that, they intersect:
And there you have it. Yet another mystery of the
|