Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Problems with Rotation

Pandora Breyer
Registered User
Join date: 18 Dec 2006
Posts: 4
05-16-2007 10:14
Hello ppl,

Can someone help me? The problem is the following: I am trying to make a script and I need to work with the z-axis rotation of an object and later do some operation using planar trigonometry. A very crazy project, let's say.

The matter is that I'm getting some odd answers from the script. I made that way:

(...)

rotation rot;
vector vec;
float zax;

rot == llGetRotation(); //(1)
vec == Rot2Eul (rot); //(2)
zax == vec.z; //(3)

(...)

Note: I need the z-axis rotation in degrees, not in radians, as the llGetRot does.


Observations:

(1) Some times, using the function llSay(0, "Rot: "+(string)rot);, i get sometimes the message with the right values of the rotation, but other times, the returning message is: "Rot: <0.000,0.000,0.000,0.000>", no matter how much I rotate the primitive.

(2) Using the llSay for the variable vec, the message is always the same, a vector with only zeros.

(3) Here, the returning is always zero, because the problem of the vector.

The Wiki seems not to have the answer to this problem I'm facing. Can someone launch some light in this case? Since now, I'm grateful for your attention.
Lee Ponzu
What Would Steve Do?
Join date: 28 Jun 2006
Posts: 1,770
various comments
05-16-2007 10:47
You don't want two equals == that tests for equality.

you prolly want

zax = vec.z*RAD_TO_DEG (or whatever that constant name is...)

If you manually rotate the object, you need to recompute rot = llGetRot(); It doesn't happen automatically.

good luck
Talarus Luan
Ancient Archaean Dragon
Join date: 18 Mar 2006
Posts: 4,831
05-16-2007 10:47
I am assuming you typed the code in from memory, as it is using nonexistent functions. llGetRot() and llRot2Euler() are the correct ones.

Multiply zax by the predefined constant RAD_TO_DEG to convert to degrees from radians.

I can't answer anything else without seeing the actual code. It sounds like you have other bugs which are preventing it from working properly, as there are no issues I am aware of which would cause llGetRot() to fail like that.
Milambus Oh
Registered User
Join date: 6 Apr 2007
Posts: 224
05-16-2007 12:39
Are you working with linked prims?
Pandora Breyer
Registered User
Join date: 18 Dec 2006
Posts: 4
Not yet.
05-16-2007 16:35
No. I'm not yet working with linked prims. At the truth, I'm now programming the primary prim to when I'm finished, link it to a bigger structure.

And thanks for the tips on the programming. I'll test them today and give you all a feedback.
Pandora Breyer
Registered User
Join date: 18 Dec 2006
Posts: 4
Yes, it worked!
05-17-2007 07:03
Hello again, ppl.

Really, the tips you all gave me worked wonderfully. Now, I have another problem. I now have the z-axis rotation and I can use it to calculate the trigonometric functions, but I still have an strange behaviour from the prim I am making.

To tell the entire story, I am working on a script to make a non-physical vehicle to fly. For that, I take the z-axis rotation and to do the forward movement, I calculate the x and y velocities as cos x and sin y then I apply it to the llSetPos of the prim. But when the angle is 0, the thing goes nice. But some angles show the desired movement, while others show unexpected answers. The code is something like that (simplified):

We'll assume zrot as te z-axis rotaion of the prim. The commands ROT_LEFT and ROT_RIGHT make the following:

(...)

rotation current_rot = llGetRot();
vector rot = llRot2Euler(current_rot)*RAD_TO_DEG;
rot = rot*<0.0,0.0,10.0>;
rotation new_rot = current_rot * (llEul2Rot(rot)*DEG_TO_ROT);
llSetRot (new_rot);

(...)

and so on.

Then, when the forward command is ginven, I go on:

(...)
rotation rot = llGetRot();
vector angle = llEul2Rot (rot);
float z = angle.z*RAD_TO_DEG;

vector pos = llGetPos();
float xvel = llCos(z);
float yvel = llSin(z);

vector new_pos = pos * <xvel,yvel,0.0>;
llSetPos(new_pos);
(...)

Well. Here I get some errors, because with some angles it works, but in othes, the behavior is completely the opposite of the spected. Has someone some answer?


This thing is part of a project to pass over the 30 prims limit of the vehicles building non-physical ones, but not making them as attachments.


Thanks...
Lee Ponzu
What Would Steve Do?
Join date: 28 Jun 2006
Posts: 1,770
05-17-2007 11:24
I don't think you want to be multiplying rotations when they are Euler format.
Lee Ponzu
What Would Steve Do?
Join date: 28 Jun 2006
Posts: 1,770
05-17-2007 11:38
From: Pandora Breyer

We'll assume zrot as te z-axis rotaion of the prim. The commands ROT_LEFT and ROT_RIGHT make the following:

(...)

rotation current_rot = llGetRot();
vector rot = llRot2Euler(current_rot)*RAD_TO_DEG;
rot = rot*<0.0,0.0,10.0>;
rotation new_rot = current_rot * (llEul2Rot(rot)*DEG_TO_ROT);
llSetRot (new_rot);

try
rot += <0,0,10>; // add ten degrees to z-rotation
new_rot = llEuler2Rot( rot*DEG_TO_ROT );


From: someone


Then, when the forward command is ginven, I go on:


rotation rot = llGetRot();
vector angle = llEul2Rot (rot);
float z = angle.z*RAD_TO_DEG;

vector pos = llGetPos();
float xvel = llCos(z);
float yvel = llSin(z);

vector new_pos = pos * <xvel,yvel,0.0>;
llSetPos(new_pos);
(...)

To move to a point 1 meters in front, try

llSetPos( llGetPos() + <1,0,0>*llGetRot() );
Pandora Breyer
Registered User
Join date: 18 Dec 2006
Posts: 4
Thanks.
05-18-2007 07:27
Hello again, ppl.

Thanks for your help ang your good will. Now, the script is ready and I can pass to the next phase of the project I'm working. If you want to see the final result, just add me in SL and IM me so I can invite you to the inaugural flight of the vessel.
Talarus Luan
Ancient Archaean Dragon
Join date: 18 Mar 2006
Posts: 4,831
05-18-2007 10:17
From: Lee Ponzu
try
rot += <0,0,10>; // add ten degrees to z-rotation
new_rot = llEuler2Rot( rot*DEG_TO_ROT );


What kind of ROT is that? Bit ROT, dry ROT, all that ROT? :P