diff options
author | Robert Adams | 2015-09-08 04:54:16 -0700 |
---|---|---|
committer | Robert Adams | 2015-09-08 04:54:16 -0700 |
commit | e5367d822be9b05e74c859afe2d2956a3e95aa33 (patch) | |
tree | e904050a30715df587aa527d7f313755177726a7 /OpenSim/Region/PhysicsModules/SharedBase | |
parent | add lost admin_reset_land method (diff) | |
parent | Deleted access control spec from [LoginService] section of standalone config.... (diff) | |
download | opensim-SC-e5367d822be9b05e74c859afe2d2956a3e95aa33.zip opensim-SC-e5367d822be9b05e74c859afe2d2956a3e95aa33.tar.gz opensim-SC-e5367d822be9b05e74c859afe2d2956a3e95aa33.tar.bz2 opensim-SC-e5367d822be9b05e74c859afe2d2956a3e95aa33.tar.xz |
Merge of ubitworkvarnew with opensim/master as of 20150905.
This integrates the OpenSim refactoring to make physics, etc into modules.
AVN physics hasn't been moved to new location.
Does not compile yet.
Merge branch 'osmaster' into mbworknew1
Diffstat (limited to 'OpenSim/Region/PhysicsModules/SharedBase')
11 files changed, 1961 insertions, 0 deletions
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 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System.Reflection; | ||
29 | using System.Runtime.InteropServices; | ||
30 | |||
31 | // Information about this assembly is defined by the following | ||
32 | // attributes. | ||
33 | // | ||
34 | // change them to the information which is associated with the assembly | ||
35 | // you compile. | ||
36 | |||
37 | [assembly : AssemblyTitle("PhysicsManager")] | ||
38 | [assembly : AssemblyDescription("")] | ||
39 | [assembly : AssemblyConfiguration("")] | ||
40 | [assembly : AssemblyCompany("http://opensimulator.org")] | ||
41 | [assembly : AssemblyProduct("PhysicsManager")] | ||
42 | [assembly : AssemblyCopyright("Copyright (c) OpenSimulator.org Developers")] | ||
43 | [assembly : AssemblyTrademark("")] | ||
44 | [assembly : AssemblyCulture("")] | ||
45 | |||
46 | // This sets the default COM visibility of types in the assembly to invisible. | ||
47 | // If you need to expose a type to COM, use [ComVisible(true)] on that type. | ||
48 | |||
49 | [assembly : ComVisible(false)] | ||
50 | |||
51 | // The assembly version has following format : | ||
52 | // | ||
53 | // Major.Minor.Build.Revision | ||
54 | // | ||
55 | // You can specify all values by your own or you can build default build and revision | ||
56 | // numbers with the '*' character (the default): | ||
57 | |||
58 | [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 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | |||
31 | namespace OpenSim.Region.PhysicsModules.SharedBase | ||
32 | { | ||
33 | public class CollisionLocker | ||
34 | { | ||
35 | private List<IntPtr> worldlock = new List<IntPtr>(); | ||
36 | |||
37 | public CollisionLocker() | ||
38 | { | ||
39 | |||
40 | } | ||
41 | |||
42 | public void dlock(IntPtr world) | ||
43 | { | ||
44 | lock (worldlock) | ||
45 | { | ||
46 | worldlock.Add(world); | ||
47 | } | ||
48 | |||
49 | } | ||
50 | |||
51 | public void dunlock(IntPtr world) | ||
52 | { | ||
53 | lock (worldlock) | ||
54 | { | ||
55 | worldlock.Remove(world); | ||
56 | } | ||
57 | } | ||
58 | |||
59 | public bool lockquery() | ||
60 | { | ||
61 | return (worldlock.Count > 0); | ||
62 | } | ||
63 | |||
64 | public void drelease(IntPtr world) | ||
65 | { | ||
66 | lock (worldlock) | ||
67 | { | ||
68 | if (worldlock.Contains(world)) | ||
69 | worldlock.Remove(world); | ||
70 | } | ||
71 | } | ||
72 | } | ||
73 | } | ||
diff --git a/OpenSim/Region/PhysicsModules/SharedBase/IMesher.cs b/OpenSim/Region/PhysicsModules/SharedBase/IMesher.cs new file mode 100644 index 0000000..88169bb --- /dev/null +++ b/OpenSim/Region/PhysicsModules/SharedBase/IMesher.cs | |||
@@ -0,0 +1,98 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Runtime.InteropServices; | ||
31 | using OpenSim.Framework; | ||
32 | using OpenMetaverse; | ||
33 | |||
34 | namespace OpenSim.Region.PhysicsModules.SharedBase | ||
35 | { | ||
36 | public interface IMesher | ||
37 | { | ||
38 | IMesh CreateMesh(String primName, PrimitiveBaseShape primShape, Vector3 size, float lod); | ||
39 | IMesh CreateMesh(String primName, PrimitiveBaseShape primShape, Vector3 size, float lod, bool isPhysical); | ||
40 | IMesh CreateMesh(String primName, PrimitiveBaseShape primShape, Vector3 size, float lod, bool isPhysical, bool convex, bool forOde); | ||
41 | IMesh CreateMesh(String primName, PrimitiveBaseShape primShape, Vector3 size, float lod, bool isPhysical, bool shouldCache, bool convex, bool forOde); | ||
42 | IMesh GetMesh(String primName, PrimitiveBaseShape primShape, Vector3 size, float lod, bool isPhysical, bool convex); | ||
43 | void ReleaseMesh(IMesh mesh); | ||
44 | void ExpireReleaseMeshs(); | ||
45 | void ExpireFileCache(); | ||
46 | } | ||
47 | |||
48 | // Values for level of detail to be passed to the mesher. | ||
49 | // Values origionally chosen for the LOD of sculpties (the sqrt(width*heigth) of sculpt texture) | ||
50 | // Lower level of detail reduces the number of vertices used to represent the meshed shape. | ||
51 | public enum LevelOfDetail | ||
52 | { | ||
53 | High = 32, | ||
54 | Medium = 16, | ||
55 | Low = 8, | ||
56 | VeryLow = 4 | ||
57 | } | ||
58 | |||
59 | public interface IVertex | ||
60 | { | ||
61 | } | ||
62 | |||
63 | [Serializable()] | ||
64 | [StructLayout(LayoutKind.Explicit)] | ||
65 | public struct AMeshKey | ||
66 | { | ||
67 | [FieldOffset(0)] | ||
68 | public UUID uuid; | ||
69 | [FieldOffset(0)] | ||
70 | public ulong hashA; | ||
71 | [FieldOffset(8)] | ||
72 | public ulong hashB; | ||
73 | [FieldOffset(16)] | ||
74 | public ulong hashC; | ||
75 | |||
76 | public override string ToString() | ||
77 | { | ||
78 | return uuid.ToString() + "-" + hashC.ToString("x") ; | ||
79 | } | ||
80 | } | ||
81 | |||
82 | public interface IMesh | ||
83 | { | ||
84 | List<Vector3> getVertexList(); | ||
85 | int[] getIndexListAsInt(); | ||
86 | int[] getIndexListAsIntLocked(); | ||
87 | float[] getVertexListAsFloat(); | ||
88 | float[] getVertexListAsFloatLocked(); | ||
89 | void getIndexListAsPtrToIntArray(out IntPtr indices, out int triStride, out int indexCount); | ||
90 | void getVertexListAsPtrToFloatArray(out IntPtr vertexList, out int vertexStride, out int vertexCount); | ||
91 | void releaseSourceMeshData(); | ||
92 | void releasePinned(); | ||
93 | void Append(IMesh newMesh); | ||
94 | void TransformLinear(float[,] matrix, float[] offset); | ||
95 | Vector3 GetCentroid(); | ||
96 | Vector3 GetOBB(); | ||
97 | } | ||
98 | } | ||
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 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using OpenSim.Framework; | ||
31 | using OpenMetaverse; | ||
32 | |||
33 | namespace OpenSim.Region.PhysicsModules.SharedBase | ||
34 | { | ||
35 | public struct PhysParameterEntry | ||
36 | { | ||
37 | // flags to say to apply to all or no instances (I wish one could put consts into interfaces) | ||
38 | public const uint APPLY_TO_ALL = 0xfffffff3; | ||
39 | public const uint APPLY_TO_NONE = 0xfffffff4; | ||
40 | |||
41 | // values that denote true and false values | ||
42 | public const float NUMERIC_TRUE = 1f; | ||
43 | public const float NUMERIC_FALSE = 0f; | ||
44 | |||
45 | public string name; | ||
46 | public string desc; | ||
47 | |||
48 | public PhysParameterEntry(string n, string d) | ||
49 | { | ||
50 | name = n; | ||
51 | desc = d; | ||
52 | } | ||
53 | } | ||
54 | |||
55 | // Interface for a physics scene that implements the runtime setting and getting of physics parameters | ||
56 | public interface IPhysicsParameters | ||
57 | { | ||
58 | // Get the list of parameters this physics engine supports | ||
59 | PhysParameterEntry[] GetParameterList(); | ||
60 | |||
61 | // Set parameter on a specific or all instances. | ||
62 | // Return 'false' if not able to set the parameter. | ||
63 | bool SetPhysicsParameter(string parm, string value, uint localID); | ||
64 | |||
65 | // Get parameter. | ||
66 | // Return 'false' if not able to get the parameter. | ||
67 | bool GetPhysicsParameter(string parm, out string value); | ||
68 | |||
69 | // Get parameter from a particular object | ||
70 | // TODO: | ||
71 | // bool GetPhysicsParameter(string parm, out string value, uint localID); | ||
72 | } | ||
73 | } | ||
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 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System.Collections.Generic; | ||
29 | using System.Reflection; | ||
30 | using log4net; | ||
31 | using Nini.Config; | ||
32 | using OpenSim.Framework; | ||
33 | using OpenMetaverse; | ||
34 | |||
35 | namespace OpenSim.Region.PhysicsModules.SharedBase | ||
36 | { | ||
37 | class NullPhysicsScene : PhysicsScene | ||
38 | { | ||
39 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
40 | |||
41 | private static int m_workIndicator; | ||
42 | |||
43 | public override PhysicsActor AddAvatar( | ||
44 | string avName, Vector3 position, Vector3 velocity, Vector3 size, bool isFlying) | ||
45 | { | ||
46 | m_log.InfoFormat("[PHYSICS]: NullPhysicsScene : AddAvatar({0})", position); | ||
47 | return PhysicsActor.Null; | ||
48 | } | ||
49 | |||
50 | public override void RemoveAvatar(PhysicsActor actor) | ||
51 | { | ||
52 | } | ||
53 | |||
54 | public override void RemovePrim(PhysicsActor prim) | ||
55 | { | ||
56 | } | ||
57 | public override void SetWaterLevel(float baseheight) | ||
58 | { | ||
59 | |||
60 | } | ||
61 | |||
62 | /* | ||
63 | public override PhysicsActor AddPrim(Vector3 position, Vector3 size, Quaternion rotation) | ||
64 | { | ||
65 | m_log.InfoFormat("NullPhysicsScene : AddPrim({0},{1})", position, size); | ||
66 | return PhysicsActor.Null; | ||
67 | } | ||
68 | */ | ||
69 | |||
70 | public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, Vector3 position, | ||
71 | Vector3 size, Quaternion rotation, bool isPhysical, uint localid) | ||
72 | { | ||
73 | m_log.InfoFormat("[PHYSICS]: NullPhysicsScene : AddPrim({0},{1})", position, size); | ||
74 | return PhysicsActor.Null; | ||
75 | } | ||
76 | |||
77 | public override void AddPhysicsActorTaint(PhysicsActor prim) | ||
78 | { | ||
79 | } | ||
80 | |||
81 | public override float Simulate(float timeStep) | ||
82 | { | ||
83 | m_workIndicator = (m_workIndicator + 1) % 10; | ||
84 | |||
85 | return 0f; | ||
86 | } | ||
87 | |||
88 | public override void GetResults() | ||
89 | { | ||
90 | m_log.Info("[PHYSICS]: NullPhysicsScene : GetResults()"); | ||
91 | } | ||
92 | |||
93 | public override void SetTerrain(float[] heightMap) | ||
94 | { | ||
95 | m_log.InfoFormat("[PHYSICS]: NullPhysicsScene : SetTerrain({0} items)", heightMap.Length); | ||
96 | } | ||
97 | |||
98 | public override void DeleteTerrain() | ||
99 | { | ||
100 | } | ||
101 | |||
102 | public override bool IsThreaded | ||
103 | { | ||
104 | get { return false; } | ||
105 | } | ||
106 | |||
107 | public override void Dispose() | ||
108 | { | ||
109 | } | ||
110 | |||
111 | public override Dictionary<uint,float> GetTopColliders() | ||
112 | { | ||
113 | Dictionary<uint, float> returncolliders = new Dictionary<uint, float>(); | ||
114 | return returncolliders; | ||
115 | } | ||
116 | } | ||
117 | } \ 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..edc41e4 --- /dev/null +++ b/OpenSim/Region/PhysicsModules/SharedBase/PhysicsActor.cs | |||
@@ -0,0 +1,639 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using log4net; | ||
29 | using System; | ||
30 | using System.Collections.Generic; | ||
31 | using System.Reflection; | ||
32 | using OpenSim.Framework; | ||
33 | using OpenMetaverse; | ||
34 | |||
35 | namespace OpenSim.Region.PhysicsModules.SharedBase | ||
36 | { | ||
37 | public delegate void PositionUpdate(Vector3 position); | ||
38 | public delegate void VelocityUpdate(Vector3 velocity); | ||
39 | public delegate void OrientationUpdate(Quaternion orientation); | ||
40 | |||
41 | public enum ActorTypes : int | ||
42 | { | ||
43 | Unknown = 0, | ||
44 | Agent = 1, | ||
45 | Prim = 2, | ||
46 | Ground = 3, | ||
47 | Water = 4 | ||
48 | } | ||
49 | |||
50 | public enum PIDHoverType | ||
51 | { | ||
52 | Ground, | ||
53 | GroundAndWater, | ||
54 | Water, | ||
55 | Absolute | ||
56 | } | ||
57 | |||
58 | public struct ContactPoint | ||
59 | { | ||
60 | public Vector3 Position; | ||
61 | public Vector3 SurfaceNormal; | ||
62 | public float PenetrationDepth; | ||
63 | public float RelativeSpeed; | ||
64 | public bool CharacterFeet; | ||
65 | |||
66 | public ContactPoint(Vector3 position, Vector3 surfaceNormal, float penetrationDepth) | ||
67 | { | ||
68 | Position = position; | ||
69 | SurfaceNormal = surfaceNormal; | ||
70 | PenetrationDepth = penetrationDepth; | ||
71 | RelativeSpeed = 0f; // for now let this one be set explicity | ||
72 | CharacterFeet = true; // keep other plugins work as before | ||
73 | } | ||
74 | |||
75 | public ContactPoint(Vector3 position, Vector3 surfaceNormal, float penetrationDepth, bool feet) | ||
76 | { | ||
77 | Position = position; | ||
78 | SurfaceNormal = surfaceNormal; | ||
79 | PenetrationDepth = penetrationDepth; | ||
80 | RelativeSpeed = 0f; // for now let this one be set explicity | ||
81 | CharacterFeet = feet; // keep other plugins work as before | ||
82 | } | ||
83 | } | ||
84 | |||
85 | public struct ContactData | ||
86 | { | ||
87 | public float mu; | ||
88 | public float bounce; | ||
89 | public bool softcolide; | ||
90 | |||
91 | public ContactData(float _mu, float _bounce, bool _softcolide) | ||
92 | { | ||
93 | mu = _mu; | ||
94 | bounce = _bounce; | ||
95 | softcolide = _softcolide; | ||
96 | } | ||
97 | } | ||
98 | /// <summary> | ||
99 | /// Used to pass collision information to OnCollisionUpdate listeners. | ||
100 | /// </summary> | ||
101 | public class CollisionEventUpdate : EventArgs | ||
102 | { | ||
103 | /// <summary> | ||
104 | /// Number of collision events in this update. | ||
105 | /// </summary> | ||
106 | public int Count { get { return m_objCollisionList.Count; } } | ||
107 | |||
108 | public bool CollisionsOnPreviousFrame { get; private set; } | ||
109 | |||
110 | public Dictionary<uint, ContactPoint> m_objCollisionList; | ||
111 | |||
112 | public CollisionEventUpdate(Dictionary<uint, ContactPoint> objCollisionList) | ||
113 | { | ||
114 | m_objCollisionList = objCollisionList; | ||
115 | } | ||
116 | |||
117 | public CollisionEventUpdate() | ||
118 | { | ||
119 | m_objCollisionList = new Dictionary<uint, ContactPoint>(); | ||
120 | } | ||
121 | |||
122 | public void AddCollider(uint localID, ContactPoint contact) | ||
123 | { | ||
124 | if (!m_objCollisionList.ContainsKey(localID)) | ||
125 | { | ||
126 | m_objCollisionList.Add(localID, contact); | ||
127 | } | ||
128 | else | ||
129 | { | ||
130 | if (m_objCollisionList[localID].PenetrationDepth < contact.PenetrationDepth) | ||
131 | m_objCollisionList[localID] = contact; | ||
132 | } | ||
133 | } | ||
134 | |||
135 | /// <summary> | ||
136 | /// Clear added collision events. | ||
137 | /// </summary> | ||
138 | public void Clear() | ||
139 | { | ||
140 | m_objCollisionList.Clear(); | ||
141 | } | ||
142 | } | ||
143 | |||
144 | public abstract class PhysicsActor | ||
145 | { | ||
146 | // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
147 | |||
148 | public delegate void RequestTerseUpdate(); | ||
149 | public delegate void CollisionUpdate(EventArgs e); | ||
150 | public delegate void OutOfBounds(Vector3 pos); | ||
151 | |||
152 | // disable warning: public events | ||
153 | #pragma warning disable 67 | ||
154 | public event PositionUpdate OnPositionUpdate; | ||
155 | public event VelocityUpdate OnVelocityUpdate; | ||
156 | public event OrientationUpdate OnOrientationUpdate; | ||
157 | public event RequestTerseUpdate OnRequestTerseUpdate; | ||
158 | |||
159 | /// <summary> | ||
160 | /// Subscribers to this event must synchronously handle the dictionary of collisions received, since the event | ||
161 | /// object is reused in subsequent physics frames. | ||
162 | /// </summary> | ||
163 | public event CollisionUpdate OnCollisionUpdate; | ||
164 | |||
165 | public virtual void SetVehicle(object vdata) { } | ||
166 | |||
167 | public event OutOfBounds OnOutOfBounds; | ||
168 | #pragma warning restore 67 | ||
169 | |||
170 | public static PhysicsActor Null | ||
171 | { | ||
172 | get { return new NullPhysicsActor(); } | ||
173 | } | ||
174 | |||
175 | public virtual bool Building { get; set; } | ||
176 | |||
177 | public virtual void getContactData(ref ContactData cdata) | ||
178 | { | ||
179 | cdata.mu = 0; | ||
180 | cdata.bounce = 0; | ||
181 | } | ||
182 | |||
183 | public abstract bool Stopped { get; } | ||
184 | |||
185 | public abstract Vector3 Size { get; set; } | ||
186 | |||
187 | public virtual void setAvatarSize(Vector3 size, float feetOffset) | ||
188 | { | ||
189 | Size = size; | ||
190 | } | ||
191 | |||
192 | public virtual bool Phantom { get; set; } | ||
193 | |||
194 | public virtual bool IsVolumeDtc | ||
195 | { | ||
196 | get { return false; } | ||
197 | set { return; } | ||
198 | } | ||
199 | |||
200 | public virtual byte PhysicsShapeType { get; set; } | ||
201 | |||
202 | public abstract PrimitiveBaseShape Shape { set; } | ||
203 | |||
204 | uint m_baseLocalID; | ||
205 | public virtual uint LocalID | ||
206 | { | ||
207 | set { m_baseLocalID = value; } | ||
208 | get { return m_baseLocalID; } | ||
209 | } | ||
210 | |||
211 | public abstract bool Grabbed { set; } | ||
212 | |||
213 | public abstract bool Selected { set; } | ||
214 | |||
215 | /// <summary> | ||
216 | /// Name of this actor. | ||
217 | /// </summary> | ||
218 | /// <remarks> | ||
219 | /// XXX: Bizarrely, this cannot be "Terrain" or "Water" right now unless it really is simulating terrain or | ||
220 | /// water. This is not a problem due to the formatting of names given by prims and avatars. | ||
221 | /// </remarks> | ||
222 | public string Name { get; set; } | ||
223 | |||
224 | /// <summary> | ||
225 | /// This is being used by ODE joint code. | ||
226 | /// </summary> | ||
227 | public string SOPName; | ||
228 | |||
229 | public abstract void CrossingFailure(); | ||
230 | |||
231 | public abstract void link(PhysicsActor obj); | ||
232 | |||
233 | public abstract void delink(); | ||
234 | |||
235 | public abstract void LockAngularMotion(Vector3 axis); | ||
236 | |||
237 | public virtual void RequestPhysicsterseUpdate() | ||
238 | { | ||
239 | // Make a temporary copy of the event to avoid possibility of | ||
240 | // a race condition if the last subscriber unsubscribes | ||
241 | // immediately after the null check and before the event is raised. | ||
242 | RequestTerseUpdate handler = OnRequestTerseUpdate; | ||
243 | |||
244 | if (handler != null) | ||
245 | { | ||
246 | handler(); | ||
247 | } | ||
248 | } | ||
249 | |||
250 | public virtual void RaiseOutOfBounds(Vector3 pos) | ||
251 | { | ||
252 | // Make a temporary copy of the event to avoid possibility of | ||
253 | // a race condition if the last subscriber unsubscribes | ||
254 | // immediately after the null check and before the event is raised. | ||
255 | OutOfBounds handler = OnOutOfBounds; | ||
256 | |||
257 | if (handler != null) | ||
258 | { | ||
259 | handler(pos); | ||
260 | } | ||
261 | } | ||
262 | |||
263 | public virtual void SendCollisionUpdate(EventArgs e) | ||
264 | { | ||
265 | CollisionUpdate handler = OnCollisionUpdate; | ||
266 | |||
267 | // m_log.DebugFormat("[PHYSICS ACTOR]: Sending collision for {0}", LocalID); | ||
268 | |||
269 | if (handler != null) | ||
270 | handler(e); | ||
271 | } | ||
272 | |||
273 | public virtual void SetMaterial (int material) { } | ||
274 | public virtual float Density { get; set; } | ||
275 | public virtual float GravModifier { get; set; } | ||
276 | public virtual float Friction { get; set; } | ||
277 | public virtual float Restitution { get; set; } | ||
278 | |||
279 | /// <summary> | ||
280 | /// Position of this actor. | ||
281 | /// </summary> | ||
282 | /// <remarks> | ||
283 | /// Setting this directly moves the actor to a given position. | ||
284 | /// Getting this retrieves the position calculated by physics scene updates, using factors such as velocity and | ||
285 | /// collisions. | ||
286 | /// </remarks> | ||
287 | public abstract Vector3 Position { get; set; } | ||
288 | |||
289 | public abstract float Mass { get; } | ||
290 | public abstract Vector3 Force { get; set; } | ||
291 | |||
292 | public abstract int VehicleType { get; set; } | ||
293 | public abstract void VehicleFloatParam(int param, float value); | ||
294 | public abstract void VehicleVectorParam(int param, Vector3 value); | ||
295 | public abstract void VehicleRotationParam(int param, Quaternion rotation); | ||
296 | public abstract void VehicleFlags(int param, bool remove); | ||
297 | |||
298 | /// <summary> | ||
299 | /// Allows the detection of collisions with inherently non-physical prims. see llVolumeDetect for more | ||
300 | /// </summary> | ||
301 | public abstract void SetVolumeDetect(int param); | ||
302 | |||
303 | public abstract Vector3 GeometricCenter { get; } | ||
304 | public abstract Vector3 CenterOfMass { get; } | ||
305 | |||
306 | public virtual Vector3 OOBsize | ||
307 | { | ||
308 | get | ||
309 | { | ||
310 | Vector3 s=Size; | ||
311 | s.X *=0.5f; | ||
312 | s.Y *=0.5f; | ||
313 | s.Z *=0.5f; | ||
314 | return s; | ||
315 | } | ||
316 | } | ||
317 | |||
318 | public virtual Vector3 OOBoffset | ||
319 | { | ||
320 | get | ||
321 | { | ||
322 | return Vector3.Zero; | ||
323 | } | ||
324 | } | ||
325 | |||
326 | public virtual float OOBRadiusSQ | ||
327 | { | ||
328 | get | ||
329 | { | ||
330 | return Size.LengthSquared() * 0.25f; // ((0.5^2) | ||
331 | } | ||
332 | } | ||
333 | |||
334 | |||
335 | public virtual float PhysicsCost | ||
336 | { | ||
337 | get | ||
338 | { | ||
339 | return 0.1f; | ||
340 | } | ||
341 | } | ||
342 | |||
343 | public virtual float StreamCost | ||
344 | { | ||
345 | get | ||
346 | { | ||
347 | return 1.0f; | ||
348 | } | ||
349 | } | ||
350 | |||
351 | /// <summary> | ||
352 | /// The desired velocity of this actor. | ||
353 | /// </summary> | ||
354 | /// <remarks> | ||
355 | /// Setting this provides a target velocity for physics scene updates. | ||
356 | /// Getting this returns the last set target. Fetch Velocity to get the current velocity. | ||
357 | /// </remarks> | ||
358 | protected Vector3 m_targetVelocity; | ||
359 | public virtual Vector3 TargetVelocity | ||
360 | { | ||
361 | get { return m_targetVelocity; } | ||
362 | set { | ||
363 | m_targetVelocity = value; | ||
364 | Velocity = m_targetVelocity; | ||
365 | } | ||
366 | } | ||
367 | |||
368 | public abstract Vector3 Velocity { get; set; } | ||
369 | |||
370 | public abstract Vector3 Torque { get; set; } | ||
371 | public abstract float CollisionScore { get; set;} | ||
372 | public abstract Vector3 Acceleration { get; set; } | ||
373 | public abstract Quaternion Orientation { get; set; } | ||
374 | public abstract int PhysicsActorType { get; set; } | ||
375 | public abstract bool IsPhysical { get; set; } | ||
376 | public abstract bool Flying { get; set; } | ||
377 | public abstract bool SetAlwaysRun { get; set; } | ||
378 | public abstract bool ThrottleUpdates { get; set; } | ||
379 | public abstract bool IsColliding { get; set; } | ||
380 | public abstract bool CollidingGround { get; set; } | ||
381 | public abstract bool CollidingObj { get; set; } | ||
382 | public abstract bool FloatOnWater { set; } | ||
383 | public abstract Vector3 RotationalVelocity { get; set; } | ||
384 | public abstract bool Kinematic { get; set; } | ||
385 | public abstract float Buoyancy { get; set; } | ||
386 | |||
387 | // Used for MoveTo | ||
388 | public abstract Vector3 PIDTarget { set; } | ||
389 | public abstract bool PIDActive { get; set; } | ||
390 | public abstract float PIDTau { set; } | ||
391 | |||
392 | // Used for llSetHoverHeight and maybe vehicle height | ||
393 | // Hover Height will override MoveTo target's Z | ||
394 | public abstract bool PIDHoverActive { set;} | ||
395 | public abstract float PIDHoverHeight { set;} | ||
396 | public abstract PIDHoverType PIDHoverType { set;} | ||
397 | public abstract float PIDHoverTau { set;} | ||
398 | |||
399 | // For RotLookAt | ||
400 | public abstract Quaternion APIDTarget { set;} | ||
401 | public abstract bool APIDActive { set;} | ||
402 | public abstract float APIDStrength { set;} | ||
403 | public abstract float APIDDamping { set;} | ||
404 | |||
405 | public abstract void AddForce(Vector3 force, bool pushforce); | ||
406 | public abstract void AddAngularForce(Vector3 force, bool pushforce); | ||
407 | public abstract void SetMomentum(Vector3 momentum); | ||
408 | public abstract void SubscribeEvents(int ms); | ||
409 | public abstract void UnSubscribeEvents(); | ||
410 | public abstract bool SubscribedEvents(); | ||
411 | |||
412 | public virtual void AddCollisionEvent(uint CollidedWith, ContactPoint contact) { } | ||
413 | |||
414 | // Warning in a parent part it returns itself, not null | ||
415 | public virtual PhysicsActor ParentActor { get { return this; } } | ||
416 | |||
417 | |||
418 | // Extendable interface for new, physics engine specific operations | ||
419 | public virtual object Extension(string pFunct, params object[] pParams) | ||
420 | { | ||
421 | // A NOP of the physics engine does not implement this feature | ||
422 | return null; | ||
423 | } | ||
424 | } | ||
425 | |||
426 | public class NullPhysicsActor : PhysicsActor | ||
427 | { | ||
428 | private ActorTypes m_actorType = ActorTypes.Unknown; | ||
429 | |||
430 | public override bool Stopped | ||
431 | { | ||
432 | get{ return true; } | ||
433 | } | ||
434 | |||
435 | public override Vector3 Position | ||
436 | { | ||
437 | get { return Vector3.Zero; } | ||
438 | set { return; } | ||
439 | } | ||
440 | |||
441 | public override bool SetAlwaysRun | ||
442 | { | ||
443 | get { return false; } | ||
444 | set { return; } | ||
445 | } | ||
446 | |||
447 | public override uint LocalID | ||
448 | { | ||
449 | get { return 0; } | ||
450 | set { return; } | ||
451 | } | ||
452 | |||
453 | public override bool Grabbed | ||
454 | { | ||
455 | set { return; } | ||
456 | } | ||
457 | |||
458 | public override bool Selected | ||
459 | { | ||
460 | set { return; } | ||
461 | } | ||
462 | |||
463 | public override float Buoyancy | ||
464 | { | ||
465 | get { return 0f; } | ||
466 | set { return; } | ||
467 | } | ||
468 | |||
469 | public override bool FloatOnWater | ||
470 | { | ||
471 | set { return; } | ||
472 | } | ||
473 | |||
474 | public override bool CollidingGround | ||
475 | { | ||
476 | get { return false; } | ||
477 | set { return; } | ||
478 | } | ||
479 | |||
480 | public override bool CollidingObj | ||
481 | { | ||
482 | get { return false; } | ||
483 | set { return; } | ||
484 | } | ||
485 | |||
486 | public override Vector3 Size | ||
487 | { | ||
488 | get { return Vector3.Zero; } | ||
489 | set { return; } | ||
490 | } | ||
491 | |||
492 | public override float Mass | ||
493 | { | ||
494 | get { return 0f; } | ||
495 | } | ||
496 | |||
497 | public override Vector3 Force | ||
498 | { | ||
499 | get { return Vector3.Zero; } | ||
500 | set { return; } | ||
501 | } | ||
502 | |||
503 | public override int VehicleType | ||
504 | { | ||
505 | get { return 0; } | ||
506 | set { return; } | ||
507 | } | ||
508 | |||
509 | public override void VehicleFloatParam(int param, float value) {} | ||
510 | public override void VehicleVectorParam(int param, Vector3 value) { } | ||
511 | public override void VehicleRotationParam(int param, Quaternion rotation) { } | ||
512 | public override void VehicleFlags(int param, bool remove) { } | ||
513 | public override void SetVolumeDetect(int param) {} | ||
514 | public override void SetMaterial(int material) {} | ||
515 | public override Vector3 CenterOfMass { get { return Vector3.Zero; }} | ||
516 | |||
517 | public override Vector3 GeometricCenter { get { return Vector3.Zero; }} | ||
518 | |||
519 | public override PrimitiveBaseShape Shape { set { return; }} | ||
520 | |||
521 | public override Vector3 Velocity | ||
522 | { | ||
523 | get { return Vector3.Zero; } | ||
524 | set { return; } | ||
525 | } | ||
526 | |||
527 | public override Vector3 Torque | ||
528 | { | ||
529 | get { return Vector3.Zero; } | ||
530 | set { return; } | ||
531 | } | ||
532 | |||
533 | public override float CollisionScore | ||
534 | { | ||
535 | get { return 0f; } | ||
536 | set { } | ||
537 | } | ||
538 | |||
539 | public override void CrossingFailure() {} | ||
540 | |||
541 | public override Quaternion Orientation | ||
542 | { | ||
543 | get { return Quaternion.Identity; } | ||
544 | set { } | ||
545 | } | ||
546 | |||
547 | public override Vector3 Acceleration | ||
548 | { | ||
549 | get { return Vector3.Zero; } | ||
550 | set { } | ||
551 | } | ||
552 | |||
553 | public override bool IsPhysical | ||
554 | { | ||
555 | get { return false; } | ||
556 | set { return; } | ||
557 | } | ||
558 | |||
559 | public override bool Flying | ||
560 | { | ||
561 | get { return false; } | ||
562 | set { return; } | ||
563 | } | ||
564 | |||
565 | public override bool ThrottleUpdates | ||
566 | { | ||
567 | get { return false; } | ||
568 | set { return; } | ||
569 | } | ||
570 | |||
571 | public override bool IsColliding | ||
572 | { | ||
573 | get { return false; } | ||
574 | set { return; } | ||
575 | } | ||
576 | |||
577 | public override int PhysicsActorType | ||
578 | { | ||
579 | get { return (int)m_actorType; } | ||
580 | set { | ||
581 | ActorTypes type = (ActorTypes)value; | ||
582 | switch (type) | ||
583 | { | ||
584 | case ActorTypes.Ground: | ||
585 | case ActorTypes.Water: | ||
586 | m_actorType = type; | ||
587 | break; | ||
588 | default: | ||
589 | m_actorType = ActorTypes.Unknown; | ||
590 | break; | ||
591 | } | ||
592 | } | ||
593 | } | ||
594 | |||
595 | public override bool Kinematic | ||
596 | { | ||
597 | get { return true; } | ||
598 | set { return; } | ||
599 | } | ||
600 | |||
601 | public override void link(PhysicsActor obj) { } | ||
602 | public override void delink() { } | ||
603 | public override void LockAngularMotion(Vector3 axis) { } | ||
604 | public override void AddForce(Vector3 force, bool pushforce) { } | ||
605 | public override void AddAngularForce(Vector3 force, bool pushforce) { } | ||
606 | |||
607 | public override Vector3 RotationalVelocity | ||
608 | { | ||
609 | get { return Vector3.Zero; } | ||
610 | set { return; } | ||
611 | } | ||
612 | |||
613 | public override Vector3 PIDTarget { set { return; } } | ||
614 | |||
615 | public override bool PIDActive | ||
616 | { | ||
617 | get { return false; } | ||
618 | set { return; } | ||
619 | } | ||
620 | |||
621 | public override float PIDTau { set { return; } } | ||
622 | |||
623 | public override float PIDHoverHeight { set { return; } } | ||
624 | public override bool PIDHoverActive { set { return; } } | ||
625 | public override PIDHoverType PIDHoverType { set { return; } } | ||
626 | public override float PIDHoverTau { set { return; } } | ||
627 | |||
628 | public override Quaternion APIDTarget { set { return; } } | ||
629 | public override bool APIDActive { set { return; } } | ||
630 | public override float APIDStrength { set { return; } } | ||
631 | public override float APIDDamping { set { return; } } | ||
632 | |||
633 | public override void SetMomentum(Vector3 momentum) { } | ||
634 | |||
635 | public override void SubscribeEvents(int ms) { } | ||
636 | public override void UnSubscribeEvents() { } | ||
637 | public override bool SubscribedEvents() { return false; } | ||
638 | } | ||
639 | } | ||
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 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using OpenSim.Framework; | ||
31 | using OpenMetaverse; | ||
32 | |||
33 | namespace OpenSim.Region.PhysicsModules.SharedBase | ||
34 | { | ||
35 | public enum PhysicsJointType : int | ||
36 | { | ||
37 | Ball = 0, | ||
38 | Hinge = 1 | ||
39 | } | ||
40 | |||
41 | public class PhysicsJoint | ||
42 | { | ||
43 | 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 | ||
44 | public PhysicsJointType Type; | ||
45 | public string RawParams; | ||
46 | public List<string> BodyNames = new List<string>(); | ||
47 | public Vector3 Position; // global coords | ||
48 | public Quaternion Rotation; // global coords | ||
49 | public string ObjectNameInScene; // proxy object in scene that represents the joint position/orientation | ||
50 | public string TrackedBodyName; // body name that this joint is attached to (ObjectNameInScene will follow TrackedBodyName) | ||
51 | public Quaternion LocalRotation; // joint orientation relative to one of the involved bodies, the tracked body | ||
52 | 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. | ||
53 | public const int maxErrorMessages = 100; // no more than this # of error messages will be printed for each joint | ||
54 | } | ||
55 | } | ||
diff --git a/OpenSim/Region/PhysicsModules/SharedBase/PhysicsScene.cs b/OpenSim/Region/PhysicsModules/SharedBase/PhysicsScene.cs new file mode 100644 index 0000000..1c0ad20 --- /dev/null +++ b/OpenSim/Region/PhysicsModules/SharedBase/PhysicsScene.cs | |||
@@ -0,0 +1,420 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Reflection; | ||
31 | |||
32 | using log4net; | ||
33 | using Nini.Config; | ||
34 | |||
35 | using OpenSim.Framework; | ||
36 | using OpenMetaverse; | ||
37 | |||
38 | namespace OpenSim.Region.PhysicsModules.SharedBase | ||
39 | { | ||
40 | public delegate void physicsCrash(); | ||
41 | |||
42 | public delegate void RaycastCallback(bool hitYN, Vector3 collisionPoint, uint localid, float distance, Vector3 normal); | ||
43 | public delegate void RayCallback(List<ContactResult> list); | ||
44 | public delegate void ProbeBoxCallback(List<ContactResult> list); | ||
45 | public delegate void ProbeSphereCallback(List<ContactResult> list); | ||
46 | public delegate void ProbePlaneCallback(List<ContactResult> list); | ||
47 | public delegate void SitAvatarCallback(int status, uint partID, Vector3 offset, Quaternion Orientation); | ||
48 | |||
49 | public delegate void JointMoved(PhysicsJoint joint); | ||
50 | public delegate void JointDeactivated(PhysicsJoint joint); | ||
51 | public delegate void JointErrorMessage(PhysicsJoint joint, string message); // this refers to an "error message due to a problem", not "amount of joint constraint violation" | ||
52 | |||
53 | public enum RayFilterFlags : ushort | ||
54 | { | ||
55 | // the flags | ||
56 | water = 0x01, | ||
57 | land = 0x02, | ||
58 | agent = 0x04, | ||
59 | nonphysical = 0x08, | ||
60 | physical = 0x10, | ||
61 | phantom = 0x20, | ||
62 | volumedtc = 0x40, | ||
63 | |||
64 | // ray cast colision control (may only work for meshs) | ||
65 | ContactsUnImportant = 0x2000, | ||
66 | BackFaceCull = 0x4000, | ||
67 | ClosestHit = 0x8000, | ||
68 | |||
69 | // some combinations | ||
70 | LSLPhantom = phantom | volumedtc, | ||
71 | PrimsNonPhantom = nonphysical | physical, | ||
72 | PrimsNonPhantomAgents = nonphysical | physical | agent, | ||
73 | |||
74 | AllPrims = nonphysical | phantom | volumedtc | physical, | ||
75 | AllButLand = agent | nonphysical | physical | phantom | volumedtc, | ||
76 | |||
77 | ClosestAndBackCull = ClosestHit | BackFaceCull, | ||
78 | |||
79 | All = 0x3f | ||
80 | } | ||
81 | |||
82 | public delegate void RequestAssetDelegate(UUID assetID, AssetReceivedDelegate callback); | ||
83 | public delegate void AssetReceivedDelegate(AssetBase asset); | ||
84 | |||
85 | /// <summary> | ||
86 | /// Contact result from a raycast. | ||
87 | /// </summary> | ||
88 | public struct ContactResult | ||
89 | { | ||
90 | public Vector3 Pos; | ||
91 | public float Depth; | ||
92 | public uint ConsumerID; | ||
93 | public Vector3 Normal; | ||
94 | } | ||
95 | |||
96 | |||
97 | |||
98 | public abstract class PhysicsScene | ||
99 | { | ||
100 | // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
101 | |||
102 | /// <summary> | ||
103 | /// A unique identifying string for this instance of the physics engine. | ||
104 | /// Useful in debug messages to distinguish one OdeScene instance from another. | ||
105 | /// Usually set to include the region name that the physics engine is acting for. | ||
106 | /// </summary> | ||
107 | public string PhysicsSceneName { get; protected set; } | ||
108 | |||
109 | /// <summary> | ||
110 | /// A string identifying the family of this physics engine. Most common values returned | ||
111 | /// are "OpenDynamicsEngine" and "BulletSim" but others are possible. | ||
112 | /// </summary> | ||
113 | public string EngineType { get; protected set; } | ||
114 | |||
115 | // The only thing that should register for this event is the SceneGraph | ||
116 | // Anything else could cause problems. | ||
117 | public event physicsCrash OnPhysicsCrash; | ||
118 | |||
119 | public static PhysicsScene Null | ||
120 | { | ||
121 | get { return new NullPhysicsScene(); } | ||
122 | } | ||
123 | |||
124 | public RequestAssetDelegate RequestAssetMethod { get; set; } | ||
125 | |||
126 | protected void Initialise(RequestAssetDelegate m, float[] terrain, float waterHeight) | ||
127 | { | ||
128 | RequestAssetMethod = m; | ||
129 | SetTerrain(terrain); | ||
130 | SetWaterLevel(waterHeight); | ||
131 | |||
132 | } | ||
133 | |||
134 | public virtual void TriggerPhysicsBasedRestart() | ||
135 | { | ||
136 | physicsCrash handler = OnPhysicsCrash; | ||
137 | if (handler != null) | ||
138 | { | ||
139 | OnPhysicsCrash(); | ||
140 | } | ||
141 | } | ||
142 | |||
143 | /// <summary> | ||
144 | /// Add an avatar | ||
145 | /// </summary> | ||
146 | /// <param name="avName"></param> | ||
147 | /// <param name="position"></param> | ||
148 | /// <param name="velocity"></param> | ||
149 | /// <param name="size"></param> | ||
150 | /// <param name="isFlying"></param> | ||
151 | /// <returns></returns> | ||
152 | |||
153 | public abstract PhysicsActor AddAvatar( | ||
154 | string avName, Vector3 position, Vector3 velocity, Vector3 size, bool isFlying); | ||
155 | |||
156 | /// <summary> | ||
157 | /// Add an avatar | ||
158 | /// </summary> | ||
159 | /// <param name="localID"></param> | ||
160 | /// <param name="avName"></param> | ||
161 | /// <param name="position"></param> | ||
162 | /// <param name="velocity"></param> | ||
163 | /// <param name="size"></param> | ||
164 | /// <param name="isFlying"></param> | ||
165 | /// <returns></returns> | ||
166 | public virtual PhysicsActor AddAvatar( | ||
167 | uint localID, string avName, Vector3 position, Vector3 velocity, Vector3 size, bool isFlying) | ||
168 | { | ||
169 | PhysicsActor ret = AddAvatar(avName, position, velocity, size, isFlying); | ||
170 | |||
171 | if (ret != null) | ||
172 | ret.LocalID = localID; | ||
173 | |||
174 | return ret; | ||
175 | } | ||
176 | |||
177 | public virtual PhysicsActor AddAvatar( | ||
178 | uint localID, string avName, Vector3 position, Vector3 size, bool isFlying) | ||
179 | { | ||
180 | PhysicsActor ret = AddAvatar(localID, avName, position, Vector3.Zero, size, isFlying); | ||
181 | return ret; | ||
182 | } | ||
183 | |||
184 | public virtual PhysicsActor AddAvatar( | ||
185 | uint localID, string avName, Vector3 position, Vector3 size, float feetOffset, bool isFlying) | ||
186 | { | ||
187 | PhysicsActor ret = AddAvatar(localID, avName, position, Vector3.Zero, size, isFlying); | ||
188 | return ret; | ||
189 | } | ||
190 | |||
191 | /// <summary> | ||
192 | /// Remove an avatar. | ||
193 | /// </summary> | ||
194 | /// <param name="actor"></param> | ||
195 | public abstract void RemoveAvatar(PhysicsActor actor); | ||
196 | |||
197 | /// <summary> | ||
198 | /// Remove a prim. | ||
199 | /// </summary> | ||
200 | /// <param name="prim"></param> | ||
201 | public abstract void RemovePrim(PhysicsActor prim); | ||
202 | |||
203 | public abstract PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, Vector3 position, | ||
204 | Vector3 size, Quaternion rotation, bool isPhysical, uint localid); | ||
205 | |||
206 | public virtual PhysicsActor AddPrimShape(string primName, PhysicsActor parent, PrimitiveBaseShape pbs, Vector3 position, | ||
207 | uint localid, byte[] sdata) | ||
208 | { | ||
209 | return null; | ||
210 | } | ||
211 | |||
212 | public virtual PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, Vector3 position, | ||
213 | Vector3 size, Quaternion rotation, bool isPhysical, bool isPhantom, uint localid) | ||
214 | { | ||
215 | return AddPrimShape(primName, pbs, position, size, rotation, isPhysical, localid); | ||
216 | } | ||
217 | |||
218 | |||
219 | public virtual PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, Vector3 position, | ||
220 | Vector3 size, Quaternion rotation, bool isPhysical, bool isPhantom, byte shapetype, uint localid) | ||
221 | { | ||
222 | return AddPrimShape(primName, pbs, position, size, rotation, isPhysical, localid); | ||
223 | } | ||
224 | |||
225 | public virtual float TimeDilation | ||
226 | { | ||
227 | get { return 1.0f; } | ||
228 | } | ||
229 | |||
230 | public virtual bool SupportsNINJAJoints | ||
231 | { | ||
232 | get { return false; } | ||
233 | } | ||
234 | |||
235 | public virtual PhysicsJoint RequestJointCreation(string objectNameInScene, PhysicsJointType jointType, Vector3 position, | ||
236 | Quaternion rotation, string parms, List<string> bodyNames, string trackedBodyName, Quaternion localRotation) | ||
237 | { return null; } | ||
238 | |||
239 | public virtual void RequestJointDeletion(string objectNameInScene) | ||
240 | { return; } | ||
241 | |||
242 | public virtual void RemoveAllJointsConnectedToActorThreadLocked(PhysicsActor actor) | ||
243 | { return; } | ||
244 | |||
245 | public virtual void DumpJointInfo() | ||
246 | { return; } | ||
247 | |||
248 | public event JointMoved OnJointMoved; | ||
249 | |||
250 | protected virtual void DoJointMoved(PhysicsJoint joint) | ||
251 | { | ||
252 | // We need this to allow subclasses (but not other classes) to invoke the event; C# does | ||
253 | // not allow subclasses to invoke the parent class event. | ||
254 | if (OnJointMoved != null) | ||
255 | { | ||
256 | OnJointMoved(joint); | ||
257 | } | ||
258 | } | ||
259 | |||
260 | public event JointDeactivated OnJointDeactivated; | ||
261 | |||
262 | protected virtual void DoJointDeactivated(PhysicsJoint joint) | ||
263 | { | ||
264 | // We need this to allow subclasses (but not other classes) to invoke the event; C# does | ||
265 | // not allow subclasses to invoke the parent class event. | ||
266 | if (OnJointDeactivated != null) | ||
267 | { | ||
268 | OnJointDeactivated(joint); | ||
269 | } | ||
270 | } | ||
271 | |||
272 | public event JointErrorMessage OnJointErrorMessage; | ||
273 | |||
274 | protected virtual void DoJointErrorMessage(PhysicsJoint joint, string message) | ||
275 | { | ||
276 | // We need this to allow subclasses (but not other classes) to invoke the event; C# does | ||
277 | // not allow subclasses to invoke the parent class event. | ||
278 | if (OnJointErrorMessage != null) | ||
279 | { | ||
280 | OnJointErrorMessage(joint, message); | ||
281 | } | ||
282 | } | ||
283 | |||
284 | public virtual Vector3 GetJointAnchor(PhysicsJoint joint) | ||
285 | { return Vector3.Zero; } | ||
286 | |||
287 | public virtual Vector3 GetJointAxis(PhysicsJoint joint) | ||
288 | { return Vector3.Zero; } | ||
289 | |||
290 | public abstract void AddPhysicsActorTaint(PhysicsActor prim); | ||
291 | |||
292 | |||
293 | public virtual void PrepareSimulation() { } | ||
294 | |||
295 | /// <summary> | ||
296 | /// Perform a simulation of the current physics scene over the given timestep. | ||
297 | /// </summary> | ||
298 | /// <param name="timeStep"></param> | ||
299 | /// <returns>The number of frames simulated over that period.</returns> | ||
300 | public abstract float Simulate(float timeStep); | ||
301 | |||
302 | /// <summary> | ||
303 | /// Get statistics about this scene. | ||
304 | /// </summary> | ||
305 | /// <remarks>This facility is currently experimental and subject to change.</remarks> | ||
306 | /// <returns> | ||
307 | /// A dictionary where the key is the statistic name. If no statistics are supplied then returns null. | ||
308 | /// </returns> | ||
309 | public virtual Dictionary<string, float> GetStats() { return null; } | ||
310 | |||
311 | public abstract void GetResults(); | ||
312 | |||
313 | public abstract void SetTerrain(float[] heightMap); | ||
314 | |||
315 | public abstract void SetWaterLevel(float baseheight); | ||
316 | |||
317 | public abstract void DeleteTerrain(); | ||
318 | |||
319 | public abstract void Dispose(); | ||
320 | |||
321 | public abstract Dictionary<uint, float> GetTopColliders(); | ||
322 | |||
323 | public abstract bool IsThreaded { get; } | ||
324 | |||
325 | /// <summary> | ||
326 | /// True if the physics plugin supports raycasting against the physics scene | ||
327 | /// </summary> | ||
328 | public virtual bool SupportsRayCast() | ||
329 | { | ||
330 | return false; | ||
331 | } | ||
332 | |||
333 | public virtual bool SupportsCombining() | ||
334 | { | ||
335 | return false; | ||
336 | } | ||
337 | |||
338 | public virtual void Combine(PhysicsScene pScene, Vector3 offset, Vector3 extents) {} | ||
339 | public virtual void CombineTerrain(float[] heightMap, Vector3 pOffset) {} | ||
340 | public virtual void UnCombine(PhysicsScene pScene) {} | ||
341 | |||
342 | /// <summary> | ||
343 | /// Queue a raycast against the physics scene. | ||
344 | /// The provided callback method will be called when the raycast is complete | ||
345 | /// | ||
346 | /// Many physics engines don't support collision testing at the same time as | ||
347 | /// manipulating the physics scene, so we queue the request up and callback | ||
348 | /// a custom method when the raycast is complete. | ||
349 | /// This allows physics engines that give an immediate result to callback immediately | ||
350 | /// and ones that don't, to callback when it gets a result back. | ||
351 | /// | ||
352 | /// ODE for example will not allow you to change the scene while collision testing or | ||
353 | /// it asserts, 'opteration not valid for locked space'. This includes adding a ray to the scene. | ||
354 | /// | ||
355 | /// This is named RayCastWorld to not conflict with modrex's Raycast method. | ||
356 | /// </summary> | ||
357 | /// <param name="position">Origin of the ray</param> | ||
358 | /// <param name="direction">Direction of the ray</param> | ||
359 | /// <param name="length">Length of ray in meters</param> | ||
360 | /// <param name="retMethod">Method to call when the raycast is complete</param> | ||
361 | public virtual void RaycastWorld(Vector3 position, Vector3 direction, float length, RaycastCallback retMethod) | ||
362 | { | ||
363 | if (retMethod != null) | ||
364 | retMethod(false, Vector3.Zero, 0, 999999999999f, Vector3.Zero); | ||
365 | } | ||
366 | |||
367 | public virtual void RaycastWorld(Vector3 position, Vector3 direction, float length, int Count, RayCallback retMethod) | ||
368 | { | ||
369 | if (retMethod != null) | ||
370 | retMethod(new List<ContactResult>()); | ||
371 | } | ||
372 | |||
373 | public virtual List<ContactResult> RaycastWorld(Vector3 position, Vector3 direction, float length, int Count) | ||
374 | { | ||
375 | return new List<ContactResult>(); | ||
376 | } | ||
377 | |||
378 | public virtual object RaycastWorld(Vector3 position, Vector3 direction, float length, int Count, RayFilterFlags filter) | ||
379 | { | ||
380 | return null; | ||
381 | } | ||
382 | |||
383 | public virtual bool SupportsRaycastWorldFiltered() | ||
384 | { | ||
385 | return false; | ||
386 | } | ||
387 | |||
388 | public virtual List<ContactResult> RaycastActor(PhysicsActor actor, Vector3 position, Vector3 direction, float length, int Count, RayFilterFlags flags) | ||
389 | { | ||
390 | return new List<ContactResult>(); | ||
391 | } | ||
392 | |||
393 | public virtual List<ContactResult> BoxProbe(Vector3 position, Vector3 size, Quaternion orientation, int Count, RayFilterFlags flags) | ||
394 | { | ||
395 | return new List<ContactResult>(); | ||
396 | } | ||
397 | |||
398 | public virtual List<ContactResult> SphereProbe(Vector3 position, float radius, int Count, RayFilterFlags flags) | ||
399 | { | ||
400 | return new List<ContactResult>(); | ||
401 | } | ||
402 | |||
403 | public virtual List<ContactResult> PlaneProbe(PhysicsActor actor, Vector4 plane, int Count, RayFilterFlags flags) | ||
404 | { | ||
405 | return new List<ContactResult>(); | ||
406 | } | ||
407 | |||
408 | public virtual int SitAvatar(PhysicsActor actor, Vector3 AbsolutePosition, Vector3 CameraPosition, Vector3 offset, Vector3 AvatarSize, SitAvatarCallback PhysicsSitResponse) | ||
409 | { | ||
410 | return 0; | ||
411 | } | ||
412 | |||
413 | // Extendable interface for new, physics engine specific operations | ||
414 | public virtual object Extension(string pFunct, params object[] pParams) | ||
415 | { | ||
416 | // A NOP if the extension thing is not implemented by the physics engine | ||
417 | return null; | ||
418 | } | ||
419 | } | ||
420 | } | ||
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 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Timers; | ||
30 | using OpenMetaverse; | ||
31 | |||
32 | namespace OpenSim.Region.PhysicsModules.SharedBase | ||
33 | { | ||
34 | [Flags] | ||
35 | public enum SenseType : uint | ||
36 | { | ||
37 | NONE = 0, | ||
38 | AGENT = 1, | ||
39 | ACTIVE = 2, | ||
40 | PASSIVE = 3, | ||
41 | SCRIPTED = 4 | ||
42 | } | ||
43 | |||
44 | public abstract class PhysicsSensor | ||
45 | { | ||
46 | public static PhysicsSensor Null | ||
47 | { | ||
48 | get { return new NullPhysicsSensor(); } | ||
49 | } | ||
50 | public abstract Vector3 Position { get; set; } | ||
51 | public abstract void TimerCallback (object obj, ElapsedEventArgs eea); | ||
52 | public abstract float radianarc {get; set;} | ||
53 | public abstract string targetname {get; set;} | ||
54 | public abstract Guid targetKey{get;set;} | ||
55 | public abstract SenseType sensetype { get;set;} | ||
56 | public abstract float range { get;set;} | ||
57 | public abstract float rateSeconds { get;set;} | ||
58 | } | ||
59 | |||
60 | public class NullPhysicsSensor : PhysicsSensor | ||
61 | { | ||
62 | public override Vector3 Position | ||
63 | { | ||
64 | get { return Vector3.Zero; } | ||
65 | set { return; } | ||
66 | } | ||
67 | public override void TimerCallback(object obj, ElapsedEventArgs eea) | ||
68 | { | ||
69 | // don't do squat | ||
70 | } | ||
71 | public override float radianarc { get { return 0f; } set { } } | ||
72 | public override string targetname { get { return ""; } set { } } | ||
73 | public override Guid targetKey { get { return Guid.Empty; } set { } } | ||
74 | public override SenseType sensetype { get { return SenseType.NONE; } set { } } | ||
75 | public override float range { get { return 0; } set { } } | ||
76 | public override float rateSeconds { get { return 0; } set { } } | ||
77 | } | ||
78 | } | ||
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 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | |||
30 | namespace OpenSim.Region.PhysicsModules.SharedBase | ||
31 | { | ||
32 | /*public class PhysicsVector | ||
33 | { | ||
34 | public float X; | ||
35 | public float Y; | ||
36 | public float Z; | ||
37 | |||
38 | public Vector3() | ||
39 | { | ||
40 | } | ||
41 | |||
42 | public Vector3(float x, float y, float z) | ||
43 | { | ||
44 | X = x; | ||
45 | Y = y; | ||
46 | Z = z; | ||
47 | } | ||
48 | |||
49 | public Vector3(Vector3 pv) : this(pv.X, pv.Y, pv.Z) | ||
50 | { | ||
51 | } | ||
52 | |||
53 | public void setValues(float x, float y, float z) | ||
54 | { | ||
55 | X = x; | ||
56 | Y = y; | ||
57 | Z = z; | ||
58 | } | ||
59 | |||
60 | public static readonly PhysicsVector Zero = new PhysicsVector(0f, 0f, 0f); | ||
61 | |||
62 | public override string ToString() | ||
63 | { | ||
64 | return "<" + X + "," + Y + "," + Z + ">"; | ||
65 | } | ||
66 | |||
67 | /// <summary> | ||
68 | /// These routines are the easiest way to store XYZ values in an Vector3 without requiring 3 calls. | ||
69 | /// </summary> | ||
70 | /// <returns></returns> | ||
71 | public byte[] GetBytes() | ||
72 | { | ||
73 | byte[] byteArray = new byte[12]; | ||
74 | |||
75 | Buffer.BlockCopy(BitConverter.GetBytes(X), 0, byteArray, 0, 4); | ||
76 | Buffer.BlockCopy(BitConverter.GetBytes(Y), 0, byteArray, 4, 4); | ||
77 | Buffer.BlockCopy(BitConverter.GetBytes(Z), 0, byteArray, 8, 4); | ||
78 | |||
79 | if (!BitConverter.IsLittleEndian) | ||
80 | { | ||
81 | Array.Reverse(byteArray, 0, 4); | ||
82 | Array.Reverse(byteArray, 4, 4); | ||
83 | Array.Reverse(byteArray, 8, 4); | ||
84 | } | ||
85 | |||
86 | return byteArray; | ||
87 | } | ||
88 | |||
89 | public void FromBytes(byte[] byteArray, int pos) | ||
90 | { | ||
91 | byte[] conversionBuffer = null; | ||
92 | if (!BitConverter.IsLittleEndian) | ||
93 | { | ||
94 | // Big endian architecture | ||
95 | if (conversionBuffer == null) | ||
96 | conversionBuffer = new byte[12]; | ||
97 | |||
98 | Buffer.BlockCopy(byteArray, pos, conversionBuffer, 0, 12); | ||
99 | |||
100 | Array.Reverse(conversionBuffer, 0, 4); | ||
101 | Array.Reverse(conversionBuffer, 4, 4); | ||
102 | Array.Reverse(conversionBuffer, 8, 4); | ||
103 | |||
104 | X = BitConverter.ToSingle(conversionBuffer, 0); | ||
105 | Y = BitConverter.ToSingle(conversionBuffer, 4); | ||
106 | Z = BitConverter.ToSingle(conversionBuffer, 8); | ||
107 | } | ||
108 | else | ||
109 | { | ||
110 | // Little endian architecture | ||
111 | X = BitConverter.ToSingle(byteArray, pos); | ||
112 | Y = BitConverter.ToSingle(byteArray, pos + 4); | ||
113 | Z = BitConverter.ToSingle(byteArray, pos + 8); | ||
114 | } | ||
115 | } | ||
116 | |||
117 | // Operations | ||
118 | public static PhysicsVector operator +(Vector3 a, Vector3 b) | ||
119 | { | ||
120 | return new PhysicsVector(a.X + b.X, a.Y + b.Y, a.Z + b.Z); | ||
121 | } | ||
122 | |||
123 | public static PhysicsVector operator -(Vector3 a, Vector3 b) | ||
124 | { | ||
125 | return new PhysicsVector(a.X - b.X, a.Y - b.Y, a.Z - b.Z); | ||
126 | } | ||
127 | |||
128 | public static PhysicsVector cross(Vector3 a, Vector3 b) | ||
129 | { | ||
130 | 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); | ||
131 | } | ||
132 | |||
133 | public float length() | ||
134 | { | ||
135 | return (float) Math.Sqrt(X*X + Y*Y + Z*Z); | ||
136 | } | ||
137 | |||
138 | public static float GetDistanceTo(Vector3 a, Vector3 b) | ||
139 | { | ||
140 | float dx = a.X - b.X; | ||
141 | float dy = a.Y - b.Y; | ||
142 | float dz = a.Z - b.Z; | ||
143 | return (float) Math.Sqrt(dx * dx + dy * dy + dz * dz); | ||
144 | } | ||
145 | |||
146 | public static PhysicsVector operator /(Vector3 v, float f) | ||
147 | { | ||
148 | return new PhysicsVector(v.X/f, v.Y/f, v.Z/f); | ||
149 | } | ||
150 | |||
151 | public static PhysicsVector operator *(Vector3 v, float f) | ||
152 | { | ||
153 | return new PhysicsVector(v.X*f, v.Y*f, v.Z*f); | ||
154 | } | ||
155 | |||
156 | public static PhysicsVector operator *(float f, Vector3 v) | ||
157 | { | ||
158 | return v*f; | ||
159 | } | ||
160 | |||
161 | public static bool isFinite(Vector3 v) | ||
162 | { | ||
163 | if (v == null) | ||
164 | return false; | ||
165 | if (Single.IsInfinity(v.X) || Single.IsNaN(v.X)) | ||
166 | return false; | ||
167 | if (Single.IsInfinity(v.Y) || Single.IsNaN(v.Y)) | ||
168 | return false; | ||
169 | if (Single.IsInfinity(v.Z) || Single.IsNaN(v.Z)) | ||
170 | return false; | ||
171 | |||
172 | return true; | ||
173 | } | ||
174 | |||
175 | public virtual bool IsIdentical(Vector3 v, float tolerance) | ||
176 | { | ||
177 | PhysicsVector diff = this - v; | ||
178 | float d = diff.length(); | ||
179 | if (d <= tolerance) | ||
180 | return true; | ||
181 | |||
182 | return false; | ||
183 | } | ||
184 | |||
185 | }*/ | ||
186 | } | ||
diff --git a/OpenSim/Region/PhysicsModules/SharedBase/VehicleConstants.cs b/OpenSim/Region/PhysicsModules/SharedBase/VehicleConstants.cs new file mode 100644 index 0000000..e850b11 --- /dev/null +++ b/OpenSim/Region/PhysicsModules/SharedBase/VehicleConstants.cs | |||
@@ -0,0 +1,164 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using OpenMetaverse; | ||
30 | |||
31 | namespace OpenSim.Region.PhysicsModules.SharedBase | ||
32 | { | ||
33 | public enum Vehicle : int | ||
34 | { | ||
35 | /// <summary> | ||
36 | /// Turns off Vehicle Support | ||
37 | /// </summary> | ||
38 | TYPE_NONE = 0, | ||
39 | |||
40 | /// <summary> | ||
41 | /// No Angular motor, High Left right friction, No Hover, Linear Deflection 1, no angular deflection | ||
42 | /// no vertical attractor, No banking, Identity rotation frame | ||
43 | /// </summary> | ||
44 | TYPE_SLED = 1, | ||
45 | |||
46 | /// <summary> | ||
47 | /// Needs Motors to be driven by timer or control events High left/right friction, No angular friction | ||
48 | /// Linear Motor wins in a second, decays in 60 seconds. Angular motor wins in a second, decays in 8/10ths of a second | ||
49 | /// linear deflection 2 seconds | ||
50 | /// Vertical Attractor locked UP | ||
51 | /// </summary> | ||
52 | TYPE_CAR = 2, | ||
53 | TYPE_BOAT = 3, | ||
54 | TYPE_AIRPLANE = 4, | ||
55 | TYPE_BALLOON = 5, | ||
56 | LINEAR_FRICTION_TIMESCALE = 16, | ||
57 | /// <summary> | ||
58 | /// vector of timescales for exponential decay of angular velocity about three axis | ||
59 | /// </summary> | ||
60 | ANGULAR_FRICTION_TIMESCALE = 17, | ||
61 | /// <summary> | ||
62 | /// linear velocity vehicle will try for | ||
63 | /// </summary> | ||
64 | LINEAR_MOTOR_DIRECTION = 18, | ||
65 | |||
66 | /// <summary> | ||
67 | /// Offset from center of mass where linear motor forces are added | ||
68 | /// </summary> | ||
69 | LINEAR_MOTOR_OFFSET = 20, | ||
70 | /// <summary> | ||
71 | /// angular velocity that vehicle will try for | ||
72 | /// </summary> | ||
73 | ANGULAR_MOTOR_DIRECTION = 19, | ||
74 | HOVER_HEIGHT = 24, | ||
75 | HOVER_EFFICIENCY = 25, | ||
76 | HOVER_TIMESCALE = 26, | ||
77 | BUOYANCY = 27, | ||
78 | LINEAR_DEFLECTION_EFFICIENCY = 28, | ||
79 | LINEAR_DEFLECTION_TIMESCALE = 29, | ||
80 | LINEAR_MOTOR_TIMESCALE = 30, | ||
81 | LINEAR_MOTOR_DECAY_TIMESCALE = 31, | ||
82 | |||
83 | /// <summary> | ||
84 | /// slide between 0 and 1 | ||
85 | /// </summary> | ||
86 | ANGULAR_DEFLECTION_EFFICIENCY = 32, | ||
87 | ANGULAR_DEFLECTION_TIMESCALE = 33, | ||
88 | ANGULAR_MOTOR_TIMESCALE = 34, | ||
89 | ANGULAR_MOTOR_DECAY_TIMESCALE = 35, | ||
90 | VERTICAL_ATTRACTION_EFFICIENCY = 36, | ||
91 | VERTICAL_ATTRACTION_TIMESCALE = 37, | ||
92 | BANKING_EFFICIENCY = 38, | ||
93 | BANKING_MIX = 39, | ||
94 | BANKING_TIMESCALE = 40, | ||
95 | REFERENCE_FRAME = 44, | ||
96 | BLOCK_EXIT = 45, | ||
97 | ROLL_FRAME = 46 | ||
98 | |||
99 | } | ||
100 | |||
101 | [Flags] | ||
102 | public enum VehicleFlag | ||
103 | { | ||
104 | NO_DEFLECTION_UP = 1, | ||
105 | LIMIT_ROLL_ONLY = 2, | ||
106 | HOVER_WATER_ONLY = 4, | ||
107 | HOVER_TERRAIN_ONLY = 8, | ||
108 | HOVER_GLOBAL_HEIGHT = 16, | ||
109 | HOVER_UP_ONLY = 32, | ||
110 | LIMIT_MOTOR_UP = 64, | ||
111 | MOUSELOOK_STEER = 128, | ||
112 | MOUSELOOK_BANK = 256, | ||
113 | CAMERA_DECOUPLED = 512, | ||
114 | NO_X = 1024, | ||
115 | NO_Y = 2048, | ||
116 | NO_Z = 4096, | ||
117 | LOCK_HOVER_HEIGHT = 8192, | ||
118 | NO_DEFLECTION = 16392, | ||
119 | LOCK_ROTATION = 32784 | ||
120 | } | ||
121 | |||
122 | public struct VehicleData | ||
123 | { | ||
124 | public Vehicle m_type; | ||
125 | public VehicleFlag m_flags; | ||
126 | |||
127 | // Linear properties | ||
128 | public Vector3 m_linearMotorDirection; | ||
129 | public Vector3 m_linearFrictionTimescale; | ||
130 | public float m_linearMotorDecayTimescale; | ||
131 | public float m_linearMotorTimescale; | ||
132 | public Vector3 m_linearMotorOffset; | ||
133 | |||
134 | //Angular properties | ||
135 | public Vector3 m_angularMotorDirection; | ||
136 | public float m_angularMotorTimescale; | ||
137 | public float m_angularMotorDecayTimescale; | ||
138 | public Vector3 m_angularFrictionTimescale; | ||
139 | |||
140 | //Deflection properties | ||
141 | public float m_angularDeflectionEfficiency; | ||
142 | public float m_angularDeflectionTimescale; | ||
143 | public float m_linearDeflectionEfficiency; | ||
144 | public float m_linearDeflectionTimescale; | ||
145 | |||
146 | //Banking properties | ||
147 | public float m_bankingEfficiency; | ||
148 | public float m_bankingMix; | ||
149 | public float m_bankingTimescale; | ||
150 | |||
151 | //Hover and Buoyancy properties | ||
152 | public float m_VhoverHeight; | ||
153 | public float m_VhoverEfficiency; | ||
154 | public float m_VhoverTimescale; | ||
155 | public float m_VehicleBuoyancy; | ||
156 | |||
157 | //Attractor properties | ||
158 | public float m_verticalAttractionEfficiency; | ||
159 | public float m_verticalAttractionTimescale; | ||
160 | |||
161 | // Axis | ||
162 | public Quaternion m_referenceFrame; | ||
163 | } | ||
164 | } | ||