From f74a9bcdc7b0682c1c205e9d640fbfa5f214840b Mon Sep 17 00:00:00 2001 From: Dahlia Trimble Date: Thu, 24 Jul 2008 07:45:58 +0000 Subject: Implements llSetForce() and llGetForce(). These are experimental and the units may not match the Linden implementation. --- .../Region/Environment/Scenes/SceneObjectPart.cs | 16 +++++++++++ .../BasicPhysicsPlugin/BasicPhysicsPlugin.cs | 1 + .../Region/Physics/BulletXPlugin/BulletXPlugin.cs | 1 + OpenSim/Region/Physics/Manager/PhysicsActor.cs | 3 +- OpenSim/Region/Physics/OdePlugin/ODECharacter.cs | 1 + OpenSim/Region/Physics/OdePlugin/ODEPrim.cs | 10 +++++-- OpenSim/Region/Physics/POSPlugin/POSCharacter.cs | 1 + OpenSim/Region/Physics/POSPlugin/POSPrim.cs | 1 + OpenSim/Region/Physics/PhysXPlugin/PhysXPlugin.cs | 2 ++ .../ScriptEngine/Common/LSL_BuiltIn_Commands.cs | 33 ++++++++++++++++++++-- .../Shared/Api/Implementation/LSL_Api.cs | 33 ++++++++++++++++++++-- 11 files changed, 92 insertions(+), 10 deletions(-) (limited to 'OpenSim/Region') diff --git a/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs b/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs index f0b1686..a9709b1 100644 --- a/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs +++ b/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs @@ -1374,6 +1374,14 @@ namespace OpenSim.Region.Environment.Scenes } } + public PhysicsVector GetForce() + { + if (PhysActor != null) + return PhysActor.Force; + else + return new PhysicsVector(); + } + [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.SerializationFormatter)] public virtual void GetObjectData( @@ -2296,6 +2304,14 @@ namespace OpenSim.Region.Environment.Scenes } } + public void SetForce(PhysicsVector force) + { + if (PhysActor != null) + { + PhysActor.Force = force; + } + } + public void SetGroup(LLUUID groupID, IClientAPI client) { _groupID = groupID; diff --git a/OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsPlugin.cs b/OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsPlugin.cs index ee30e54..213f1d4 100644 --- a/OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsPlugin.cs +++ b/OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsPlugin.cs @@ -332,6 +332,7 @@ namespace OpenSim.Region.Physics.BasicPhysicsPlugin public override PhysicsVector Force { get { return PhysicsVector.Zero; } + set { return; } } public override PhysicsVector CenterOfMass diff --git a/OpenSim/Region/Physics/BulletXPlugin/BulletXPlugin.cs b/OpenSim/Region/Physics/BulletXPlugin/BulletXPlugin.cs index 5ef196f..cc55f6e 100644 --- a/OpenSim/Region/Physics/BulletXPlugin/BulletXPlugin.cs +++ b/OpenSim/Region/Physics/BulletXPlugin/BulletXPlugin.cs @@ -943,6 +943,7 @@ namespace OpenSim.Region.Physics.BulletXPlugin public override PhysicsVector Force { get { return PhysicsVector.Zero; } + set { return; } } public override PhysicsVector CenterOfMass diff --git a/OpenSim/Region/Physics/Manager/PhysicsActor.cs b/OpenSim/Region/Physics/Manager/PhysicsActor.cs index 22e21a5..beca4da 100644 --- a/OpenSim/Region/Physics/Manager/PhysicsActor.cs +++ b/OpenSim/Region/Physics/Manager/PhysicsActor.cs @@ -173,7 +173,7 @@ namespace OpenSim.Region.Physics.Manager public abstract PhysicsVector Position { get; set; } public abstract float Mass { get; } - public abstract PhysicsVector Force { get; } + public abstract PhysicsVector Force { get; set; } public abstract PhysicsVector GeometricCenter { get; } public abstract PhysicsVector CenterOfMass { get; } public abstract PhysicsVector Velocity { get; set; } @@ -277,6 +277,7 @@ namespace OpenSim.Region.Physics.Manager public override PhysicsVector Force { get { return PhysicsVector.Zero; } + set { return; } } public override PhysicsVector CenterOfMass diff --git a/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs b/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs index 7f08cb4..5d3e986 100644 --- a/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs +++ b/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs @@ -534,6 +534,7 @@ namespace OpenSim.Region.Physics.OdePlugin public override PhysicsVector Force { get { return new PhysicsVector(_target_velocity.X, _target_velocity.Y, _target_velocity.Z); } + set { return; } } public override PhysicsVector CenterOfMass diff --git a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs index 59655d7..a4c0d79 100644 --- a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs +++ b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs @@ -103,6 +103,7 @@ namespace OpenSim.Region.Physics.OdePlugin private CollisionLocker ode; private bool m_taintforce = false; + private PhysicsVector m_force = new PhysicsVector(0.0f, 0.0f, 0.0f); private List m_forcelist = new List(); private IMesh _mesh; @@ -749,7 +750,7 @@ namespace OpenSim.Region.Physics.OdePlugin changeshape(timestep); // - if (m_taintforce) + if (m_taintforce || m_force != new PhysicsVector(0.0f, 0.0f, 0.0f)) changeAddForce(timestep); if (m_taintdisable) @@ -1751,7 +1752,8 @@ namespace OpenSim.Region.Physics.OdePlugin //m_log.Info("[PHYSICS]: dequeing forcelist"); if (IsPhysical) { - PhysicsVector iforce = new PhysicsVector(); + //PhysicsVector iforce = new PhysicsVector(); + PhysicsVector iforce = m_force * 100.0f; for (int i = 0; i < m_forcelist.Count; i++) { iforce = iforce + (m_forcelist[i] * 100); @@ -1856,7 +1858,9 @@ namespace OpenSim.Region.Physics.OdePlugin public override PhysicsVector Force { - get { return PhysicsVector.Zero; } + //get { return PhysicsVector.Zero; } + get { return m_force; } + set { m_force = value; } } public override PhysicsVector CenterOfMass diff --git a/OpenSim/Region/Physics/POSPlugin/POSCharacter.cs b/OpenSim/Region/Physics/POSPlugin/POSCharacter.cs index d146b60..c674d15 100644 --- a/OpenSim/Region/Physics/POSPlugin/POSCharacter.cs +++ b/OpenSim/Region/Physics/POSPlugin/POSCharacter.cs @@ -156,6 +156,7 @@ namespace OpenSim.Region.Physics.POSPlugin public override PhysicsVector Force { get { return PhysicsVector.Zero; } + set { return; } } public override PhysicsVector CenterOfMass diff --git a/OpenSim/Region/Physics/POSPlugin/POSPrim.cs b/OpenSim/Region/Physics/POSPlugin/POSPrim.cs index c767917..fed67dd 100644 --- a/OpenSim/Region/Physics/POSPlugin/POSPrim.cs +++ b/OpenSim/Region/Physics/POSPlugin/POSPrim.cs @@ -118,6 +118,7 @@ namespace OpenSim.Region.Physics.POSPlugin public override PhysicsVector Force { get { return PhysicsVector.Zero; } + set { return; } } public override PhysicsVector CenterOfMass diff --git a/OpenSim/Region/Physics/PhysXPlugin/PhysXPlugin.cs b/OpenSim/Region/Physics/PhysXPlugin/PhysXPlugin.cs index c9e1e30..197da0a 100644 --- a/OpenSim/Region/Physics/PhysXPlugin/PhysXPlugin.cs +++ b/OpenSim/Region/Physics/PhysXPlugin/PhysXPlugin.cs @@ -340,6 +340,7 @@ namespace OpenSim.Region.Physics.PhysXPlugin public override PhysicsVector Force { get { return PhysicsVector.Zero; } + set { return; } } public override PhysicsVector CenterOfMass @@ -669,6 +670,7 @@ namespace OpenSim.Region.Physics.PhysXPlugin public override PhysicsVector Force { get { return PhysicsVector.Zero; } + set { return; } } public override PhysicsVector CenterOfMass diff --git a/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs b/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs index 2d5be27..1a60f45 100644 --- a/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs +++ b/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs @@ -42,6 +42,7 @@ using OpenSim.Region.Environment.Interfaces; using OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney; using OpenSim.Region.Environment.Modules.World.Land; using OpenSim.Region.Environment.Scenes; +using OpenSim.Region.Physics.Manager; using OpenSim.Region.ScriptEngine.Common.ScriptEngineBase; //using OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL; @@ -1578,14 +1579,40 @@ namespace OpenSim.Region.ScriptEngine.Common public void llSetForce(LSL_Types.Vector3 force, int local) { m_host.AddScriptLPS(1); - NotImplemented("llSetForce"); + //NotImplemented("llSetForce"); + + if (m_host.ParentGroup != null) + { + if (m_host.ParentGroup.RootPart != null) + { + if (local != 0) + force *= llGetRot(); + + m_host.ParentGroup.RootPart.SetForce(new PhysicsVector((float)force.x, (float)force.y, (float)force.z)); + } + } } public LSL_Types.Vector3 llGetForce() { + LSL_Types.Vector3 force = new LSL_Types.Vector3(0.0, 0.0, 0.0); + m_host.AddScriptLPS(1); - NotImplemented("llGetForce"); - return new LSL_Types.Vector3(); + //NotImplemented("llGetForce"); + //return new LSL_Types.Vector3(); + + if (m_host.ParentGroup != null) + { + if (m_host.ParentGroup.RootPart != null) + { + PhysicsVector tmpForce = m_host.ParentGroup.RootPart.GetForce(); + force.x = tmpForce.X; + force.y = tmpForce.Y; + force.z = tmpForce.Z; + } + } + + return force; } public LSL_Types.LSLInteger llTarget(LSL_Types.Vector3 position, double range) diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index 9832cfc..ed320f8 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs @@ -43,6 +43,7 @@ using OpenSim.Region.Environment.Interfaces; using OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney; using OpenSim.Region.Environment.Modules.World.Land; using OpenSim.Region.Environment.Scenes; +using OpenSim.Region.Physics.Manager; using OpenSim.Region.ScriptEngine.Shared; using OpenSim.Region.ScriptEngine.Shared.Api.Plugins; using OpenSim.Region.ScriptEngine.Shared.ScriptBase; @@ -1430,14 +1431,40 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api public void llSetForce(LSL_Types.Vector3 force, int local) { m_host.AddScriptLPS(1); - NotImplemented("llSetForce"); + //NotImplemented("llSetForce"); + + if (m_host.ParentGroup != null) + { + if (m_host.ParentGroup.RootPart != null) + { + if (local != 0) + force *= llGetRot(); + + m_host.ParentGroup.RootPart.SetForce(new PhysicsVector((float)force.x, (float)force.y, (float)force.z)); + } + } } public LSL_Types.Vector3 llGetForce() { + LSL_Types.Vector3 force = new LSL_Types.Vector3(0.0, 0.0, 0.0); + m_host.AddScriptLPS(1); - NotImplemented("llGetForce"); - return new LSL_Types.Vector3(); + //NotImplemented("llGetForce"); + //return new LSL_Types.Vector3(); + + if (m_host.ParentGroup != null) + { + if (m_host.ParentGroup.RootPart != null) + { + PhysicsVector tmpForce = m_host.ParentGroup.RootPart.GetForce(); + force.x = tmpForce.X; + force.y = tmpForce.Y; + force.z = tmpForce.Z; + } + } + + return force; } public LSL_Types.LSLInteger llTarget(LSL_Types.Vector3 position, double range) -- cgit v1.1