From 18c959df12983256d73240a86fa0bad12c4e36ce Mon Sep 17 00:00:00 2001
From: Teravus Ovares
Date: Thu, 17 Jan 2008 14:59:05 +0000
Subject: * Added llApplyImpulse in the global frame. The object must be
physical before this'll do anything. Be careful with this function as it's
easy to loose prim.
---
.../Region/Environment/Scenes/SceneObjectGroup.cs | 10 +++++++
.../Region/Environment/Scenes/SceneObjectPart.cs | 15 +++++++++++
OpenSim/Region/Physics/OdePlugin/ODEPrim.cs | 31 ++++++++++++++++++++++
.../ScriptEngine/Common/LSL_BuiltIn_Commands.cs | 17 +++++++++++-
4 files changed, 72 insertions(+), 1 deletion(-)
(limited to 'OpenSim/Region')
diff --git a/OpenSim/Region/Environment/Scenes/SceneObjectGroup.cs b/OpenSim/Region/Environment/Scenes/SceneObjectGroup.cs
index 6447403..5790591 100644
--- a/OpenSim/Region/Environment/Scenes/SceneObjectGroup.cs
+++ b/OpenSim/Region/Environment/Scenes/SceneObjectGroup.cs
@@ -578,6 +578,16 @@ namespace OpenSim.Region.Environment.Scenes
SetPartAsRoot(newPart);
}
+ public void applyImpulse(PhysicsVector impulse)
+ {
+ SceneObjectPart rootpart = m_rootPart;
+ if (m_rootPart.PhysActor != null)
+ {
+ m_rootPart.PhysActor.AddForce(impulse);
+ m_scene.PhysicsScene.AddPhysicsActorTaint(m_rootPart.PhysActor);
+ }
+ }
+
public void SetRootPartOwner(SceneObjectPart part, LLUUID cAgentID, LLUUID cGroupID)
{
part.LastOwnerID = part.OwnerID;
diff --git a/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs b/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs
index 0cb4ae7..ce38bee 100644
--- a/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs
+++ b/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs
@@ -520,6 +520,21 @@ namespace OpenSim.Region.Environment.Scenes
protected PrimitiveBaseShape m_shape;
+ ///
+ /// hook to the physics scene to apply 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
+ public void ApplyImpulse(LLVector3 impulsei)
+ {
+ PhysicsVector impulse = new PhysicsVector(impulsei.X, impulsei.Y, impulsei.Z);
+ if (m_parentGroup != null)
+ {
+ m_parentGroup.applyImpulse(impulse);
+ }
+ }
+
public void TriggerScriptChangedEvent(Changed val)
{
if (m_parentGroup != null)
diff --git a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs
index 6d08f98..bf88fc4 100644
--- a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs
+++ b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs
@@ -27,6 +27,7 @@
*/
using System;
+using System.Collections.Generic;
using Axiom.Math;
using Ode.NET;
using OpenSim.Framework;
@@ -51,6 +52,9 @@ namespace OpenSim.Region.Physics.OdePlugin
private bool m_taintPhysics = false;
public bool m_taintremove = false;
+ private bool m_taintforce = false;
+ private List m_forcelist = new List();
+
private IMesh _mesh;
private PrimitiveBaseShape _pbs;
private OdeScene _parent_scene;
@@ -355,6 +359,9 @@ namespace OpenSim.Region.Physics.OdePlugin
if (m_taintshape)
changeshape(timestep);
//
+
+ if (m_taintforce)
+ changeAddForce(timestep);
}
public void Move(float timestep)
@@ -541,6 +548,27 @@ namespace OpenSim.Region.Physics.OdePlugin
m_taintshape = false;
}
+ public void changeAddForce(float timestamp)
+ {
+ lock (m_forcelist)
+ {
+ //OpenSim.Framework.Console.MainLog.Instance.Verbose("PHYSICS", "dequeing forcelist");
+ if (IsPhysical)
+ {
+ PhysicsVector iforce = new PhysicsVector();
+ for (int i = 0; i < m_forcelist.Count; i++)
+ {
+ iforce = iforce + (m_forcelist[i]*100);
+ }
+ d.BodyEnable(Body);
+ d.BodyAddForce(Body, iforce.X, iforce.Y, iforce.Z);
+ }
+ m_forcelist.Clear();
+ }
+ m_taintforce = false;
+
+ }
+
public override bool IsPhysical
{
get { return m_isphysical; }
@@ -663,6 +691,9 @@ namespace OpenSim.Region.Physics.OdePlugin
public override void AddForce(PhysicsVector force)
{
+ m_forcelist.Add(force);
+ m_taintforce = true;
+ //OpenSim.Framework.Console.MainLog.Instance.Verbose("PHYSICS", "Added Force:" + force.ToString() + " to prim at " + Position.ToString());
}
public override PhysicsVector RotationalVelocity
diff --git a/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs b/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs
index 1400617..c196322 100644
--- a/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs
+++ b/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs
@@ -792,7 +792,22 @@ namespace OpenSim.Region.ScriptEngine.Common
public void llApplyImpulse(LSL_Types.Vector3 force, int local)
{
- NotImplemented("llApplyImpulse");
+ //No energy force yet
+ if (local == 1)
+ {
+ NotImplemented("llApplyImpulse Local Force");
+ }
+ else
+ {
+ if (force.x > 20000)
+ force.x = 20000;
+ if (force.y > 20000)
+ force.y = 20000;
+ if (force.z > 20000)
+ force.z = 20000;
+
+ m_host.ApplyImpulse(new LLVector3((float)force.x,(float)force.y,(float)force.z));
+ }
}
public void llApplyRotationalImpulse(LSL_Types.Vector3 force, int local)
--
cgit v1.1