From 8ad6f575ebc23f0c7b282b9ec2543bce26287e54 Mon Sep 17 00:00:00 2001
From: Teravus Ovares
Date: Sun, 14 Dec 2008 14:30:28 +0000
Subject: * Implements the torque/Rotational Impulse methods in the PhysicsAPI
and the ODEPlugin and pipes them to their respective LSL method. * NBody will
need to be updated, this is an API change. Torque property and
AddAngularForce
---
.../Region/Environment/Scenes/SceneObjectGroup.cs | 58 ++++++++++++++++++++
.../Region/Environment/Scenes/SceneObjectPart.cs | 62 ++++++++++++++++++++++
2 files changed, 120 insertions(+)
(limited to 'OpenSim/Region/Environment')
diff --git a/OpenSim/Region/Environment/Scenes/SceneObjectGroup.cs b/OpenSim/Region/Environment/Scenes/SceneObjectGroup.cs
index fabf276..cc99929 100644
--- a/OpenSim/Region/Environment/Scenes/SceneObjectGroup.cs
+++ b/OpenSim/Region/Environment/Scenes/SceneObjectGroup.cs
@@ -1466,6 +1466,64 @@ namespace OpenSim.Region.Environment.Scenes
}
}
+ public void applyAngularImpulse(PhysicsVector impulse)
+ {
+ // We check if rootpart is null here because scripts don't delete if you delete the host.
+ // This means that unfortunately, we can pass a null physics actor to Simulate!
+ // Make sure we don't do that!
+ SceneObjectPart rootpart = m_rootPart;
+ if (rootpart != null)
+ {
+ if (rootpart.PhysActor != null)
+ {
+ if (!IsAttachment)
+ {
+ rootpart.PhysActor.AddAngularForce(impulse, true);
+ m_scene.PhysicsScene.AddPhysicsActorTaint(rootpart.PhysActor);
+ }
+ }
+ }
+ }
+
+ public void setAngularImpulse(PhysicsVector impulse)
+ {
+ // We check if rootpart is null here because scripts don't delete if you delete the host.
+ // This means that unfortunately, we can pass a null physics actor to Simulate!
+ // Make sure we don't do that!
+ SceneObjectPart rootpart = m_rootPart;
+ if (rootpart != null)
+ {
+ if (rootpart.PhysActor != null)
+ {
+ if (!IsAttachment)
+ {
+ rootpart.PhysActor.Torque = impulse;
+ m_scene.PhysicsScene.AddPhysicsActorTaint(rootpart.PhysActor);
+ }
+ }
+ }
+ }
+
+ public Vector3 GetTorque()
+ {
+ // We check if rootpart is null here because scripts don't delete if you delete the host.
+ // This means that unfortunately, we can pass a null physics actor to Simulate!
+ // Make sure we don't do that!
+ SceneObjectPart rootpart = m_rootPart;
+ if (rootpart != null)
+ {
+ if (rootpart.PhysActor != null)
+ {
+ if (!IsAttachment)
+ {
+ PhysicsVector torque = rootpart.PhysActor.Torque;
+ return new Vector3(torque.X, torque.Y, torque.Z);
+ }
+ }
+ }
+ return Vector3.Zero;
+ }
+
public void moveToTarget(Vector3 target, float tau)
{
SceneObjectPart rootpart = m_rootPart;
diff --git a/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs b/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs
index efc9289..5a43df6 100644
--- a/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs
+++ b/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs
@@ -1180,6 +1180,68 @@ if (m_shape != null) {
}
}
+
+ ///
+ /// hook to the physics scene to apply angular impulse
+ /// This is sent up to the group, which then finds the root prim
+ /// and applies the force on the root prim of the group
+ ///
+ /// Vector force
+ /// true for the local frame, false for the global frame
+ public void ApplyAngularImpulse(Vector3 impulsei, bool localGlobalTF)
+ {
+ PhysicsVector impulse = new PhysicsVector(impulsei.X, impulsei.Y, impulsei.Z);
+
+ if (localGlobalTF)
+ {
+ Quaternion grot = GetWorldRotation();
+ Quaternion AXgrot = grot;
+ Vector3 AXimpulsei = impulsei;
+ Vector3 newimpulse = AXimpulsei * AXgrot;
+ impulse = new PhysicsVector(newimpulse.X, newimpulse.Y, newimpulse.Z);
+ }
+
+ if (m_parentGroup != null)
+ {
+ m_parentGroup.applyAngularImpulse(impulse);
+ }
+ }
+
+ ///
+ /// hook to the physics scene to apply angular impulse
+ /// This is sent up to the group, which then finds the root prim
+ /// and applies the force on the root prim of the group
+ ///
+ /// Vector force
+ /// true for the local frame, false for the global frame
+ public void SetAngularImpulse(Vector3 impulsei, bool localGlobalTF)
+ {
+ PhysicsVector impulse = new PhysicsVector(impulsei.X, impulsei.Y, impulsei.Z);
+
+ if (localGlobalTF)
+ {
+ Quaternion grot = GetWorldRotation();
+ Quaternion AXgrot = grot;
+ Vector3 AXimpulsei = impulsei;
+ Vector3 newimpulse = AXimpulsei * AXgrot;
+ impulse = new PhysicsVector(newimpulse.X, newimpulse.Y, newimpulse.Z);
+ }
+
+ if (m_parentGroup != null)
+ {
+ m_parentGroup.setAngularImpulse(impulse);
+ }
+ }
+
+ public Vector3 GetTorque()
+ {
+ if (m_parentGroup != null)
+ {
+ m_parentGroup.GetTorque();
+ }
+ return Vector3.Zero;
+ }
+
///
/// Apply physics to this part.
///
--
cgit v1.1