Difference between revisions of "User:Pedro Oval/Calculate rotation for pointing in a direction"

From Second Life Wiki
Jump to navigation Jump to search
(First template)
 
m (moved User:Pedro Oval/Calculate rotation to point in a direction to User:Pedro Oval/Calculate rotation for pointing in a direction: Better name, avoids ambiguity between point as a verb and as a substantive.)
(No difference)

Revision as of 20:21, 7 January 2011

Here are two useful functions that, given a vector to point at, return the rotation that corresponds to that vector. The first function points exactly in that direction, while keeping the up (Z) vector pointing "as up as possible", and the second function points to the horizontal that is closest to the given vector, while the Z vector points exactly up.

<lsl> rotation PointAt2Rot(vector target) {

   vector fwd = llVecNorm(target);
   vector left = llVecNorm(<0., 0., 1.> % fwd);
   vector up = fwd % left;
   return llAxes2Rot(fwd, left, up);

}

rotation PointAtHoriz2Rot(vector target) {

   vector up = <0., 0., 1.>;
   vector left = llVecNorm(up % target);
   vector fwd = left % up;
   return llAxes2Rot(fwd, left, up);

} </lsl>