diff options
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs')
-rw-r--r-- | OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs | 186 |
1 files changed, 186 insertions, 0 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs b/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs new file mode 100644 index 0000000..b2bc0d7 --- /dev/null +++ b/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.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 copyrightD | ||
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 | using System; | ||
28 | using System.Runtime.InteropServices; | ||
29 | using System.Security; | ||
30 | using System.Text; | ||
31 | using OpenMetaverse; | ||
32 | |||
33 | namespace OpenSim.Region.Physics.BulletSPlugin { | ||
34 | |||
35 | public struct ConvexHull | ||
36 | { | ||
37 | Vector3 Offset; | ||
38 | int VertexCount; | ||
39 | Vector3[] Vertices; | ||
40 | } | ||
41 | public struct ShapeData | ||
42 | { | ||
43 | public enum PhysicsShapeType | ||
44 | { | ||
45 | SHAPE_AVATAR = 0, | ||
46 | SHAPE_BOX = 1, | ||
47 | SHAPE_CONE = 2, | ||
48 | SHAPE_CYLINDER = 3, | ||
49 | SHAPE_SPHERE = 4, | ||
50 | SHAPE_HULL = 5 | ||
51 | }; | ||
52 | public const int numericTrue = 1; | ||
53 | public const int numericFalse = 0; | ||
54 | public uint ID; | ||
55 | public PhysicsShapeType Type; | ||
56 | public Vector3 Position; | ||
57 | public Quaternion Rotation; | ||
58 | public Vector3 Velocity; | ||
59 | public Vector3 Scale; | ||
60 | public float Mass; | ||
61 | public float Buoyancy; | ||
62 | public System.UInt64 MeshKey; | ||
63 | public int Collidable; | ||
64 | public float Friction; | ||
65 | public int Static; // true if a static object. Otherwise gravity, etc. | ||
66 | // note that bools are passed as ints since bool size changes by language | ||
67 | } | ||
68 | public struct SweepHit | ||
69 | { | ||
70 | public uint ID; | ||
71 | public float Fraction; | ||
72 | public Vector3 Normal; | ||
73 | public Vector3 Point; | ||
74 | } | ||
75 | public struct RaycastHit | ||
76 | { | ||
77 | public uint ID; | ||
78 | public float Fraction; | ||
79 | public Vector3 Normal; | ||
80 | } | ||
81 | |||
82 | public struct EntityProperties | ||
83 | { | ||
84 | public uint ID; | ||
85 | public Vector3 Position; | ||
86 | public Quaternion Rotation; | ||
87 | public Vector3 Velocity; | ||
88 | public Vector3 Acceleration; | ||
89 | public Vector3 AngularVelocity; | ||
90 | } | ||
91 | |||
92 | static class BulletSimAPI { | ||
93 | |||
94 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
95 | public static extern uint Initialize(Vector3 maxPosition); | ||
96 | |||
97 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
98 | public static extern void SetHeightmap(uint worldID, [MarshalAs(UnmanagedType.LPArray)] float[] heightMap); | ||
99 | |||
100 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
101 | public static extern void Shutdown(uint worldID); | ||
102 | |||
103 | |||
104 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
105 | public static extern int PhysicsStep(uint worldID, float timeStep, int maxSubSteps, float fixedTimeStep, | ||
106 | out int updatedEntityCount, | ||
107 | out IntPtr updatedEntitiesPtr, | ||
108 | out int collidersCount, | ||
109 | out IntPtr collidersPtr); | ||
110 | |||
111 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
112 | public static extern bool CreateHull(uint worldID, System.UInt64 meshKey, int hullCount, | ||
113 | [MarshalAs(UnmanagedType.LPArray)] float[] hulls | ||
114 | ); | ||
115 | |||
116 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
117 | public static extern bool DestroyHull(uint worldID, System.UInt64 meshKey); | ||
118 | |||
119 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
120 | public static extern bool CreateObject(uint worldID, ShapeData shapeData); | ||
121 | |||
122 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
123 | public static extern void CreateLinkset(uint worldID, int objectCount, ShapeData[] shapeDatas); | ||
124 | |||
125 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
126 | public static extern void AddConstraint(uint worldID, uint id1, uint id2, | ||
127 | Vector3 frame1, Vector3 frame2, Vector3 lowLinear, Vector3 hiLinear, Vector3 lowAngular, Vector3 hiAngular); | ||
128 | |||
129 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
130 | public static extern bool RemoveConstraint(uint worldID, uint id1, uint id2); | ||
131 | |||
132 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
133 | public static extern Vector3 GetObjectPosition(uint WorldID, uint id); | ||
134 | |||
135 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
136 | public static extern bool SetObjectTranslation(uint worldID, uint id, Vector3 position, Quaternion rotation); | ||
137 | |||
138 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
139 | public static extern bool SetObjectVelocity(uint worldID, uint id, Vector3 velocity); | ||
140 | |||
141 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
142 | public static extern bool SetObjectAngularVelocity(uint worldID, uint id, Vector3 angularVelocity); | ||
143 | |||
144 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
145 | public static extern bool SetObjectForce(uint worldID, uint id, Vector3 force); | ||
146 | |||
147 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
148 | public static extern bool SetObjectScaleMass(uint worldID, uint id, Vector3 scale, float mass, bool isDynamic); | ||
149 | |||
150 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
151 | public static extern bool SetObjectCollidable(uint worldID, uint id, bool phantom); | ||
152 | |||
153 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
154 | public static extern bool SetObjectDynamic(uint worldID, uint id, bool isDynamic, float mass); | ||
155 | |||
156 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
157 | public static extern bool SetObjectGhost(uint worldID, uint id, bool ghostly); | ||
158 | |||
159 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
160 | public static extern bool SetObjectProperties(uint worldID, uint id, bool isStatic, bool isSolid, bool genCollisions, float mass); | ||
161 | |||
162 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
163 | public static extern bool SetObjectBuoyancy(uint worldID, uint id, float buoyancy); | ||
164 | |||
165 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
166 | public static extern bool HasObject(uint worldID, uint id); | ||
167 | |||
168 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
169 | public static extern bool DestroyObject(uint worldID, uint id); | ||
170 | |||
171 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
172 | public static extern SweepHit ConvexSweepTest(uint worldID, uint id, Vector3 to, float extraMargin); | ||
173 | |||
174 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
175 | public static extern RaycastHit RayTest(uint worldID, uint id, Vector3 from, Vector3 to); | ||
176 | |||
177 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
178 | public static extern Vector3 RecoverFromPenetration(uint worldID, uint id); | ||
179 | |||
180 | // Log a debug message | ||
181 | [UnmanagedFunctionPointer(CallingConvention.Cdecl)] | ||
182 | public delegate void DebugLogCallback([MarshalAs(UnmanagedType.LPStr)]string msg); | ||
183 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
184 | public static extern void SetDebugLogCallback(DebugLogCallback callback); | ||
185 | } | ||
186 | } | ||