Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Rezzing and positioning a door regardless of angle?

Soen Eber
Registered User
Join date: 3 Aug 2006
Posts: 428
01-03-2007 05:50
I'm working on a house which has a control/aunthetication script in a control box next to where the door will be. One of its functions will be to rez and align the door, regardless of how the house (and the linked control box) is rotated.

Rotations have always been scary for me, despite being a half-competent scripter - so my question is which functions would I need to pay attention to, and what kind of math would I need to perform to calculate the correct position and rotation.

Once I'm done with this I'll post the code to the scripting library,and the house (sized for a 512 lot with scripted doors/windows/basic security/autorezzed furniture & stairs) will be offered to the gnubie store - thanks in advance!.
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
01-04-2007 01:16
llGetRot and llSetRot
Soen Eber
Registered User
Join date: 3 Aug 2006
Posts: 428
01-04-2007 05:37
Right. I got that. Thankyou very much.

But what's driving me up the wall right now is the old x and y bit, as in "I want this door to rez 2 meters to the right, regardless of what direction the house is oriented. The rezzed object has to pivot around the rezzing control unit. It's easy to figure out that if the rezzer is at 45 degress, the door will have to be oriented 45 degrees, but where do I place the properly rotated door?

I should be able to do some sine and cosine magic, but it seems all the formulas I've seen work with some permutation of multiplying, dividing, adding, and subtracting vectors and rotations, so that's what I'm really looking for.

Given:
control unit position
control unit rotation
Solve for:
door position, when door must be aligned with the control unit and 2 meters to the right of its fromt facing.
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
01-04-2007 06:12
You multiply the position offset by the building's rotation.

CODE

vector Offset = < 0, 2, 0 >;
rotation rot = llGetRot();
vector pos = llGetPos() + ( Offset * rot );
llRezObject("Door", pos , ZERO_VECTOR, rot ,InitVariable);
Soen Eber
Registered User
Join date: 3 Aug 2006
Posts: 428
01-06-2007 05:53
Thank you very much! It worked.

I'm getting the impression that the rotation is actually a place holder for unitized trigometric constants which are then applied to the vector scalar components ... interesting. I suppose once you get used to it its a lot easier then normal trig.
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
01-06-2007 07:43
From: Soen Eber
Thank you very much! It worked.

I'm getting the impression that the rotation is actually a place holder for unitized trigometric constants which are then applied to the vector scalar components ... interesting. I suppose once you get used to it its a lot easier then normal trig.



LSL uses quaternions to represent rotations.
Soen Eber
Registered User
Join date: 3 Aug 2006
Posts: 428
01-06-2007 18:37
OK, a related issue.

Everything was working great until I rotated the house and tried rezzing the door again, and now the door is out of alignment.

Further experimenting shows that this will happen when trying to rez an object set, its apparently funky about determing where the rez point will be in such an instance.

As an experiment, put the following into a .5 x .5 x .5 sphere raised 2 or 3 meters off the ground, and drop an object named "Object" in there which are a linked sphere and cube. You will see that the rezzed objects seem to define a geometric center which is different from the rezzing object:

CODE

default
{
state_entry()
{
}
touch_start(integer total_number)
{
vector currentPosition = llGetPos();
vector offset = <0, 1, 0>;
integer x;

for (x = 0; x < 8; x++) {
rotation newrot = llEuler2Rot(<(x*45) * DEG_TO_RAD, 0, 0> );
llSetRot(newrot);
vector calcOffset = offset * llGetRot();
vector newpos = llGetPos() + calcOffset;
llRezObject("Object", newpos, <0.0, 0.0, 0.0>, llGetRot(), 0);
}
}
}
Soen Eber
Registered User
Join date: 3 Aug 2006
Posts: 428
01-07-2007 08:25
I worked it out.

llRezObject rezzes an object at its geometric center, and this can throw things off if you're rezzing an object at an arbitrarily defined angle which has match up with the surrounding prims.

Use llRezAtRoot instead, it rezzes at the root prim of the object being rezzed, making it much easier to position accurately.