Second Life Rezzing and Rotating

by Bill Magee, Ph.D.

Recently I built a demonstration in Second Life modeling Vasubandhu's refutation of partless particles (which also implicitly refutes external objects). The demonstration is fairly straightforward and the code is simple, except for one aspect we shall discuss here.

The demonstration involves a wall of text explaining each of Vasubandhu's points, and a cube I shall call "parent" which contains a number of other cubes. These other cubes are to be rezzed into various position around the parent ("rez" is SL-speak for "created"). Here is a picture of the parent:

As long as the rotation of the parent is 0,0,0 around the x,y,z axes of Second Life, it is a simple matter to rez the other cubes into position. The code looks like this:

llRezObject("test", llGetPos() + <0, .5, 0>, ZERO_VECTOR,llGetRot(), 0);

As you can see, this line of code places an object .5 meters along the y axis of the parent. llGetPos() returns the position of the parent, and the .5 bumps the rezzed cube along the y axis half a meter. llGetRot() towards the end of the line informs the rezzed cube of the rotation of the parent, which in this case is <0,0,0>. Other lines of code place the other objects into position around the parent with similar lines of code. Step 5 in the demonstration has all the cubes arrayed in a straight line to one side of the parent. It looks like this:

As long as the parent is not rotated, this works fine. But a problem occurs if the cube is rotated: for instance, 30 degrees around the y axis like this:

The problem is that the other cubes do not know how to line up on the new y axis of the parent, and so they simply line up on the y axis of Second Life. The result is unpleasant:

In order for the other cubes to line up correctly along the new y axis, the code must multiply the positional vector of their new position by the rotational vector of the parent's rotation. (My friend Louis remarks that the math works because LSL allows one to multiply a vector X (which represents a position in space) with a rotation Y (also called a quaternion). LSL interprets such multiplication as "rotate X by Y". Louis thinks this ability is peculiar to LSL.) The code looks like this:

llRezObject("test", llGetPos() + <0, .5, 0> * llGetRot(), ZERO_VECTOR,llGetRot(), 0);

Notice the new function llGetRot() that has been added to the original line of code. This function returns a vector reflecting the rotation of the parent (in this case <0,30,0>). It is multiplied by the position of the rezzed cube to yeild a new position along the x and y axes. The second llGetRot() in the line, as before, informs the rezzed cube of the rotation of the parent, so it can mimic that. The result looks good:

You can see the Vasubandhu demonstration in Second Life at Catocala (172,112,600). Enjoy your Second Life!