aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region
diff options
context:
space:
mode:
authorMelanie2012-01-23 13:48:16 +0100
committerMelanie2012-01-23 13:48:16 +0100
commit4e0bb49394d303c7c7707f85b02e47b7c2053201 (patch)
tree0a6777be2984a1ed37787f3484a31f1be17735ad /OpenSim/Region
parentMerge branch 'master' into careminster (diff)
downloadopensim-SC_OLD-4e0bb49394d303c7c7707f85b02e47b7c2053201.zip
opensim-SC_OLD-4e0bb49394d303c7c7707f85b02e47b7c2053201.tar.gz
opensim-SC_OLD-4e0bb49394d303c7c7707f85b02e47b7c2053201.tar.bz2
opensim-SC_OLD-4e0bb49394d303c7c7707f85b02e47b7c2053201.tar.xz
Fix llLookAt the right way
Diffstat (limited to 'OpenSim/Region')
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs43
1 files changed, 24 insertions, 19 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
index ac22638..7af5d2d 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
@@ -3040,34 +3040,39 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3040 public void llLookAt(LSL_Vector target, double strength, double damping) 3040 public void llLookAt(LSL_Vector target, double strength, double damping)
3041 { 3041 {
3042 m_host.AddScriptLPS(1); 3042 m_host.AddScriptLPS(1);
3043 // Determine where we are looking from
3044 LSL_Vector from = llGetPos();
3045 3043
3046 // Work out the normalised vector from the source to the target 3044 // Get the normalized vector to the target
3047 LSL_Vector delta = llVecNorm(target - from); 3045 LSL_Vector d1 = llVecNorm(target - llGetPos());
3048 LSL_Vector angle = new LSL_Vector(0,0,0);
3049 3046
3050 // Calculate the yaw 3047 // Get the bearing (yaw)
3051 // subtracting PI_BY_TWO is required to compensate for the odd SL co-ordinate system 3048 LSL_Vector a1 = new LSL_Vector(0,0,0);
3052 angle.x = llAtan2(delta.z, delta.y) - ScriptBaseClass.PI_BY_TWO; 3049 a1.z = llAtan2(d1.y, d1.x);
3053 3050
3054 // Calculate pitch 3051 // Get the elevation (pitch)
3055 angle.y = llAtan2(delta.x, llSqrt((delta.y * delta.y) + (delta.z * delta.z))); 3052 LSL_Vector a2 = new LSL_Vector(0,0,0);
3053 a2.y= -llAtan2(d1.z, llSqrt((d1.x * d1.x) + (d1.y * d1.y)));
3056 3054
3057 // we need to convert from a vector describing 3055 LSL_Rotation r1 = llEuler2Rot(a1);
3058 // the angles of rotation in radians into rotation value 3056 LSL_Rotation r2 = llEuler2Rot(a2);
3057 LSL_Rotation r3 = new LSL_Rotation(0.000000, 0.707107, 0.000000, 0.707107);
3059 3058
3060 LSL_Rotation rot = llEuler2Rot(angle); 3059 if (m_host.PhysActor == null || !m_host.PhysActor.IsPhysical)
3061
3062 // Per discussion with Melanie, for non-physical objects llLookAt appears to simply
3063 // set the rotation of the object, copy that behavior
3064 if (strength == 0 || m_host.PhysActor == null || !m_host.PhysActor.IsPhysical)
3065 { 3060 {
3066 llSetRot(rot); 3061 // Do nothing if either value is 0 (this has been checked in SL)
3062 if (strength <= 0.0 || damping <= 0.0)
3063 return;
3064
3065 llSetRot(r3 * r2 * r1);
3067 } 3066 }
3068 else 3067 else
3069 { 3068 {
3070 m_host.StartLookAt(Rot2Quaternion(rot), (float)strength, (float)damping); 3069 if (strength == 0)
3070 {
3071 llSetRot(r3 * r2 * r1);
3072 return;
3073 }
3074
3075 m_host.StartLookAt(Rot2Quaternion(r3 * r2 * r1), (float)strength, (float)damping);
3071 } 3076 }
3072 } 3077 }
3073 3078