From 1eedc2b4af192973889341da5615139cfd65f152 Mon Sep 17 00:00:00 2001 From: dahlia Date: Mon, 2 Feb 2015 02:47:47 -0800 Subject: Compute rotation for llLookAt() with local positive X axis pointing down --- .../Shared/Api/Implementation/LSL_Api.cs | 25 ++++++++++------------ 1 file changed, 11 insertions(+), 14 deletions(-) (limited to 'OpenSim/Region/ScriptEngine/Shared/Api/Implementation') diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index 97e3eeb..debc262 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs @@ -3092,20 +3092,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api // Determine where we are looking from LSL_Vector from = llGetPos(); - // Work out the normalised vector from the source to the target - LSL_Vector delta = llVecNorm(target - from); - LSL_Vector angle = new LSL_Vector(0,0,0); - - // Calculate the yaw - // subtracting PI_BY_TWO is required to compensate for the odd SL co-ordinate system - 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); + // normalized direction to target + LSL_Vector dir = llVecNorm(target - from); + // 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); + + // compute rotation based on orthogonal azes + LSL_Rotation rot = new LSL_Rotation(0.0, 0.707107, 0.0, 0.707107) * llAxes2Rot(dir, left, up); // Per discussion with Melanie, for non-physical objects llLookAt appears to simply // set the rotation of the object, copy that behavior -- cgit v1.1