From 134f86e8d5c414409631b25b8c6f0ee45fbd8631 Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Thu, 3 Nov 2016 21:44:39 +1000 Subject: Initial update to OpenSim 0.8.2.1 source code. --- .../PhysicsModules/SharedBase/AssemblyInfo.cs | 58 ++ .../PhysicsModules/SharedBase/CollisionLocker.cs | 73 +++ .../Region/PhysicsModules/SharedBase/IMesher.cs | 71 +++ .../SharedBase/IPhysicsParameters.cs | 73 +++ .../PhysicsModules/SharedBase/NullPhysicsScene.cs | 117 +++++ .../PhysicsModules/SharedBase/PhysicsActor.cs | 584 +++++++++++++++++++++ .../PhysicsModules/SharedBase/PhysicsJoint.cs | 55 ++ .../PhysicsModules/SharedBase/PhysicsScene.cs | 358 +++++++++++++ .../PhysicsModules/SharedBase/PhysicsSensor.cs | 78 +++ .../PhysicsModules/SharedBase/PhysicsVector.cs | 186 +++++++ .../PhysicsModules/SharedBase/VehicleConstants.cs | 121 +++++ 11 files changed, 1774 insertions(+) create mode 100644 OpenSim/Region/PhysicsModules/SharedBase/AssemblyInfo.cs create mode 100644 OpenSim/Region/PhysicsModules/SharedBase/CollisionLocker.cs create mode 100644 OpenSim/Region/PhysicsModules/SharedBase/IMesher.cs create mode 100755 OpenSim/Region/PhysicsModules/SharedBase/IPhysicsParameters.cs create mode 100644 OpenSim/Region/PhysicsModules/SharedBase/NullPhysicsScene.cs create mode 100644 OpenSim/Region/PhysicsModules/SharedBase/PhysicsActor.cs create mode 100644 OpenSim/Region/PhysicsModules/SharedBase/PhysicsJoint.cs create mode 100644 OpenSim/Region/PhysicsModules/SharedBase/PhysicsScene.cs create mode 100644 OpenSim/Region/PhysicsModules/SharedBase/PhysicsSensor.cs create mode 100644 OpenSim/Region/PhysicsModules/SharedBase/PhysicsVector.cs create mode 100644 OpenSim/Region/PhysicsModules/SharedBase/VehicleConstants.cs (limited to 'OpenSim/Region/PhysicsModules/SharedBase') diff --git a/OpenSim/Region/PhysicsModules/SharedBase/AssemblyInfo.cs b/OpenSim/Region/PhysicsModules/SharedBase/AssemblyInfo.cs new file mode 100644 index 0000000..33f60e4 --- /dev/null +++ b/OpenSim/Region/PhysicsModules/SharedBase/AssemblyInfo.cs @@ -0,0 +1,58 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSimulator Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using System.Reflection; +using System.Runtime.InteropServices; + +// Information about this assembly is defined by the following +// attributes. +// +// change them to the information which is associated with the assembly +// you compile. + +[assembly : AssemblyTitle("PhysicsManager")] +[assembly : AssemblyDescription("")] +[assembly : AssemblyConfiguration("")] +[assembly : AssemblyCompany("http://opensimulator.org")] +[assembly : AssemblyProduct("PhysicsManager")] +[assembly : AssemblyCopyright("Copyright (c) OpenSimulator.org Developers")] +[assembly : AssemblyTrademark("")] +[assembly : AssemblyCulture("")] + +// This sets the default COM visibility of types in the assembly to invisible. +// If you need to expose a type to COM, use [ComVisible(true)] on that type. + +[assembly : ComVisible(false)] + +// The assembly version has following format : +// +// Major.Minor.Build.Revision +// +// You can specify all values by your own or you can build default build and revision +// numbers with the '*' character (the default): + +[assembly : AssemblyVersion("0.8.2.*")] diff --git a/OpenSim/Region/PhysicsModules/SharedBase/CollisionLocker.cs b/OpenSim/Region/PhysicsModules/SharedBase/CollisionLocker.cs new file mode 100644 index 0000000..6e658b5 --- /dev/null +++ b/OpenSim/Region/PhysicsModules/SharedBase/CollisionLocker.cs @@ -0,0 +1,73 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSimulator Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using System; +using System.Collections.Generic; + +namespace OpenSim.Region.PhysicsModules.SharedBase +{ + public class CollisionLocker + { + private List worldlock = new List(); + + public CollisionLocker() + { + + } + + public void dlock(IntPtr world) + { + lock (worldlock) + { + worldlock.Add(world); + } + + } + + public void dunlock(IntPtr world) + { + lock (worldlock) + { + worldlock.Remove(world); + } + } + + public bool lockquery() + { + return (worldlock.Count > 0); + } + + public void drelease(IntPtr world) + { + lock (worldlock) + { + if (worldlock.Contains(world)) + worldlock.Remove(world); + } + } + } +} diff --git a/OpenSim/Region/PhysicsModules/SharedBase/IMesher.cs b/OpenSim/Region/PhysicsModules/SharedBase/IMesher.cs new file mode 100644 index 0000000..5c75307 --- /dev/null +++ b/OpenSim/Region/PhysicsModules/SharedBase/IMesher.cs @@ -0,0 +1,71 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSimulator Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using System; +using System.Collections.Generic; +using OpenSim.Framework; +using OpenMetaverse; + +namespace OpenSim.Region.PhysicsModules.SharedBase +{ + public interface IMesher + { + IMesh CreateMesh(String primName, PrimitiveBaseShape primShape, Vector3 size, float lod); + IMesh CreateMesh(String primName, PrimitiveBaseShape primShape, Vector3 size, float lod, bool isPhysical); + IMesh CreateMesh(String primName, PrimitiveBaseShape primShape, Vector3 size, float lod, bool isPhysical, bool shouldCache); + } + + // Values for level of detail to be passed to the mesher. + // Values origionally chosen for the LOD of sculpties (the sqrt(width*heigth) of sculpt texture) + // Lower level of detail reduces the number of vertices used to represent the meshed shape. + public enum LevelOfDetail + { + High = 32, + Medium = 16, + Low = 8, + VeryLow = 4 + } + + public interface IVertex + { + } + + public interface IMesh + { + List getVertexList(); + int[] getIndexListAsInt(); + int[] getIndexListAsIntLocked(); + float[] getVertexListAsFloat(); + float[] getVertexListAsFloatLocked(); + void getIndexListAsPtrToIntArray(out IntPtr indices, out int triStride, out int indexCount); + void getVertexListAsPtrToFloatArray(out IntPtr vertexList, out int vertexStride, out int vertexCount); + void releaseSourceMeshData(); + void releasePinned(); + void Append(IMesh newMesh); + void TransformLinear(float[,] matrix, float[] offset); + } +} diff --git a/OpenSim/Region/PhysicsModules/SharedBase/IPhysicsParameters.cs b/OpenSim/Region/PhysicsModules/SharedBase/IPhysicsParameters.cs new file mode 100755 index 0000000..fb0c9e2 --- /dev/null +++ b/OpenSim/Region/PhysicsModules/SharedBase/IPhysicsParameters.cs @@ -0,0 +1,73 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSimulator Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using System; +using System.Collections.Generic; +using OpenSim.Framework; +using OpenMetaverse; + +namespace OpenSim.Region.PhysicsModules.SharedBase +{ + public struct PhysParameterEntry + { + // flags to say to apply to all or no instances (I wish one could put consts into interfaces) + public const uint APPLY_TO_ALL = 0xfffffff3; + public const uint APPLY_TO_NONE = 0xfffffff4; + + // values that denote true and false values + public const float NUMERIC_TRUE = 1f; + public const float NUMERIC_FALSE = 0f; + + public string name; + public string desc; + + public PhysParameterEntry(string n, string d) + { + name = n; + desc = d; + } + } + + // Interface for a physics scene that implements the runtime setting and getting of physics parameters + public interface IPhysicsParameters + { + // Get the list of parameters this physics engine supports + PhysParameterEntry[] GetParameterList(); + + // Set parameter on a specific or all instances. + // Return 'false' if not able to set the parameter. + bool SetPhysicsParameter(string parm, string value, uint localID); + + // Get parameter. + // Return 'false' if not able to get the parameter. + bool GetPhysicsParameter(string parm, out string value); + + // Get parameter from a particular object + // TODO: + // bool GetPhysicsParameter(string parm, out string value, uint localID); + } +} diff --git a/OpenSim/Region/PhysicsModules/SharedBase/NullPhysicsScene.cs b/OpenSim/Region/PhysicsModules/SharedBase/NullPhysicsScene.cs new file mode 100644 index 0000000..432708c --- /dev/null +++ b/OpenSim/Region/PhysicsModules/SharedBase/NullPhysicsScene.cs @@ -0,0 +1,117 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSimulator Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using System.Collections.Generic; +using System.Reflection; +using log4net; +using Nini.Config; +using OpenSim.Framework; +using OpenMetaverse; + +namespace OpenSim.Region.PhysicsModules.SharedBase +{ + class NullPhysicsScene : PhysicsScene + { + private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + + private static int m_workIndicator; + + public override PhysicsActor AddAvatar( + string avName, Vector3 position, Vector3 velocity, Vector3 size, bool isFlying) + { + m_log.InfoFormat("[PHYSICS]: NullPhysicsScene : AddAvatar({0})", position); + return PhysicsActor.Null; + } + + public override void RemoveAvatar(PhysicsActor actor) + { + } + + public override void RemovePrim(PhysicsActor prim) + { + } + public override void SetWaterLevel(float baseheight) + { + + } + +/* + public override PhysicsActor AddPrim(Vector3 position, Vector3 size, Quaternion rotation) + { + m_log.InfoFormat("NullPhysicsScene : AddPrim({0},{1})", position, size); + return PhysicsActor.Null; + } +*/ + + public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, Vector3 position, + Vector3 size, Quaternion rotation, bool isPhysical, uint localid) + { + m_log.InfoFormat("[PHYSICS]: NullPhysicsScene : AddPrim({0},{1})", position, size); + return PhysicsActor.Null; + } + + public override void AddPhysicsActorTaint(PhysicsActor prim) + { + } + + public override float Simulate(float timeStep) + { + m_workIndicator = (m_workIndicator + 1) % 10; + + return 0f; + } + + public override void GetResults() + { + m_log.Info("[PHYSICS]: NullPhysicsScene : GetResults()"); + } + + public override void SetTerrain(float[] heightMap) + { + m_log.InfoFormat("[PHYSICS]: NullPhysicsScene : SetTerrain({0} items)", heightMap.Length); + } + + public override void DeleteTerrain() + { + } + + public override bool IsThreaded + { + get { return false; } + } + + public override void Dispose() + { + } + + public override Dictionary GetTopColliders() + { + Dictionary returncolliders = new Dictionary(); + return returncolliders; + } + } +} \ No newline at end of file diff --git a/OpenSim/Region/PhysicsModules/SharedBase/PhysicsActor.cs b/OpenSim/Region/PhysicsModules/SharedBase/PhysicsActor.cs new file mode 100644 index 0000000..c04ff58 --- /dev/null +++ b/OpenSim/Region/PhysicsModules/SharedBase/PhysicsActor.cs @@ -0,0 +1,584 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSimulator Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using log4net; +using System; +using System.Collections.Generic; +using System.Reflection; +using OpenSim.Framework; +using OpenMetaverse; + +namespace OpenSim.Region.PhysicsModules.SharedBase +{ + public delegate void PositionUpdate(Vector3 position); + public delegate void VelocityUpdate(Vector3 velocity); + public delegate void OrientationUpdate(Quaternion orientation); + + public enum ActorTypes : int + { + Unknown = 0, + Agent = 1, + Prim = 2, + Ground = 3 + } + + public enum PIDHoverType + { + Ground, + GroundAndWater, + Water, + Absolute + } + + public struct ContactPoint + { + public Vector3 Position; + public Vector3 SurfaceNormal; + public float PenetrationDepth; + + public ContactPoint(Vector3 position, Vector3 surfaceNormal, float penetrationDepth) + { + Position = position; + SurfaceNormal = surfaceNormal; + PenetrationDepth = penetrationDepth; + } + } + + /// + /// Used to pass collision information to OnCollisionUpdate listeners. + /// + public class CollisionEventUpdate : EventArgs + { + /// + /// Number of collision events in this update. + /// + public int Count { get { return m_objCollisionList.Count; } } + + public bool CollisionsOnPreviousFrame { get; private set; } + + public Dictionary m_objCollisionList; + + public CollisionEventUpdate(Dictionary objCollisionList) + { + m_objCollisionList = objCollisionList; + } + + public CollisionEventUpdate() + { + m_objCollisionList = new Dictionary(); + } + + public void AddCollider(uint localID, ContactPoint contact) + { + if (!m_objCollisionList.ContainsKey(localID)) + { + m_objCollisionList.Add(localID, contact); + } + else + { + if (m_objCollisionList[localID].PenetrationDepth < contact.PenetrationDepth) + m_objCollisionList[localID] = contact; + } + } + + /// + /// Clear added collision events. + /// + public void Clear() + { + m_objCollisionList.Clear(); + } + } + + public abstract class PhysicsActor + { +// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + + public delegate void RequestTerseUpdate(); + public delegate void CollisionUpdate(EventArgs e); + public delegate void OutOfBounds(Vector3 pos); + +// disable warning: public events +#pragma warning disable 67 + public event PositionUpdate OnPositionUpdate; + public event VelocityUpdate OnVelocityUpdate; + public event OrientationUpdate OnOrientationUpdate; + public event RequestTerseUpdate OnRequestTerseUpdate; + + /// + /// Subscribers to this event must synchronously handle the dictionary of collisions received, since the event + /// object is reused in subsequent physics frames. + /// + public event CollisionUpdate OnCollisionUpdate; + + public event OutOfBounds OnOutOfBounds; +#pragma warning restore 67 + + public static PhysicsActor Null + { + get { return new NullPhysicsActor(); } + } + + public abstract bool Stopped { get; } + + public abstract Vector3 Size { get; set; } + + public virtual byte PhysicsShapeType { get; set; } + + public abstract PrimitiveBaseShape Shape { set; } + + uint m_baseLocalID; + public virtual uint LocalID + { + set { m_baseLocalID = value; } + get { return m_baseLocalID; } + } + + public abstract bool Grabbed { set; } + + public abstract bool Selected { set; } + + /// + /// Name of this actor. + /// + /// + /// XXX: Bizarrely, this cannot be "Terrain" or "Water" right now unless it really is simulating terrain or + /// water. This is not a problem due to the formatting of names given by prims and avatars. + /// + public string Name { get; protected set; } + + /// + /// This is being used by ODE joint code. + /// + public string SOPName; + + public abstract void CrossingFailure(); + + public abstract void link(PhysicsActor obj); + + public abstract void delink(); + + public abstract void LockAngularMotion(Vector3 axis); + + public virtual void RequestPhysicsterseUpdate() + { + // Make a temporary copy of the event to avoid possibility of + // a race condition if the last subscriber unsubscribes + // immediately after the null check and before the event is raised. + RequestTerseUpdate handler = OnRequestTerseUpdate; + + if (handler != null) + { + handler(); + } + } + + public virtual void RaiseOutOfBounds(Vector3 pos) + { + // Make a temporary copy of the event to avoid possibility of + // a race condition if the last subscriber unsubscribes + // immediately after the null check and before the event is raised. + OutOfBounds handler = OnOutOfBounds; + + if (handler != null) + { + handler(pos); + } + } + + public virtual void SendCollisionUpdate(EventArgs e) + { + CollisionUpdate handler = OnCollisionUpdate; + +// m_log.DebugFormat("[PHYSICS ACTOR]: Sending collision for {0}", LocalID); + + if (handler != null) + handler(e); + } + + public virtual void SetMaterial (int material) { } + public virtual float Density { get; set; } + public virtual float GravModifier { get; set; } + public virtual float Friction { get; set; } + public virtual float Restitution { get; set; } + + /// + /// Position of this actor. + /// + /// + /// Setting this directly moves the actor to a given position. + /// Getting this retrieves the position calculated by physics scene updates, using factors such as velocity and + /// collisions. + /// + public abstract Vector3 Position { get; set; } + + public abstract float Mass { get; } + public abstract Vector3 Force { get; set; } + + public abstract int VehicleType { get; set; } + public abstract void VehicleFloatParam(int param, float value); + public abstract void VehicleVectorParam(int param, Vector3 value); + public abstract void VehicleRotationParam(int param, Quaternion rotation); + public abstract void VehicleFlags(int param, bool remove); + + /// + /// Allows the detection of collisions with inherently non-physical prims. see llVolumeDetect for more + /// + public abstract void SetVolumeDetect(int param); + + public abstract Vector3 GeometricCenter { get; } + public abstract Vector3 CenterOfMass { get; } + + /// + /// The desired velocity of this actor. + /// + /// + /// Setting this provides a target velocity for physics scene updates. + /// Getting this returns the last set target. Fetch Velocity to get the current velocity. + /// + protected Vector3 m_targetVelocity; + public virtual Vector3 TargetVelocity + { + get { return m_targetVelocity; } + set { + m_targetVelocity = value; + Velocity = m_targetVelocity; + } + } + + public abstract Vector3 Velocity { get; set; } + + public abstract Vector3 Torque { get; set; } + public abstract float CollisionScore { get; set;} + public abstract Vector3 Acceleration { get; set; } + public abstract Quaternion Orientation { get; set; } + public abstract int PhysicsActorType { get; set; } + public abstract bool IsPhysical { get; set; } + public abstract bool Flying { get; set; } + public abstract bool SetAlwaysRun { get; set; } + public abstract bool ThrottleUpdates { get; set; } + public abstract bool IsColliding { get; set; } + public abstract bool CollidingGround { get; set; } + public abstract bool CollidingObj { get; set; } + public abstract bool FloatOnWater { set; } + public abstract Vector3 RotationalVelocity { get; set; } + public abstract bool Kinematic { get; set; } + public abstract float Buoyancy { get; set; } + + // Used for MoveTo + public abstract Vector3 PIDTarget { set; } + public abstract bool PIDActive { get; set; } + public abstract float PIDTau { set; } + + // Used for llSetHoverHeight and maybe vehicle height + // Hover Height will override MoveTo target's Z + public abstract bool PIDHoverActive { set;} + public abstract float PIDHoverHeight { set;} + public abstract PIDHoverType PIDHoverType { set;} + public abstract float PIDHoverTau { set;} + + // For RotLookAt + public abstract Quaternion APIDTarget { set;} + public abstract bool APIDActive { set;} + public abstract float APIDStrength { set;} + public abstract float APIDDamping { set;} + + public abstract void AddForce(Vector3 force, bool pushforce); + public abstract void AddAngularForce(Vector3 force, bool pushforce); + public abstract void SetMomentum(Vector3 momentum); + public abstract void SubscribeEvents(int ms); + public abstract void UnSubscribeEvents(); + public abstract bool SubscribedEvents(); + + // Extendable interface for new, physics engine specific operations + public virtual object Extension(string pFunct, params object[] pParams) + { + // A NOP of the physics engine does not implement this feature + return null; + } + } + + public class NullPhysicsActor : PhysicsActor + { + public override bool Stopped + { + get{ return false; } + } + + public override Vector3 Position + { + get { return Vector3.Zero; } + set { return; } + } + + public override bool SetAlwaysRun + { + get { return false; } + set { return; } + } + + public override uint LocalID + { + set { return; } + } + + public override bool Grabbed + { + set { return; } + } + + public override bool Selected + { + set { return; } + } + + public override float Buoyancy + { + get { return 0f; } + set { return; } + } + + public override bool FloatOnWater + { + set { return; } + } + + public override bool CollidingGround + { + get { return false; } + set { return; } + } + + public override bool CollidingObj + { + get { return false; } + set { return; } + } + + public override Vector3 Size + { + get { return Vector3.Zero; } + set { return; } + } + + public override float Mass + { + get { return 0f; } + } + + public override Vector3 Force + { + get { return Vector3.Zero; } + set { return; } + } + + public override int VehicleType + { + get { return 0; } + set { return; } + } + + public override void VehicleFloatParam(int param, float value) + { + + } + + public override void VehicleVectorParam(int param, Vector3 value) + { + + } + + public override void VehicleRotationParam(int param, Quaternion rotation) + { + + } + + public override void VehicleFlags(int param, bool remove) + { + + } + + public override void SetVolumeDetect(int param) + { + + } + + public override void SetMaterial(int material) + { + + } + + public override Vector3 CenterOfMass + { + get { return Vector3.Zero; } + } + + public override Vector3 GeometricCenter + { + get { return Vector3.Zero; } + } + + public override PrimitiveBaseShape Shape + { + set { return; } + } + + public override Vector3 Velocity + { + get { return Vector3.Zero; } + set { return; } + } + + public override Vector3 Torque + { + get { return Vector3.Zero; } + set { return; } + } + + public override float CollisionScore + { + get { return 0f; } + set { } + } + + public override void CrossingFailure() + { + } + + public override Quaternion Orientation + { + get { return Quaternion.Identity; } + set { } + } + + public override Vector3 Acceleration + { + get { return Vector3.Zero; } + set { } + } + + public override bool IsPhysical + { + get { return false; } + set { return; } + } + + public override bool Flying + { + get { return false; } + set { return; } + } + + public override bool ThrottleUpdates + { + get { return false; } + set { return; } + } + + public override bool IsColliding + { + get { return false; } + set { return; } + } + + public override int PhysicsActorType + { + get { return (int) ActorTypes.Unknown; } + set { return; } + } + + public override bool Kinematic + { + get { return true; } + set { return; } + } + + public override void link(PhysicsActor obj) + { + } + + public override void delink() + { + } + + public override void LockAngularMotion(Vector3 axis) + { + } + + public override void AddForce(Vector3 force, bool pushforce) + { + } + + public override void AddAngularForce(Vector3 force, bool pushforce) + { + + } + + public override Vector3 RotationalVelocity + { + get { return Vector3.Zero; } + set { return; } + } + + public override Vector3 PIDTarget { set { return; } } + + public override bool PIDActive + { + get { return false; } + set { return; } + } + + public override float PIDTau { set { return; } } + + public override float PIDHoverHeight { set { return; } } + public override bool PIDHoverActive { set { return; } } + public override PIDHoverType PIDHoverType { set { return; } } + public override float PIDHoverTau { set { return; } } + + public override Quaternion APIDTarget { set { return; } } + public override bool APIDActive { set { return; } } + public override float APIDStrength { set { return; } } + public override float APIDDamping { set { return; } } + + public override void SetMomentum(Vector3 momentum) + { + } + + public override void SubscribeEvents(int ms) + { + + } + public override void UnSubscribeEvents() + { + + } + public override bool SubscribedEvents() + { + return false; + } + } +} diff --git a/OpenSim/Region/PhysicsModules/SharedBase/PhysicsJoint.cs b/OpenSim/Region/PhysicsModules/SharedBase/PhysicsJoint.cs new file mode 100644 index 0000000..ce2bf05 --- /dev/null +++ b/OpenSim/Region/PhysicsModules/SharedBase/PhysicsJoint.cs @@ -0,0 +1,55 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSimulator Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using System; +using System.Collections.Generic; +using OpenSim.Framework; +using OpenMetaverse; + +namespace OpenSim.Region.PhysicsModules.SharedBase +{ + public enum PhysicsJointType : int + { + Ball = 0, + Hinge = 1 + } + + public class PhysicsJoint + { + public virtual bool IsInPhysicsEngine { get { return false; } } // set internally to indicate if this joint has already been passed to the physics engine or is still pending + public PhysicsJointType Type; + public string RawParams; + public List BodyNames = new List(); + public Vector3 Position; // global coords + public Quaternion Rotation; // global coords + public string ObjectNameInScene; // proxy object in scene that represents the joint position/orientation + public string TrackedBodyName; // body name that this joint is attached to (ObjectNameInScene will follow TrackedBodyName) + public Quaternion LocalRotation; // joint orientation relative to one of the involved bodies, the tracked body + public int ErrorMessageCount; // total # of error messages printed for this joint since its creation. if too many, further error messages are suppressed to prevent flooding. + public const int maxErrorMessages = 100; // no more than this # of error messages will be printed for each joint + } +} diff --git a/OpenSim/Region/PhysicsModules/SharedBase/PhysicsScene.cs b/OpenSim/Region/PhysicsModules/SharedBase/PhysicsScene.cs new file mode 100644 index 0000000..32691fc --- /dev/null +++ b/OpenSim/Region/PhysicsModules/SharedBase/PhysicsScene.cs @@ -0,0 +1,358 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSimulator Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using System; +using System.Collections.Generic; +using System.Reflection; + +using log4net; +using Nini.Config; + +using OpenSim.Framework; +using OpenMetaverse; + +namespace OpenSim.Region.PhysicsModules.SharedBase +{ + public delegate void physicsCrash(); + + public delegate void RaycastCallback(bool hitYN, Vector3 collisionPoint, uint localid, float distance, Vector3 normal); + public delegate void RayCallback(List list); + + public delegate void JointMoved(PhysicsJoint joint); + public delegate void JointDeactivated(PhysicsJoint joint); + public delegate void JointErrorMessage(PhysicsJoint joint, string message); // this refers to an "error message due to a problem", not "amount of joint constraint violation" + + public enum RayFilterFlags : ushort + { + // the flags + water = 0x01, + land = 0x02, + agent = 0x04, + nonphysical = 0x08, + physical = 0x10, + phantom = 0x20, + volumedtc = 0x40, + + // ray cast colision control (may only work for meshs) + ContactsUnImportant = 0x2000, + BackFaceCull = 0x4000, + ClosestHit = 0x8000, + + // some combinations + LSLPhantom = phantom | volumedtc, + PrimsNonPhantom = nonphysical | physical, + PrimsNonPhantomAgents = nonphysical | physical | agent, + + AllPrims = nonphysical | phantom | volumedtc | physical, + AllButLand = agent | nonphysical | physical | phantom | volumedtc, + + ClosestAndBackCull = ClosestHit | BackFaceCull, + + All = 0x3f + } + + public delegate void RequestAssetDelegate(UUID assetID, AssetReceivedDelegate callback); + public delegate void AssetReceivedDelegate(AssetBase asset); + + /// + /// Contact result from a raycast. + /// + public struct ContactResult + { + public Vector3 Pos; + public float Depth; + public uint ConsumerID; + public Vector3 Normal; + } + + public abstract class PhysicsScene + { +// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + + /// + /// A unique identifying string for this instance of the physics engine. + /// Useful in debug messages to distinguish one OdeScene instance from another. + /// Usually set to include the region name that the physics engine is acting for. + /// + public string PhysicsSceneName { get; protected set; } + + /// + /// A string identifying the family of this physics engine. Most common values returned + /// are "OpenDynamicsEngine" and "BulletSim" but others are possible. + /// + public string EngineType { get; protected set; } + + // The only thing that should register for this event is the SceneGraph + // Anything else could cause problems. + public event physicsCrash OnPhysicsCrash; + + public static PhysicsScene Null + { + get { return new NullPhysicsScene(); } + } + + public RequestAssetDelegate RequestAssetMethod { get; set; } + + protected void Initialise(RequestAssetDelegate m, float[] terrain, float waterHeight) + { + RequestAssetMethod = m; + SetTerrain(terrain); + SetWaterLevel(waterHeight); + + } + + public virtual void TriggerPhysicsBasedRestart() + { + physicsCrash handler = OnPhysicsCrash; + if (handler != null) + { + OnPhysicsCrash(); + } + } + + /// + /// Add an avatar + /// + /// + /// + /// + /// + /// + /// + public abstract PhysicsActor AddAvatar( + string avName, Vector3 position, Vector3 velocity, Vector3 size, bool isFlying); + + /// + /// Add an avatar + /// + /// + /// + /// + /// + /// + /// + /// + public virtual PhysicsActor AddAvatar( + uint localID, string avName, Vector3 position, Vector3 velocity, Vector3 size, bool isFlying) + { + PhysicsActor ret = AddAvatar(avName, position, velocity, size, isFlying); + + if (ret != null) + ret.LocalID = localID; + + return ret; + } + + /// + /// Remove an avatar. + /// + /// + public abstract void RemoveAvatar(PhysicsActor actor); + + /// + /// Remove a prim. + /// + /// + public abstract void RemovePrim(PhysicsActor prim); + + public abstract PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, Vector3 position, + Vector3 size, Quaternion rotation, bool isPhysical, uint localid); + + public virtual PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, Vector3 position, + Vector3 size, Quaternion rotation, bool isPhysical, bool isPhantom, byte shapetype, uint localid) + { + return AddPrimShape(primName, pbs, position, size, rotation, isPhysical, localid); + } + + public virtual float TimeDilation + { + get { return 1.0f; } + } + + public virtual bool SupportsNINJAJoints + { + get { return false; } + } + + public virtual PhysicsJoint RequestJointCreation(string objectNameInScene, PhysicsJointType jointType, Vector3 position, + Quaternion rotation, string parms, List bodyNames, string trackedBodyName, Quaternion localRotation) + { return null; } + + public virtual void RequestJointDeletion(string objectNameInScene) + { return; } + + public virtual void RemoveAllJointsConnectedToActorThreadLocked(PhysicsActor actor) + { return; } + + public virtual void DumpJointInfo() + { return; } + + public event JointMoved OnJointMoved; + + protected virtual void DoJointMoved(PhysicsJoint joint) + { + // We need this to allow subclasses (but not other classes) to invoke the event; C# does + // not allow subclasses to invoke the parent class event. + if (OnJointMoved != null) + { + OnJointMoved(joint); + } + } + + public event JointDeactivated OnJointDeactivated; + + protected virtual void DoJointDeactivated(PhysicsJoint joint) + { + // We need this to allow subclasses (but not other classes) to invoke the event; C# does + // not allow subclasses to invoke the parent class event. + if (OnJointDeactivated != null) + { + OnJointDeactivated(joint); + } + } + + public event JointErrorMessage OnJointErrorMessage; + + protected virtual void DoJointErrorMessage(PhysicsJoint joint, string message) + { + // We need this to allow subclasses (but not other classes) to invoke the event; C# does + // not allow subclasses to invoke the parent class event. + if (OnJointErrorMessage != null) + { + OnJointErrorMessage(joint, message); + } + } + + public virtual Vector3 GetJointAnchor(PhysicsJoint joint) + { return Vector3.Zero; } + + public virtual Vector3 GetJointAxis(PhysicsJoint joint) + { return Vector3.Zero; } + + public abstract void AddPhysicsActorTaint(PhysicsActor prim); + + /// + /// Perform a simulation of the current physics scene over the given timestep. + /// + /// + /// The number of frames simulated over that period. + public abstract float Simulate(float timeStep); + + /// + /// Get statistics about this scene. + /// + /// This facility is currently experimental and subject to change. + /// + /// A dictionary where the key is the statistic name. If no statistics are supplied then returns null. + /// + public virtual Dictionary GetStats() { return null; } + + public abstract void GetResults(); + + public abstract void SetTerrain(float[] heightMap); + + public abstract void SetWaterLevel(float baseheight); + + public abstract void DeleteTerrain(); + + public abstract void Dispose(); + + public abstract Dictionary GetTopColliders(); + + public abstract bool IsThreaded { get; } + + /// + /// True if the physics plugin supports raycasting against the physics scene + /// + public virtual bool SupportsRayCast() + { + return false; + } + + public virtual bool SupportsCombining() + { + return false; + } + + public virtual void Combine(PhysicsScene pScene, Vector3 offset, Vector3 extents) {} + + public virtual void UnCombine(PhysicsScene pScene) {} + + /// + /// Queue a raycast against the physics scene. + /// The provided callback method will be called when the raycast is complete + /// + /// Many physics engines don't support collision testing at the same time as + /// manipulating the physics scene, so we queue the request up and callback + /// a custom method when the raycast is complete. + /// This allows physics engines that give an immediate result to callback immediately + /// and ones that don't, to callback when it gets a result back. + /// + /// ODE for example will not allow you to change the scene while collision testing or + /// it asserts, 'opteration not valid for locked space'. This includes adding a ray to the scene. + /// + /// This is named RayCastWorld to not conflict with modrex's Raycast method. + /// + /// Origin of the ray + /// Direction of the ray + /// Length of ray in meters + /// Method to call when the raycast is complete + public virtual void RaycastWorld(Vector3 position, Vector3 direction, float length, RaycastCallback retMethod) + { + if (retMethod != null) + retMethod(false, Vector3.Zero, 0, 999999999999f, Vector3.Zero); + } + + public virtual void RaycastWorld(Vector3 position, Vector3 direction, float length, int Count, RayCallback retMethod) + { + if (retMethod != null) + retMethod(new List()); + } + + public virtual List RaycastWorld(Vector3 position, Vector3 direction, float length, int Count) + { + return new List(); + } + + public virtual object RaycastWorld(Vector3 position, Vector3 direction, float length, int Count, RayFilterFlags filter) + { + return null; + } + + public virtual bool SupportsRaycastWorldFiltered() + { + return false; + } + + // Extendable interface for new, physics engine specific operations + public virtual object Extension(string pFunct, params object[] pParams) + { + // A NOP if the extension thing is not implemented by the physics engine + return null; + } + } +} diff --git a/OpenSim/Region/PhysicsModules/SharedBase/PhysicsSensor.cs b/OpenSim/Region/PhysicsModules/SharedBase/PhysicsSensor.cs new file mode 100644 index 0000000..da9c96c --- /dev/null +++ b/OpenSim/Region/PhysicsModules/SharedBase/PhysicsSensor.cs @@ -0,0 +1,78 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSimulator Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using System; +using System.Timers; +using OpenMetaverse; + +namespace OpenSim.Region.PhysicsModules.SharedBase +{ + [Flags] + public enum SenseType : uint + { + NONE = 0, + AGENT = 1, + ACTIVE = 2, + PASSIVE = 3, + SCRIPTED = 4 + } + + public abstract class PhysicsSensor + { + public static PhysicsSensor Null + { + get { return new NullPhysicsSensor(); } + } + public abstract Vector3 Position { get; set; } + public abstract void TimerCallback (object obj, ElapsedEventArgs eea); + public abstract float radianarc {get; set;} + public abstract string targetname {get; set;} + public abstract Guid targetKey{get;set;} + public abstract SenseType sensetype { get;set;} + public abstract float range { get;set;} + public abstract float rateSeconds { get;set;} + } + + public class NullPhysicsSensor : PhysicsSensor + { + public override Vector3 Position + { + get { return Vector3.Zero; } + set { return; } + } + public override void TimerCallback(object obj, ElapsedEventArgs eea) + { + // don't do squat + } + public override float radianarc { get { return 0f; } set { } } + public override string targetname { get { return ""; } set { } } + public override Guid targetKey { get { return Guid.Empty; } set { } } + public override SenseType sensetype { get { return SenseType.NONE; } set { } } + public override float range { get { return 0; } set { } } + public override float rateSeconds { get { return 0; } set { } } + } +} diff --git a/OpenSim/Region/PhysicsModules/SharedBase/PhysicsVector.cs b/OpenSim/Region/PhysicsModules/SharedBase/PhysicsVector.cs new file mode 100644 index 0000000..76a82fa --- /dev/null +++ b/OpenSim/Region/PhysicsModules/SharedBase/PhysicsVector.cs @@ -0,0 +1,186 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSimulator Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using System; + +namespace OpenSim.Region.PhysicsModules.SharedBase +{ + /*public class PhysicsVector + { + public float X; + public float Y; + public float Z; + + public Vector3() + { + } + + public Vector3(float x, float y, float z) + { + X = x; + Y = y; + Z = z; + } + + public Vector3(Vector3 pv) : this(pv.X, pv.Y, pv.Z) + { + } + + public void setValues(float x, float y, float z) + { + X = x; + Y = y; + Z = z; + } + + public static readonly PhysicsVector Zero = new PhysicsVector(0f, 0f, 0f); + + public override string ToString() + { + return "<" + X + "," + Y + "," + Z + ">"; + } + + /// + /// These routines are the easiest way to store XYZ values in an Vector3 without requiring 3 calls. + /// + /// + public byte[] GetBytes() + { + byte[] byteArray = new byte[12]; + + Buffer.BlockCopy(BitConverter.GetBytes(X), 0, byteArray, 0, 4); + Buffer.BlockCopy(BitConverter.GetBytes(Y), 0, byteArray, 4, 4); + Buffer.BlockCopy(BitConverter.GetBytes(Z), 0, byteArray, 8, 4); + + if (!BitConverter.IsLittleEndian) + { + Array.Reverse(byteArray, 0, 4); + Array.Reverse(byteArray, 4, 4); + Array.Reverse(byteArray, 8, 4); + } + + return byteArray; + } + + public void FromBytes(byte[] byteArray, int pos) + { + byte[] conversionBuffer = null; + if (!BitConverter.IsLittleEndian) + { + // Big endian architecture + if (conversionBuffer == null) + conversionBuffer = new byte[12]; + + Buffer.BlockCopy(byteArray, pos, conversionBuffer, 0, 12); + + Array.Reverse(conversionBuffer, 0, 4); + Array.Reverse(conversionBuffer, 4, 4); + Array.Reverse(conversionBuffer, 8, 4); + + X = BitConverter.ToSingle(conversionBuffer, 0); + Y = BitConverter.ToSingle(conversionBuffer, 4); + Z = BitConverter.ToSingle(conversionBuffer, 8); + } + else + { + // Little endian architecture + X = BitConverter.ToSingle(byteArray, pos); + Y = BitConverter.ToSingle(byteArray, pos + 4); + Z = BitConverter.ToSingle(byteArray, pos + 8); + } + } + + // Operations + public static PhysicsVector operator +(Vector3 a, Vector3 b) + { + return new PhysicsVector(a.X + b.X, a.Y + b.Y, a.Z + b.Z); + } + + public static PhysicsVector operator -(Vector3 a, Vector3 b) + { + return new PhysicsVector(a.X - b.X, a.Y - b.Y, a.Z - b.Z); + } + + public static PhysicsVector cross(Vector3 a, Vector3 b) + { + return new PhysicsVector(a.Y*b.Z - a.Z*b.Y, a.Z*b.X - a.X*b.Z, a.X*b.Y - a.Y*b.X); + } + + public float length() + { + return (float) Math.Sqrt(X*X + Y*Y + Z*Z); + } + + public static float GetDistanceTo(Vector3 a, Vector3 b) + { + float dx = a.X - b.X; + float dy = a.Y - b.Y; + float dz = a.Z - b.Z; + return (float) Math.Sqrt(dx * dx + dy * dy + dz * dz); + } + + public static PhysicsVector operator /(Vector3 v, float f) + { + return new PhysicsVector(v.X/f, v.Y/f, v.Z/f); + } + + public static PhysicsVector operator *(Vector3 v, float f) + { + return new PhysicsVector(v.X*f, v.Y*f, v.Z*f); + } + + public static PhysicsVector operator *(float f, Vector3 v) + { + return v*f; + } + + public static bool isFinite(Vector3 v) + { + if (v == null) + return false; + if (Single.IsInfinity(v.X) || Single.IsNaN(v.X)) + return false; + if (Single.IsInfinity(v.Y) || Single.IsNaN(v.Y)) + return false; + if (Single.IsInfinity(v.Z) || Single.IsNaN(v.Z)) + return false; + + return true; + } + + public virtual bool IsIdentical(Vector3 v, float tolerance) + { + PhysicsVector diff = this - v; + float d = diff.length(); + if (d <= tolerance) + return true; + + return false; + } + + }*/ +} diff --git a/OpenSim/Region/PhysicsModules/SharedBase/VehicleConstants.cs b/OpenSim/Region/PhysicsModules/SharedBase/VehicleConstants.cs new file mode 100644 index 0000000..63a8cb8 --- /dev/null +++ b/OpenSim/Region/PhysicsModules/SharedBase/VehicleConstants.cs @@ -0,0 +1,121 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSimulator Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using System; + +namespace OpenSim.Region.PhysicsModules.SharedBase +{ + public enum Vehicle : int + { + /// + /// Turns off Vehicle Support + /// + TYPE_NONE = 0, + + /// + /// No Angular motor, High Left right friction, No Hover, Linear Deflection 1, no angular deflection + /// no vertical attractor, No banking, Identity rotation frame + /// + TYPE_SLED = 1, + + /// + /// Needs Motors to be driven by timer or control events High left/right friction, No angular friction + /// Linear Motor wins in a second, decays in 60 seconds. Angular motor wins in a second, decays in 8/10ths of a second + /// linear deflection 2 seconds + /// Vertical Attractor locked UP + /// + TYPE_CAR = 2, + TYPE_BOAT = 3, + TYPE_AIRPLANE = 4, + TYPE_BALLOON = 5, + LINEAR_FRICTION_TIMESCALE = 16, + /// + /// vector of timescales for exponential decay of angular velocity about three axis + /// + ANGULAR_FRICTION_TIMESCALE = 17, + /// + /// linear velocity vehicle will try for + /// + LINEAR_MOTOR_DIRECTION = 18, + + /// + /// Offset from center of mass where linear motor forces are added + /// + LINEAR_MOTOR_OFFSET = 20, + /// + /// angular velocity that vehicle will try for + /// + ANGULAR_MOTOR_DIRECTION = 19, + HOVER_HEIGHT = 24, + HOVER_EFFICIENCY = 25, + HOVER_TIMESCALE = 26, + BUOYANCY = 27, + LINEAR_DEFLECTION_EFFICIENCY = 28, + LINEAR_DEFLECTION_TIMESCALE = 29, + LINEAR_MOTOR_TIMESCALE = 30, + LINEAR_MOTOR_DECAY_TIMESCALE = 31, + + /// + /// slide between 0 and 1 + /// + ANGULAR_DEFLECTION_EFFICIENCY = 32, + ANGULAR_DEFLECTION_TIMESCALE = 33, + ANGULAR_MOTOR_TIMESCALE = 34, + ANGULAR_MOTOR_DECAY_TIMESCALE = 35, + VERTICAL_ATTRACTION_EFFICIENCY = 36, + VERTICAL_ATTRACTION_TIMESCALE = 37, + BANKING_EFFICIENCY = 38, + BANKING_MIX = 39, + BANKING_TIMESCALE = 40, + REFERENCE_FRAME = 44, + BLOCK_EXIT = 45, + ROLL_FRAME = 46 + + } + + [Flags] + public enum VehicleFlag + { + NO_DEFLECTION_UP = 1, + LIMIT_ROLL_ONLY = 2, + HOVER_WATER_ONLY = 4, + HOVER_TERRAIN_ONLY = 8, + HOVER_GLOBAL_HEIGHT = 16, + HOVER_UP_ONLY = 32, + LIMIT_MOTOR_UP = 64, + MOUSELOOK_STEER = 128, + MOUSELOOK_BANK = 256, + CAMERA_DECOUPLED = 512, + NO_X = 1024, + NO_Y = 2048, + NO_Z = 4096, + LOCK_HOVER_HEIGHT = 8192, + NO_DEFLECTION = 16392, + LOCK_ROTATION = 32784 + } + +} -- cgit v1.1