Fix llLookAt so that it doesn't "roll" the object and more closely imitates the behaviour in SL. ( http://bugs.meta7.com/view.php?id=28 )

avinationmerge
Thomas Grimshaw 2010-04-07 09:49:11 +02:00
parent 20e3de1f0a
commit db5ea850f6
1 changed files with 16 additions and 4 deletions

View File

@ -2881,6 +2881,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
public void llLookAt(LSL_Vector target, double strength, double damping) public void llLookAt(LSL_Vector target, double strength, double damping)
{ {
/*
m_host.AddScriptLPS(1); m_host.AddScriptLPS(1);
// Determine where we are looking from // Determine where we are looking from
LSL_Vector from = llGetPos(); LSL_Vector from = llGetPos();
@ -2900,12 +2901,23 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
// the angles of rotation in radians into rotation value // the angles of rotation in radians into rotation value
LSL_Types.Quaternion rot = llEuler2Rot(angle); LSL_Types.Quaternion rot = llEuler2Rot(angle);
/*
Quaternion rotation = new Quaternion((float)rot.x, (float)rot.y, (float)rot.z, (float)rot.s); // This would only work if your physics system contains an APID controller:
m_host.startLookAt(rotation, (float)damping, (float)strength); // Quaternion rotation = new Quaternion((float)rot.x, (float)rot.y, (float)rot.z, (float)rot.s);
This would only work if your physics system contains an APID controller */ // m_host.startLookAt(rotation, (float)damping, (float)strength);
// Orient the object to the angle calculated // Orient the object to the angle calculated
llSetRot(rot); llSetRot(rot);
*/
//The above code, while nice, doesn't replicate the behaviour of SL and tends to "roll" the object.
//There's probably a smarter way of doing this, my rotation math-fu is weak.
// http://bugs.meta7.com/view.php?id=28
// - Tom
LSL_Rotation newrot = llGetRot() * llRotBetween(new LSL_Vector(1.0d, 0.0d, 0.0d) * llGetRot(), new LSL_Vector(0.0d, 0.0d, -1.0d));
llSetRot(newrot * llRotBetween(new LSL_Vector(0.0d,0.0d,1.0d) * newrot, target - llGetPos()));
} }
public void llRotLookAt(LSL_Rotation target, double strength, double damping) public void llRotLookAt(LSL_Rotation target, double strength, double damping)