aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorMic Bowman2012-01-13 14:48:56 -0800
committerMic Bowman2012-01-13 14:48:56 -0800
commite1a2c44ebe8f10cf00a14578e44b000ff16b68df (patch)
tree00d0dd19ce7a3f4f67d8625868c594777132de27
parentFix llRotLookAt and llLookAt for non-physical objects. Per conversation (diff)
downloadopensim-SC_OLD-e1a2c44ebe8f10cf00a14578e44b000ff16b68df.zip
opensim-SC_OLD-e1a2c44ebe8f10cf00a14578e44b000ff16b68df.tar.gz
opensim-SC_OLD-e1a2c44ebe8f10cf00a14578e44b000ff16b68df.tar.bz2
opensim-SC_OLD-e1a2c44ebe8f10cf00a14578e44b000ff16b68df.tar.xz
Cleaned up the LookAt code in SOP and SOG. Added support for incrementally
rotating physical objects. This does not use physics. Currently the rate of change is determined as 1 / (PI * Strength).
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs6
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneObjectPart.cs69
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs8
3 files changed, 34 insertions, 49 deletions
diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs
index 8860764..cad09b8 100644
--- a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs
@@ -1613,12 +1613,6 @@ namespace OpenSim.Region.Framework.Scenes
1613 RootPart.PhysActor.PIDActive = false; 1613 RootPart.PhysActor.PIDActive = false;
1614 } 1614 }
1615 1615
1616 public void stopLookAt()
1617 {
1618 if (RootPart.PhysActor != null)
1619 RootPart.PhysActor.APIDActive = false;
1620 }
1621
1622 /// <summary> 1616 /// <summary>
1623 /// Uses a PID to attempt to clamp the object on the Z axis at the given height over tau seconds. 1617 /// Uses a PID to attempt to clamp the object on the Z axis at the given height over tau seconds.
1624 /// </summary> 1618 /// </summary>
diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs
index e9c33eb..ad3bcd5 100644
--- a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs
@@ -217,11 +217,10 @@ namespace OpenSim.Region.Framework.Scenes
217 217
218 public Quaternion SpinOldOrientation = Quaternion.Identity; 218 public Quaternion SpinOldOrientation = Quaternion.Identity;
219 219
220 public Quaternion m_APIDTarget = Quaternion.Identity; 220 protected int m_APIDIterations = 0;
221 221 protected Quaternion m_APIDTarget = Quaternion.Identity;
222 public float m_APIDDamp = 0; 222 protected float m_APIDDamp = 0;
223 223 protected float m_APIDStrength = 0;
224 public float m_APIDStrength = 0;
225 224
226 /// <summary> 225 /// <summary>
227 /// This part's inventory 226 /// This part's inventory
@@ -563,22 +562,21 @@ namespace OpenSim.Region.Framework.Scenes
563 } 562 }
564 } 563 }
565 564
566 565 protected Quaternion APIDTarget
567 public Quaternion APIDTarget
568 { 566 {
569 get { return m_APIDTarget; } 567 get { return m_APIDTarget; }
570 set { m_APIDTarget = value; } 568 set { m_APIDTarget = value; }
571 } 569 }
572 570
573 571
574 public float APIDDamp 572 protected float APIDDamp
575 { 573 {
576 get { return m_APIDDamp; } 574 get { return m_APIDDamp; }
577 set { m_APIDDamp = value; } 575 set { m_APIDDamp = value; }
578 } 576 }
579 577
580 578
581 public float APIDStrength 579 protected float APIDStrength
582 { 580 {
583 get { return m_APIDStrength; } 581 get { return m_APIDStrength; }
584 set { m_APIDStrength = value; } 582 set { m_APIDStrength = value; }
@@ -2697,11 +2695,6 @@ namespace OpenSim.Region.Framework.Scenes
2697 2695
2698 public void RotLookAt(Quaternion target, float strength, float damping) 2696 public void RotLookAt(Quaternion target, float strength, float damping)
2699 { 2697 {
2700 rotLookAt(target, strength, damping);
2701 }
2702
2703 public void rotLookAt(Quaternion target, float strength, float damping)
2704 {
2705 if (ParentGroup.IsAttachment) 2698 if (ParentGroup.IsAttachment)
2706 { 2699 {
2707 /* 2700 /*
@@ -2716,17 +2709,26 @@ namespace OpenSim.Region.Framework.Scenes
2716 APIDDamp = damping; 2709 APIDDamp = damping;
2717 APIDStrength = strength; 2710 APIDStrength = strength;
2718 APIDTarget = target; 2711 APIDTarget = target;
2712
2713 if (APIDStrength <= 0)
2714 {
2715 m_log.WarnFormat("[SceneObjectPart] Invalid rotation strength {0}",APIDStrength);
2716 return;
2717 }
2718
2719 m_APIDIterations = 1 + (int)(Math.PI * APIDStrength);
2719 } 2720 }
2721
2722 // Necessary to get the lookat deltas applied
2723 ParentGroup.QueueForUpdateCheck();
2720 } 2724 }
2721 2725
2722 public void startLookAt(Quaternion rot, float damp, float strength) 2726 public void StartLookAt(Quaternion target, float strength, float damping)
2723 { 2727 {
2724 APIDDamp = damp; 2728 RotLookAt(target,strength,damping);
2725 APIDStrength = strength;
2726 APIDTarget = rot;
2727 } 2729 }
2728 2730
2729 public void stopLookAt() 2731 public void StopLookAt()
2730 { 2732 {
2731 APIDTarget = Quaternion.Identity; 2733 APIDTarget = Quaternion.Identity;
2732 } 2734 }
@@ -3417,13 +3419,6 @@ namespace OpenSim.Region.Framework.Scenes
3417 } 3419 }
3418 } 3420 }
3419 3421
3420 public void StopLookAt()
3421 {
3422 ParentGroup.stopLookAt();
3423
3424 ParentGroup.ScheduleGroupForTerseUpdate();
3425 }
3426
3427 /// <summary> 3422 /// <summary>
3428 /// Set the text displayed for this part. 3423 /// Set the text displayed for this part.
3429 /// </summary> 3424 /// </summary>
@@ -4731,24 +4726,20 @@ namespace OpenSim.Region.Framework.Scenes
4731 { 4726 {
4732 if (APIDTarget != Quaternion.Identity) 4727 if (APIDTarget != Quaternion.Identity)
4733 { 4728 {
4734 if (Single.IsNaN(APIDTarget.W) == true) 4729 if (m_APIDIterations <= 1)
4735 { 4730 {
4731 UpdateRotation(APIDTarget);
4736 APIDTarget = Quaternion.Identity; 4732 APIDTarget = Quaternion.Identity;
4737 return; 4733 return;
4738 } 4734 }
4739 Quaternion rot = RotationOffset; 4735
4740 Quaternion dir = (rot - APIDTarget); 4736 Quaternion rot = Quaternion.Slerp(RotationOffset,APIDTarget,1.0f/(float)m_APIDIterations);
4741 float speed = ((APIDStrength / APIDDamp) * (float)(Math.PI / 180.0f));
4742 if (dir.Z > speed)
4743 {
4744 rot.Z -= speed;
4745 }
4746 if (dir.Z < -speed)
4747 {
4748 rot.Z += speed;
4749 }
4750 rot.Normalize();
4751 UpdateRotation(rot); 4737 UpdateRotation(rot);
4738
4739 m_APIDIterations--;
4740
4741 // This ensures that we'll check this object on the next iteration
4742 ParentGroup.QueueForUpdateCheck();
4752 } 4743 }
4753 } 4744 }
4754 catch (Exception ex) 4745 catch (Exception ex)
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
index 30145c7..ab175ba 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
@@ -2865,13 +2865,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2865 2865
2866 // Per discussion with Melanie, for non-physical objects llLookAt appears to simply 2866 // Per discussion with Melanie, for non-physical objects llLookAt appears to simply
2867 // set the rotation of the object, copy that behavior 2867 // set the rotation of the object, copy that behavior
2868 if (m_host.PhysActor == null || !m_host.PhysActor.IsPhysical) 2868 if (strength == 0 || m_host.PhysActor == null || !m_host.PhysActor.IsPhysical)
2869 { 2869 {
2870 llSetRot(rot); 2870 llSetRot(rot);
2871 } 2871 }
2872 else 2872 else
2873 { 2873 {
2874 m_host.startLookAt(Rot2Quaternion(rot), (float)damping, (float)strength); 2874 m_host.StartLookAt(Rot2Quaternion(rot), (float)strength, (float)damping);
2875 } 2875 }
2876 } 2876 }
2877 2877
@@ -3251,13 +3251,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3251 3251
3252 // Per discussion with Melanie, for non-physical objects llLookAt appears to simply 3252 // Per discussion with Melanie, for non-physical objects llLookAt appears to simply
3253 // set the rotation of the object, copy that behavior 3253 // set the rotation of the object, copy that behavior
3254 if (m_host.PhysActor == null || !m_host.PhysActor.IsPhysical) 3254 if (strength == 0 || m_host.PhysActor == null || !m_host.PhysActor.IsPhysical)
3255 { 3255 {
3256 llSetLocalRot(target); 3256 llSetLocalRot(target);
3257 } 3257 }
3258 else 3258 else
3259 { 3259 {
3260 m_host.RotLookAt(Rot2Quaternion(target), (float)damping, (float)strength); 3260 m_host.RotLookAt(Rot2Quaternion(target), (float)strength, (float)damping);
3261 } 3261 }
3262 } 3262 }
3263 3263