Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Problems with llRotate

Nada Epoch
The Librarian
Join date: 4 Nov 2002
Posts: 1,423
12-02-2002 22:33
Ok here is the script that i am running, basically i am using a for loop to make an object do half a rotation around an axis outside of itself. As i read it (heh, course i am biased) it is making a full 180 degree rotation about its y axis, and infact it states at the end that it is at 3.14...radians, however it isn't really, it is at -35 degrees about the y if you inspect it. This script does a little more than just that, but it the other part is not important, i just included it in its entirity so you could cut and paste it into a new script.

I have run several experiments on the llSetRot() command, and it is just screwy. For example, just to test it, i wrote a for loop that went through 8 times, and was supposed to rotat the object by 90 degrees, or 1/4 radians each time, but it doesn't...It rotates the object a larger number initially and then the change drops dramatically as the function progresses( i will post that tomorrow)

Anyways, if you see something I am missing, drop me a line, cause, well I am completely stumper


vector base_pos;
rotation base_rotation;

default
{
state_entry()
{
base_pos=llGetPos();
base_rotation=llGetRot();
llListen(0,"","","start";);
llListen(0,"","","stop";);
llListen(0,"","","die";);
}

listen(integer a, string n, key id, string m)
{
vector linear=base_pos;
rotation circular=base_rotation;
if(m=="start";)
{
integer i;
// for (i=0;i<20;i++)
// {
// linear.x+=(.5/20);
// llSetPos(linear);
// }
vector o_point;
o_point=linear+<0,0,-.3>;
for (i=0;i<21;i++)
{
float x;
float z;
z=.3-i*(1.1)/20;
x=llSqrt((.3*.3)-(z*z));
circular=<0,1,0,-i*(PI)/20>;
llWhisper(0,(string)circular);
linear.x=o_point.x+x;
linear.z=o_point.z+z;
llSetPos(linear);
llSetRot(circular);
llSleep(.1);
}


}
if(m=="stop";)
{
llSetPos(base_pos);
llSetRot(base_rotation);
}
if(m=="die";)
{
llDie();
}

}
}
_____________________
i've got nothing. ;)
Philip Linden
Founder, Linden Lab
Join date: 18 Nov 2002
Posts: 428
12-03-2002 05:19
Hi Nada,

I think the problem is how you are constructing your rotations... they are what are mathematically called Quaternions (we renamed them to make them easier to understand for beginners - figuring all the lucky folks who actually know what quaternion means won't have a prob with rotation).

There are several functions in the scripting language that make it easy to convert from euler angles or axis of rotation to quaterion/rotation representation. I think for your application (making an object appear to follow a converyor pathway) the easiest function to use it llAngleAxis2Rot(). This lets you specify a direction as an axix, and then rotate about it.

Below is some code that slowly rotates a cube, printing out the angle in radians along the way. Let me know if this helps.

float radians = 0.0;
default
{
state_entry()
{
llSetTimerEvent(0.25);
}
timer()
{
radians += 0.1;
if (radians > 2.0*PI) radians = 0.0;
llSay(0, "Deg/PI = " + (string)(radians/PI));
rotation test;
test = llAxisAngle2Rot(<0,0,1>, radians);
llSetRot(test);
}
}
Nada Epoch
The Librarian
Join date: 4 Nov 2002
Posts: 1,423
4-D Rotation
12-03-2002 21:27
I understand Quaternions, 4 dimensional rotation <x,y,z,w> where the x,y,z determine an abitrary vector that will be the axis about which the object will rotate, and w is number of radians that the object will rotate about the axis. So my question really is any idea why my script isn't causing the object to rotate correctly?

a la your script
float radians = 0.0;
default
{
state_entry()
{
llSetTimerEvent(0.25);
}
timer()
{
radians += 0.1;
if (radians > 2.0*PI) radians = 0.0;
llSay(0, "Deg/PI = " + (string)(radians/PI));
rotation test;
test = llAxisAngle2Rot(<0,0,1>, radians);
llSetRot(test);
}
}

hey wait a minute, your script isn't any different than mine, heh, only thing you changed was making test equal to the quaternion that i was using in my llSetRotate...

It goes through the math totally fine, incrementing the rotation fine, but what the math says and what the object does, in my script, are two different things...and I just don't get it.

There is also another problem, it should make a full half circle about the axis I set up that is .55 away from its center, but it doesn't...I am wondering if the system is dropping decimal points I need. Reason: if you set i to 40, and the increment of distance and rotation to 1/40 of the total, it goes ok until it gets to towards the end of the rotation and then it slows down and then stops moving at all even though it is still calling out variables... I probably just need to show you guys, since i think it is getting garbled trying to explain it all over the boards. Or you can just drop by my pole, and floating near the top is a green box with a smaller striped one sitting on it. Say start and watch the little box move.
_____________________
i've got nothing. ;)
Nada Epoch
The Librarian
Join date: 4 Nov 2002
Posts: 1,423
stupid math error
12-03-2002 21:54
I found a silly math error in my cirulation calculation, that accounted for why it was getting to the end and not moving, so belay that part of the comment. However if some one could tell me why my direct use of the quartenions was wrong, that would be most helpful.

BTW thanks peter, i just inserted your little snippet of code, along with my partitioning of the angle in the for loop and it works just fine, which makes me ven more confused about why the other one won't work... oh well, at least one of them does now :)
_____________________
i've got nothing. ;)