3d Transformations

From BZFlagWiki
Jump to: navigation, search

The following is ©Petteri Aimonen 2005, Used by permission.


In version 1.10.8 and older bzflag, objects position, rotation and size where defined by, logically, position, rotation and size keywords. When 2.0 introduced 3d rotation, this had to change. Position and rotation have been obsoleted by their superiors, shift and spin. Size could be replaced with scale, but there is no need for that on traditional objects (mesh are a bit different). All keywords are order-specific. If you do shift before spin, it will still spin the object around 0 0 0, moving it somewhere else than where it was meant to be.

 position 50 100 0
 size 20 20 5
 rotation 45

can now be written:

 size 20 20 5
 spin 45 0 0 1
 shift 50 100 0


Spin can be used to rotate object around a specific axis. Axis is a line, defined by two points. First value after spin-keyword is rotation in degrees. The other three values determine which axis the spin will be applied. It is usually simple to think rotation around the standard axises. You can spin around any axis, diagonal or anything. Anyway, all rotations can be made by rotating around standard axises, and they are usually most simple to think of.

X-axis eg. spin 45 1 0 0 
Y-axis eg. spin 45 0 1 0 
Z-axis, normal rotation, eg. spin 45 0 0 1

alt text alt text


Shifting means moving the object. It is used in same manner as old position-keyword. Without position-keyword, object is placed around 0 0 0. When shift moves it from origin, coordinates are just like with position. However, shift is repeatable, and sequential moves will use last point as origin.

alt text


Shearing is "a deformation of an object in which parallel planes remain parallel but are shifted in a direction parallel to themselves." If you don't understand, look at the image below. The three values after shear-keyword define a vector. Vectors length represents change per Z-axis unit. If you have 10 unit high meshbox, and shear it by 1 0 0, top will move 10 * 1 away from the bottom in X-axis direction. In next example, we use shear to make an escalator with nice ends.

 name escalator
 linear 15 0 15
 size 10 10 100
 shear 2 0 0
 phydrv escalator
 size 10 10 10
 shear 1 0 0

alt text