User:Pedro Oval/Calculate rotation for pointing in a direction
Jump to navigation
Jump to search
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>