The situation is that I have a simple pointing object, one that orients itself to point directly at an avatar, which most likely will be slightly "down" from its vantage point. Well, using the code at the WIKI (http://rpgstats.com/wiki/index.php?title=LlLookAt), I can get the object to point to the avatar, but I'm currently wanting to use the local X-axis of the object rather than the Z, so am using the code alternative for the llRotLookAt function rather than the llLookAt function.
The problem arises in the fact that often, as the object rotates to point its local X to the avatar target, it barrel rolls around the local X to end up with the local Z no longer pointing up, but off in a random direction. In trying to re-orient this object, I realize that I can't get the local Z axis to point straight up (global Z), if the object itself is tipped in the Y to have it point down. In truth, I need to find out how to orient the object such that the local Z-axis is coplanar to the plane formed by the local X-axis and the global Z-axis.
So, I'm guessing my code will look something like:
CODE
float myAngle = 42;
rotation myAngleRot = llEuler2Rot(<myAngle, 0, 0>); // Rotate around X to un-barrel-roll
rotation newRot = myAngleRot * llGetRot(); // rotate locally, rather than globally
llRotLookAt(newRot, 0.5, 0.5); // Apply the rotation
The question would be, in this scenario, how to find out what "myAngle" should be (I used 42 here as an arbitrary number), since it needs to be the amount that will bring Z back "up" as much as possible.
Or, is it possible to prevent this barrel roll in the first place? I tried setting llSetStatus(STATUS_ROTATE_X,FALSE); before doing the llRotLookAt to begin with, in the hopes of preventing that barrel roll in the first place, but that didn't work. Is there another way?