Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Rotation combination

Caoimhe Armitage
Script Witch
Join date: 7 Sep 2004
Posts: 117
11-23-2004 08:47
Ok, I am fairly befuddled. I have the following:

CODE

// from the Wiki
rotation getRotToPointAxisAt(vector axis, vector target) {
return llGetRot() * llRotBetween(axis * llGetRot(), target - llGetPos()); }

// adapted from forum code by Pedro Pendragon
float getRoll(rotation now) {
vector v = llRot2Fwd(llGetRot());
float heading = llAtan2(v.y, v.x);

float run = llSqrt(v.x * v.x + v.y * v.y);
float pitch = -llAtan2(v.z, run);

rotation y = llEuler2Rot(<0, pitch, 0>);
rotation z = llEuler2Rot(<0, 0, heading>);
rotation x = now / z / y;
vector tmp = llRot2Euler(x);
float roll=tmp.x;

return roll; }


Now when I rotate my object as follows:

CODE

llSetRot(getRotToPointAxisAt(<1,0,0>, target));
llSetRot(llEuler2Rot(<-getRoll(llGetRot()), 0, 0>) * llGetRot());


I get perfect alignment, but two visible motions. Not a problem! Just combine
the rots, right?

CODE

rotation first = getRotToPointAxisAt(<1,0,0>, target));
llSetRot(llEuler2Rot(<-getRoll(first), 0, 0>) * first);


but apparently this is the wrong way to combine those two operations. Help!

- C
Pedro Pendragon
Registered User
Join date: 15 Jan 2004
Posts: 77
11-23-2004 19:42
Probably in your getRoll() function you want to do this instead:

CODE

vector v = llRot2Fwd(now);


Looks like you're using llGetRot() there, which will give you the rotation previous to 'first' (because it hasn't happened yet)
Caoimhe Armitage
Script Witch
Join date: 7 Sep 2004
Posts: 117
11-23-2004 23:30
From: Pedro Pendragon
Probably in your getRoll() function you want to do this instead:


D'oh! Transformations piled on top of transformations. You're dead right. Thanks.

How I wish LSL was a FP language. :)

- C :)