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