In my last post I talked about the functions available to rez objects inworld, llRezObject and llRezAtRoot. In this post I’ll look a little further at one of their parameters and in doing so also look at the creation of a user-defined function.
The parameters for these functions, already decribed in the previous post, are as follows:
(string inventory, vector position, vector velocity, rotation rot, integer param)
As inventory and position have already been covered and velocity is not likely to be a factor in a holodeck, the next parameter to be considered is the rotation (rot) of the rezzed object. I will cover param in the next post and velocity later on in a slightly different context but for the purposes of this post both will continue to be set to zero.
As discussed in Adjusting Teleporter Rotations, a rotation in Second Life (and OpenSim) is not written in LSL (Linden Scripting Language) using the X, Y and Z degrees of rotation seen in the Build window. The degrees must first be converted to radians then the resulting euler vector converted to a quaternion rotation. LSL supplies the functions to achieve this but, because each rezzed part of a holodeck scene (and there may be many) will require its own rotation, the code can end up with the required functions being written repetitively for each object to be rezzed. This is where creating a user-defined function can be useful as the repetitive parts of the code can be written once with only the variable factor, the rotation in degrees, being changed as required.
In the first instance a user-defined function must have its data type set. For this particular function the data we want returned is a rotation so that will be the function’s return type. Then the function needs a name, preferably one that tells us what the function is doing; for this one I’m going to give it the name degrees2Rot. Then the function requires its parameters to be set; in this case there is only one; a vector that details the X, Y and Z degrees that the function will be coverting to a rotation, which I will call degreesXYZ. After this comes the function statements comprising the code that will convert the parameter degreesXYZ into a rotation. This rotation is then returned (i.e. given out) by the function. The code block below shows how this is written.
rotation degrees2Rot(vector degreesXYZ) // The data type set, the function named and the parameter set and named
vector rotRadians = degreesXYZ * DEG_TO_RAD; // The degrees converted to radians (euler vector)
rotation rezzedRot = llEuler2Rot(rotRadians); // The euler vector converted to a rotation
return rezzedRot; // The degrees expressed as a rotation returned by the function
Note: The comments, i.e. the statements after the double forward slashes, can be removed from the final script (from the // onwards).
The following shows this function used in the script from the post From Rezzer to Holodeck, the rezzing activated by touching the prim. It rezzes two instances of the object rezTest at the same position as the rezzing prim (using llGetPos()) with their rotations set to 135° on the Z axis, and 270° on the Y axis respectively.
rotation degrees2Rot(vector degreesXYZ)
vector rotRadians = degreesXYZ * DEG_TO_RAD;
rotation rezzedRot = llEuler2Rot(rotRadians);
llRezAtRoot(“rezTest“, llGetPos(), <0.0, 0.0, 0.0>, degrees2Rot(<0.0, 0.0, 135.0>), 0);
llRezAtRoot(“rezTest“, llGetPos(), <0.0, 0.0, 0.0>, degrees2Rot(<0.0, 270.0, 0.0>), 0);
The image below shows the resulting rezzed objects rotated at the required amounts, relative to the sim axes. Note: The degrees shown on the platform (which is aligned with the sim) are degrees of positive rotation around the Z axis.
As can be seen a user-defined function is very useful in this instance as multiple objects can have the degrees to rotation conversion applied without repetitively writing the functions required for the conversion. Just the user-defined function name and its variable, the required X, Y and Z degrees, need be included for the llRezAtRoot rotation parameter.
The next post to follow in this series will look at the last parameter of the rez object functions, an integer, and will demonstrate how it can be used to set a timer for deleting rezzed objects.
Note: To receive email updates of further posts in this or other series on this blog you can follow the blog. If you are a WordPress user you can login and click on the Follow button at the top left of the post page. Otherwise click on the Follow button in the sidebar to receive email notifications of posts.
Next in this Series: Setting a Rezzed Object Timer