Compute rotation for llLookAt() with local positive X axis pointing down
parent
bee3933e57
commit
1eedc2b4af
|
@ -3092,20 +3092,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
|
||||||
// Determine where we are looking from
|
// Determine where we are looking from
|
||||||
LSL_Vector from = llGetPos();
|
LSL_Vector from = llGetPos();
|
||||||
|
|
||||||
// Work out the normalised vector from the source to the target
|
// normalized direction to target
|
||||||
LSL_Vector delta = llVecNorm(target - from);
|
LSL_Vector dir = llVecNorm(target - from);
|
||||||
LSL_Vector angle = new LSL_Vector(0,0,0);
|
// use vertical to help compute left azis
|
||||||
|
LSL_Vector up = new LSL_Vector(0.0, 0.0, 1.0);
|
||||||
|
// find normalized left axis parallel to horizon
|
||||||
|
LSL_Vector left = llVecNorm(LSL_Vector.Cross(up, dir));
|
||||||
|
// make up orthogonal to left and dir
|
||||||
|
up = LSL_Vector.Cross(dir, left);
|
||||||
|
|
||||||
// Calculate the yaw
|
// compute rotation based on orthogonal azes
|
||||||
// subtracting PI_BY_TWO is required to compensate for the odd SL co-ordinate system
|
LSL_Rotation rot = new LSL_Rotation(0.0, 0.707107, 0.0, 0.707107) * llAxes2Rot(dir, left, up);
|
||||||
angle.x = llAtan2(delta.z, delta.y) - ScriptBaseClass.PI_BY_TWO;
|
|
||||||
|
|
||||||
// Calculate pitch
|
|
||||||
angle.y = llAtan2(delta.x, llSqrt((delta.y * delta.y) + (delta.z * delta.z)));
|
|
||||||
|
|
||||||
// we need to convert from a vector describing
|
|
||||||
// the angles of rotation in radians into rotation value
|
|
||||||
LSL_Rotation rot = llEuler2Rot(angle);
|
|
||||||
|
|
||||||
// Per discussion with Melanie, for non-physical objects llLookAt appears to simply
|
// Per discussion with Melanie, for non-physical objects llLookAt appears to simply
|
||||||
// set the rotation of the object, copy that behavior
|
// set the rotation of the object, copy that behavior
|
||||||
|
|
Loading…
Reference in New Issue