Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Rotation Problem (mis-posted in Library forum by mistake...sorry!)

Zuleica Sartre
Registered User
Join date: 27 Sep 2005
Posts: 105
08-22-2007 19:59
Use llRezObject to rez a single prim with a random rotation.

How do you, from within the single prim, align it pointing it's x-axis along the global x-axis and then read the angle of rotation around that axis?

I've tried the following, which seemed intuitive, but gives nonsense...

rotation rMyRot = llGetRot();
vector vFwd = llRot2Fwd(rMyRot);

rotation rBetween = llRotBetween(vFwd,<1.0,0.0,0.0>;);

rotation rNewRot = rBetween * rMyRot;

llSetRot(rNewRot);

Shouldn't at this point the prim be lined up with the global x-axis?
And shouldn't I now be able to get the x-axis angle of rotation by...

vector eulerRot = llRot2Euler(rNewRot);
float angleX = eulerRot.x * RAD_TO_DEG;
Talarus Luan
Ancient Archaean Dragon
Join date: 18 Mar 2006
Posts: 4,831
08-23-2007 08:46
Replace this:

rotation rNewRot = rBetween * rMyRot;

with this:

rotation rNewRot = rMyRot * rBetween;

and try it.

Rotation combinations are not commutative. The order of operands makes a big difference.
Zuleica Sartre
Registered User
Join date: 27 Sep 2005
Posts: 105
08-23-2007 19:08
Swapping the order on that didn't help.

What I want to do is:

1. Rez an object in the direction the camera is pointing (any random direction) and give it a fixed rotation along the forward axis.

2. Have the object determine the rotation it was given around it's forward axis.

#1 is easy

#2 I can't seem to accomplish...
Talarus Luan
Ancient Archaean Dragon
Join date: 18 Mar 2006
Posts: 4,831
08-23-2007 21:56
OK. First point: rotations are difficult, which makes solutions more difficult, when not presented with very exacting details of what you are trying to accomplish.

That said, your original code with my change does exactly what you asked. Rez a prim with an arbitrary rotation, and it will align the prim's X-axis with the global X-axis. The remaining rotation will be the rotation around the X-axis.

From your revised description, you want to rez a prim in the direction the camera is pointing (with what rotation? zero? the camera rotation? etc), and give it a fixed rotation around the X-axis (which X-axis? local, global? what fixed rotation? how is it "given?). Until the details of #1 are worked out, #2 won't make any sense to anyone.
Jotheph Nemeth
Registered User
Join date: 9 Aug 2007
Posts: 142
08-23-2007 22:10
From: Talarus Luan
OK. First point: rotations are difficult, which makes solutions more difficult, when not presented with very exacting details of what you are trying to accomplish.

That said, your original code with my change does exactly what you asked. Rez a prim with an arbitrary rotation, and it will align the prim's X-axis with the global X-axis. The remaining rotation will be the rotation around the X-axis.


That explains some results I was getting a while back.
Zuleica Sartre
Registered User
Join date: 27 Sep 2005
Posts: 105
08-24-2007 08:29
From: Talarus Luan
OK. First point: rotations are difficult, which makes solutions more difficult, when not presented with very exacting details of what you are trying to accomplish.

That said, your original code with my change does exactly what you asked. Rez a prim with an arbitrary rotation, and it will align the prim's X-axis with the global X-axis. The remaining rotation will be the rotation around the X-axis.

From your revised description, you want to rez a prim in the direction the camera is pointing (with what rotation? zero? the camera rotation? etc), and give it a fixed rotation around the X-axis (which X-axis? local, global? what fixed rotation? how is it "given?). Until the details of #1 are worked out, #2 won't make any sense to anyone.


// The code that generates the rotation for the llRezObject
float variable_xRot = 15.0;
rotation rot = llGetCameraRot();
rot = llEuler2Rot(<variable_xRot,90.0,0.0>*DEG_TO_RAD) * rot;

This seems to rez the object just fine with it's x-axis pointing along the mouselook direction with variable_xRot along that forward axis.

What I can't seem to do is to derive variable_xRot from within the prim. I thought I made your change correctly but I can try again when I get home from work.

Given the above code to rez the object I should be able to read the rotation variable_xRot as 15 degrees for every camera rotation...right? I'm hoping that I'm just making some stupid mistake...