diff options
author | Justin Clark-Casey (justincc) | 2013-01-24 00:02:43 +0000 |
---|---|---|
committer | Justin Clark-Casey (justincc) | 2013-01-24 00:02:43 +0000 |
commit | a1f78ceb37dda544f8d04aa00bf3fedd298f024e (patch) | |
tree | e3f9b4f03f712dc63a4aefc5ac389f9b1c36ed8d /OpenSim/Region/Physics/BulletSNPlugin/BulletSimAPI.cs | |
parent | New constants for llGetObjectDetails (diff) | |
parent | BulletSim: remove setting of vehicle InterpolationRotationalVelocity. (diff) | |
download | opensim-SC-a1f78ceb37dda544f8d04aa00bf3fedd298f024e.zip opensim-SC-a1f78ceb37dda544f8d04aa00bf3fedd298f024e.tar.gz opensim-SC-a1f78ceb37dda544f8d04aa00bf3fedd298f024e.tar.bz2 opensim-SC-a1f78ceb37dda544f8d04aa00bf3fedd298f024e.tar.xz |
Merge branch 'master' of ssh://opensimulator.org/var/git/opensim
Diffstat (limited to 'OpenSim/Region/Physics/BulletSNPlugin/BulletSimAPI.cs')
-rw-r--r-- | OpenSim/Region/Physics/BulletSNPlugin/BulletSimAPI.cs | 1603 |
1 files changed, 0 insertions, 1603 deletions
diff --git a/OpenSim/Region/Physics/BulletSNPlugin/BulletSimAPI.cs b/OpenSim/Region/Physics/BulletSNPlugin/BulletSimAPI.cs deleted file mode 100644 index 93643c9..0000000 --- a/OpenSim/Region/Physics/BulletSNPlugin/BulletSimAPI.cs +++ /dev/null | |||
@@ -1,1603 +0,0 @@ | |||
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.Collections.Generic; | ||
29 | using System.IO; | ||
30 | using System.Runtime.InteropServices; | ||
31 | using System.Security; | ||
32 | using System.Text; | ||
33 | using BulletXNA; | ||
34 | using OpenMetaverse; | ||
35 | using BulletXNA.LinearMath; | ||
36 | using BulletXNA.BulletCollision; | ||
37 | using BulletXNA.BulletDynamics; | ||
38 | using BulletXNA.BulletCollision.CollisionDispatch; | ||
39 | using OpenSim.Framework; | ||
40 | |||
41 | namespace OpenSim.Region.Physics.BulletSNPlugin { | ||
42 | |||
43 | // Classes to allow some type checking for the API | ||
44 | // These hold pointers to allocated objects in the unmanaged space. | ||
45 | |||
46 | |||
47 | |||
48 | // Constraint type values as defined by Bullet | ||
49 | public enum ConstraintType : int | ||
50 | { | ||
51 | POINT2POINT_CONSTRAINT_TYPE = 3, | ||
52 | HINGE_CONSTRAINT_TYPE, | ||
53 | CONETWIST_CONSTRAINT_TYPE, | ||
54 | D6_CONSTRAINT_TYPE, | ||
55 | SLIDER_CONSTRAINT_TYPE, | ||
56 | CONTACT_CONSTRAINT_TYPE, | ||
57 | D6_SPRING_CONSTRAINT_TYPE, | ||
58 | MAX_CONSTRAINT_TYPE | ||
59 | } | ||
60 | |||
61 | // =============================================================================== | ||
62 | [StructLayout(LayoutKind.Sequential)] | ||
63 | public struct ConvexHull | ||
64 | { | ||
65 | Vector3 Offset; | ||
66 | int VertexCount; | ||
67 | Vector3[] Vertices; | ||
68 | } | ||
69 | public enum BSPhysicsShapeType | ||
70 | { | ||
71 | SHAPE_UNKNOWN = 0, | ||
72 | SHAPE_CAPSULE = 1, | ||
73 | SHAPE_BOX = 2, | ||
74 | SHAPE_CONE = 3, | ||
75 | SHAPE_CYLINDER = 4, | ||
76 | SHAPE_SPHERE = 5, | ||
77 | SHAPE_MESH = 6, | ||
78 | SHAPE_HULL = 7, | ||
79 | // following defined by BulletSim | ||
80 | SHAPE_GROUNDPLANE = 20, | ||
81 | SHAPE_TERRAIN = 21, | ||
82 | SHAPE_COMPOUND = 22, | ||
83 | SHAPE_HEIGHTMAP = 23, | ||
84 | }; | ||
85 | |||
86 | // The native shapes have predefined shape hash keys | ||
87 | public enum FixedShapeKey : ulong | ||
88 | { | ||
89 | KEY_NONE = 0, | ||
90 | KEY_BOX = 1, | ||
91 | KEY_SPHERE = 2, | ||
92 | KEY_CONE = 3, | ||
93 | KEY_CYLINDER = 4, | ||
94 | KEY_CAPSULE = 5, | ||
95 | } | ||
96 | |||
97 | [StructLayout(LayoutKind.Sequential)] | ||
98 | public struct ShapeData | ||
99 | { | ||
100 | public uint ID; | ||
101 | public BSPhysicsShapeType Type; | ||
102 | public Vector3 Position; | ||
103 | public Quaternion Rotation; | ||
104 | public Vector3 Velocity; | ||
105 | public Vector3 Scale; | ||
106 | public float Mass; | ||
107 | public float Buoyancy; | ||
108 | public System.UInt64 HullKey; | ||
109 | public System.UInt64 MeshKey; | ||
110 | public float Friction; | ||
111 | public float Restitution; | ||
112 | public float Collidable; // true of things bump into this | ||
113 | public float Static; // true if a static object. Otherwise gravity, etc. | ||
114 | public float Solid; // true if object cannot be passed through | ||
115 | public Vector3 Size; | ||
116 | |||
117 | // note that bools are passed as floats since bool size changes by language and architecture | ||
118 | public const float numericTrue = 1f; | ||
119 | public const float numericFalse = 0f; | ||
120 | } | ||
121 | [StructLayout(LayoutKind.Sequential)] | ||
122 | public struct SweepHit | ||
123 | { | ||
124 | public uint ID; | ||
125 | public float Fraction; | ||
126 | public Vector3 Normal; | ||
127 | public Vector3 Point; | ||
128 | } | ||
129 | [StructLayout(LayoutKind.Sequential)] | ||
130 | public struct RaycastHit | ||
131 | { | ||
132 | public uint ID; | ||
133 | public float Fraction; | ||
134 | public Vector3 Normal; | ||
135 | } | ||
136 | [StructLayout(LayoutKind.Sequential)] | ||
137 | public struct CollisionDesc | ||
138 | { | ||
139 | public uint aID; | ||
140 | public uint bID; | ||
141 | public Vector3 point; | ||
142 | public Vector3 normal; | ||
143 | } | ||
144 | [StructLayout(LayoutKind.Sequential)] | ||
145 | public struct EntityProperties | ||
146 | { | ||
147 | public uint ID; | ||
148 | public Vector3 Position; | ||
149 | public Quaternion Rotation; | ||
150 | public Vector3 Velocity; | ||
151 | public Vector3 Acceleration; | ||
152 | public Vector3 RotationalVelocity; | ||
153 | public override string ToString() | ||
154 | { | ||
155 | return string.Format("ID:{0}, Pos:<{1:F},{2:F},{3:F}>, Rot:<{4:F},{5:F},{6:F},{7:F}>, LVel:<{8:F},{9:F},{10:F}>, AVel:<{11:F},{12:F},{13:F}>", | ||
156 | ID.ToString(), | ||
157 | Position.X,Position.Y,Position.Z, | ||
158 | Rotation.X,Rotation.Y,Rotation.Z,Rotation.W, | ||
159 | Velocity.X,Velocity.Y,Velocity.Z, | ||
160 | RotationalVelocity.X,RotationalVelocity.Y,RotationalVelocity.Z | ||
161 | ); | ||
162 | } | ||
163 | } | ||
164 | |||
165 | // Format of this structure must match the definition in the C++ code | ||
166 | // NOTE: adding the X causes compile breaks if used. These are unused symbols | ||
167 | // that can be removed from both here and the unmanaged definition of this structure. | ||
168 | [StructLayout(LayoutKind.Sequential)] | ||
169 | public struct ConfigurationParameters | ||
170 | { | ||
171 | public float defaultFriction; | ||
172 | public float defaultDensity; | ||
173 | public float defaultRestitution; | ||
174 | public float collisionMargin; | ||
175 | public float gravity; | ||
176 | |||
177 | public float XlinearDamping; | ||
178 | public float XangularDamping; | ||
179 | public float XdeactivationTime; | ||
180 | public float XlinearSleepingThreshold; | ||
181 | public float XangularSleepingThreshold; | ||
182 | public float XccdMotionThreshold; | ||
183 | public float XccdSweptSphereRadius; | ||
184 | public float XcontactProcessingThreshold; | ||
185 | |||
186 | public float XterrainImplementation; | ||
187 | public float XterrainFriction; | ||
188 | public float XterrainHitFraction; | ||
189 | public float XterrainRestitution; | ||
190 | public float XterrainCollisionMargin; | ||
191 | |||
192 | public float XavatarFriction; | ||
193 | public float XavatarStandingFriction; | ||
194 | public float XavatarDensity; | ||
195 | public float XavatarRestitution; | ||
196 | public float XavatarCapsuleWidth; | ||
197 | public float XavatarCapsuleDepth; | ||
198 | public float XavatarCapsuleHeight; | ||
199 | public float XavatarContactProcessingThreshold; | ||
200 | |||
201 | public float XvehicleAngularDamping; | ||
202 | |||
203 | public float maxPersistantManifoldPoolSize; | ||
204 | public float maxCollisionAlgorithmPoolSize; | ||
205 | public float shouldDisableContactPoolDynamicAllocation; | ||
206 | public float shouldForceUpdateAllAabbs; | ||
207 | public float shouldRandomizeSolverOrder; | ||
208 | public float shouldSplitSimulationIslands; | ||
209 | public float shouldEnableFrictionCaching; | ||
210 | public float numberOfSolverIterations; | ||
211 | |||
212 | public float XlinksetImplementation; | ||
213 | public float XlinkConstraintUseFrameOffset; | ||
214 | public float XlinkConstraintEnableTransMotor; | ||
215 | public float XlinkConstraintTransMotorMaxVel; | ||
216 | public float XlinkConstraintTransMotorMaxForce; | ||
217 | public float XlinkConstraintERP; | ||
218 | public float XlinkConstraintCFM; | ||
219 | public float XlinkConstraintSolverIterations; | ||
220 | |||
221 | public float physicsLoggingFrames; | ||
222 | |||
223 | public const float numericTrue = 1f; | ||
224 | public const float numericFalse = 0f; | ||
225 | } | ||
226 | |||
227 | |||
228 | // The states a bullet collision object can have | ||
229 | |||
230 | public enum ActivationState : uint | ||
231 | { | ||
232 | UNDEFINED = 0, | ||
233 | ACTIVE_TAG = 1, | ||
234 | ISLAND_SLEEPING = 2, | ||
235 | WANTS_DEACTIVATION = 3, | ||
236 | DISABLE_DEACTIVATION = 4, | ||
237 | DISABLE_SIMULATION = 5, | ||
238 | } | ||
239 | |||
240 | public enum CollisionObjectTypes : int | ||
241 | { | ||
242 | CO_COLLISION_OBJECT = 1 << 0, | ||
243 | CO_RIGID_BODY = 1 << 1, | ||
244 | CO_GHOST_OBJECT = 1 << 2, | ||
245 | CO_SOFT_BODY = 1 << 3, | ||
246 | CO_HF_FLUID = 1 << 4, | ||
247 | CO_USER_TYPE = 1 << 5, | ||
248 | } | ||
249 | |||
250 | // Values used by Bullet and BulletSim to control object properties. | ||
251 | // Bullet's "CollisionFlags" has more to do with operations on the | ||
252 | // object (if collisions happen, if gravity effects it, ...). | ||
253 | [Flags] | ||
254 | public enum CollisionFlags : uint | ||
255 | { | ||
256 | CF_STATIC_OBJECT = 1 << 0, | ||
257 | CF_KINEMATIC_OBJECT = 1 << 1, | ||
258 | CF_NO_CONTACT_RESPONSE = 1 << 2, | ||
259 | CF_CUSTOM_MATERIAL_CALLBACK = 1 << 3, | ||
260 | CF_CHARACTER_OBJECT = 1 << 4, | ||
261 | CF_DISABLE_VISUALIZE_OBJECT = 1 << 5, | ||
262 | CF_DISABLE_SPU_COLLISION_PROCESS = 1 << 6, | ||
263 | // Following used by BulletSim to control collisions and updates | ||
264 | BS_SUBSCRIBE_COLLISION_EVENTS = 1 << 10, | ||
265 | BS_FLOATS_ON_WATER = 1 << 11, | ||
266 | BS_VEHICLE_COLLISIONS = 1 << 12, | ||
267 | BS_NONE = 0, | ||
268 | BS_ALL = 0xFFFFFFFF, | ||
269 | |||
270 | // These are the collision flags switched depending on physical state. | ||
271 | // The other flags are used for other things and should not be fooled with. | ||
272 | BS_ACTIVE = CF_STATIC_OBJECT | ||
273 | | CF_KINEMATIC_OBJECT | ||
274 | | CF_NO_CONTACT_RESPONSE | ||
275 | }; | ||
276 | |||
277 | // Values for collisions groups and masks | ||
278 | public enum CollisionFilterGroups : uint | ||
279 | { | ||
280 | // Don't use the bit definitions!! Define the use in a | ||
281 | // filter/mask definition below. This way collision interactions | ||
282 | // are more easily debugged. | ||
283 | BNoneGroup = 0, | ||
284 | BDefaultGroup = 1 << 0, | ||
285 | BStaticGroup = 1 << 1, | ||
286 | BKinematicGroup = 1 << 2, | ||
287 | BDebrisGroup = 1 << 3, | ||
288 | BSensorTrigger = 1 << 4, | ||
289 | BCharacterGroup = 1 << 5, | ||
290 | BAllGroup = 0xFFFFFFFF, | ||
291 | // Filter groups defined by BulletSim | ||
292 | BGroundPlaneGroup = 1 << 10, | ||
293 | BTerrainGroup = 1 << 11, | ||
294 | BRaycastGroup = 1 << 12, | ||
295 | BSolidGroup = 1 << 13, | ||
296 | // BLinksetGroup = xx // a linkset proper is either static or dynamic | ||
297 | BLinksetChildGroup = 1 << 14, | ||
298 | // The collsion filters and masked are defined in one place -- don't want them scattered | ||
299 | AvatarGroup = BCharacterGroup, | ||
300 | AvatarMask = BAllGroup, | ||
301 | ObjectGroup = BSolidGroup, | ||
302 | ObjectMask = BAllGroup, | ||
303 | StaticObjectGroup = BStaticGroup, | ||
304 | StaticObjectMask = AvatarGroup | ObjectGroup, // static things don't interact with much | ||
305 | LinksetGroup = BLinksetChildGroup, | ||
306 | LinksetMask = BAllGroup & ~BLinksetChildGroup, // linkset objects don't collide with each other | ||
307 | VolumeDetectGroup = BSensorTrigger, | ||
308 | VolumeDetectMask = ~BSensorTrigger, | ||
309 | TerrainGroup = BTerrainGroup, | ||
310 | TerrainMask = BAllGroup & ~BStaticGroup, // static objects on the ground don't collide | ||
311 | GroundPlaneGroup = BGroundPlaneGroup, | ||
312 | GroundPlaneMask = BAllGroup | ||
313 | |||
314 | }; | ||
315 | |||
316 | // CFM controls the 'hardness' of the constraint. 0=fixed, 0..1=violatable. Default=0 | ||
317 | // ERP controls amount of correction per tick. Usable range=0.1..0.8. Default=0.2. | ||
318 | public enum ConstraintParams : int | ||
319 | { | ||
320 | BT_CONSTRAINT_ERP = 1, // this one is not used in Bullet as of 20120730 | ||
321 | BT_CONSTRAINT_STOP_ERP, | ||
322 | BT_CONSTRAINT_CFM, | ||
323 | BT_CONSTRAINT_STOP_CFM, | ||
324 | }; | ||
325 | public enum ConstraintParamAxis : int | ||
326 | { | ||
327 | AXIS_LINEAR_X = 0, | ||
328 | AXIS_LINEAR_Y, | ||
329 | AXIS_LINEAR_Z, | ||
330 | AXIS_ANGULAR_X, | ||
331 | AXIS_ANGULAR_Y, | ||
332 | AXIS_ANGULAR_Z, | ||
333 | AXIS_LINEAR_ALL = 20, // these last three added by BulletSim so we don't have to do zillions of calls | ||
334 | AXIS_ANGULAR_ALL, | ||
335 | AXIS_ALL | ||
336 | }; | ||
337 | |||
338 | // =============================================================================== | ||
339 | static class BulletSimAPI { | ||
340 | private static int m_collisionsThisFrame; | ||
341 | public delegate void DebugLogCallback(string msg); | ||
342 | /// <summary> | ||
343 | /// | ||
344 | /// </summary> | ||
345 | /// <param name="p"></param> | ||
346 | /// <param name="p_2"></param> | ||
347 | internal static bool RemoveObjectFromWorld2(object pWorld, object pBody) | ||
348 | { | ||
349 | DiscreteDynamicsWorld world = pWorld as DiscreteDynamicsWorld; | ||
350 | RigidBody body = pBody as RigidBody; | ||
351 | world.RemoveRigidBody(body); | ||
352 | return true; | ||
353 | } | ||
354 | |||
355 | internal static void SetRestitution2(object pBody, float pRestitution) | ||
356 | { | ||
357 | RigidBody body = pBody as RigidBody; | ||
358 | body.SetRestitution(pRestitution); | ||
359 | } | ||
360 | |||
361 | internal static void SetMargin2(object pShape, float pMargin) | ||
362 | { | ||
363 | CollisionShape shape = pShape as CollisionShape; | ||
364 | shape.SetMargin(pMargin); | ||
365 | } | ||
366 | |||
367 | internal static void SetLocalScaling2(object pShape, Vector3 pScale) | ||
368 | { | ||
369 | CollisionShape shape = pShape as CollisionShape; | ||
370 | IndexedVector3 vec = new IndexedVector3(pScale.X, pScale.Y, pScale.Z); | ||
371 | shape.SetLocalScaling(ref vec); | ||
372 | |||
373 | } | ||
374 | |||
375 | internal static void SetContactProcessingThreshold2(object pBody, float contactprocessingthreshold) | ||
376 | { | ||
377 | RigidBody body = pBody as RigidBody; | ||
378 | body.SetContactProcessingThreshold(contactprocessingthreshold); | ||
379 | } | ||
380 | |||
381 | internal static void SetCcdMotionThreshold2(object pBody, float pccdMotionThreashold) | ||
382 | { | ||
383 | RigidBody body = pBody as RigidBody; | ||
384 | body.SetCcdMotionThreshold(pccdMotionThreashold); | ||
385 | } | ||
386 | |||
387 | internal static void SetCcdSweptSphereRadius2(object pBody, float pCcdSweptSphereRadius) | ||
388 | { | ||
389 | RigidBody body = pBody as RigidBody; | ||
390 | body.SetCcdSweptSphereRadius(pCcdSweptSphereRadius); | ||
391 | } | ||
392 | |||
393 | internal static void SetAngularFactorV2(object pBody, Vector3 pAngularFactor) | ||
394 | { | ||
395 | RigidBody body = pBody as RigidBody; | ||
396 | body.SetAngularFactor(new IndexedVector3(pAngularFactor.X, pAngularFactor.Y, pAngularFactor.Z)); | ||
397 | } | ||
398 | |||
399 | internal static CollisionFlags AddToCollisionFlags2(object pBody, CollisionFlags pcollisionFlags) | ||
400 | { | ||
401 | CollisionObject body = pBody as CollisionObject; | ||
402 | CollisionFlags existingcollisionFlags = (CollisionFlags)(uint)body.GetCollisionFlags(); | ||
403 | existingcollisionFlags |= pcollisionFlags; | ||
404 | body.SetCollisionFlags((BulletXNA.BulletCollision.CollisionFlags)(uint)existingcollisionFlags); | ||
405 | return (CollisionFlags) (uint) existingcollisionFlags; | ||
406 | } | ||
407 | |||
408 | internal static void AddObjectToWorld2(object pWorld, object pBody) | ||
409 | { | ||
410 | RigidBody body = pBody as RigidBody; | ||
411 | DiscreteDynamicsWorld world = pWorld as DiscreteDynamicsWorld; | ||
412 | //if (!(body.GetCollisionShape().GetShapeType() == BroadphaseNativeTypes.STATIC_PLANE_PROXYTYPE && body.GetCollisionShape().GetShapeType() == BroadphaseNativeTypes.TERRAIN_SHAPE_PROXYTYPE)) | ||
413 | |||
414 | world.AddRigidBody(body); | ||
415 | |||
416 | //if (body.GetBroadphaseHandle() != null) | ||
417 | // world.UpdateSingleAabb(body); | ||
418 | } | ||
419 | |||
420 | internal static void AddObjectToWorld2(object pWorld, object pBody, Vector3 _position, Quaternion _orientation) | ||
421 | { | ||
422 | RigidBody body = pBody as RigidBody; | ||
423 | DiscreteDynamicsWorld world = pWorld as DiscreteDynamicsWorld; | ||
424 | //if (!(body.GetCollisionShape().GetShapeType() == BroadphaseNativeTypes.STATIC_PLANE_PROXYTYPE && body.GetCollisionShape().GetShapeType() == BroadphaseNativeTypes.TERRAIN_SHAPE_PROXYTYPE)) | ||
425 | |||
426 | world.AddRigidBody(body); | ||
427 | IndexedVector3 vposition = new IndexedVector3(_position.X, _position.Y, _position.Z); | ||
428 | IndexedQuaternion vquaternion = new IndexedQuaternion(_orientation.X, _orientation.Y, _orientation.Z, | ||
429 | _orientation.W); | ||
430 | IndexedMatrix mat = IndexedMatrix.CreateFromQuaternion(vquaternion); | ||
431 | mat._origin = vposition; | ||
432 | body.SetWorldTransform(mat); | ||
433 | //if (body.GetBroadphaseHandle() != null) | ||
434 | // world.UpdateSingleAabb(body); | ||
435 | } | ||
436 | |||
437 | internal static void ForceActivationState2(object pBody, ActivationState pActivationState) | ||
438 | { | ||
439 | CollisionObject body = pBody as CollisionObject; | ||
440 | body.ForceActivationState((BulletXNA.BulletCollision.ActivationState)(uint)pActivationState); | ||
441 | } | ||
442 | |||
443 | internal static void UpdateSingleAabb2(object pWorld, object pBody) | ||
444 | { | ||
445 | CollisionObject body = pBody as CollisionObject; | ||
446 | DiscreteDynamicsWorld world = pWorld as DiscreteDynamicsWorld; | ||
447 | world.UpdateSingleAabb(body); | ||
448 | } | ||
449 | |||
450 | internal static bool SetCollisionGroupMask2(object pBody, uint pGroup, uint pMask) | ||
451 | { | ||
452 | RigidBody body = pBody as RigidBody; | ||
453 | body.GetBroadphaseHandle().m_collisionFilterGroup = (BulletXNA.BulletCollision.CollisionFilterGroups) pGroup; | ||
454 | body.GetBroadphaseHandle().m_collisionFilterGroup = (BulletXNA.BulletCollision.CollisionFilterGroups) pGroup; | ||
455 | if ((uint) body.GetBroadphaseHandle().m_collisionFilterGroup == 0) | ||
456 | return false; | ||
457 | return true; | ||
458 | } | ||
459 | |||
460 | internal static void ClearAllForces2(object pBody) | ||
461 | { | ||
462 | CollisionObject body = pBody as CollisionObject; | ||
463 | IndexedVector3 zeroVector = new IndexedVector3(0, 0, 0); | ||
464 | body.SetInterpolationLinearVelocity(ref zeroVector); | ||
465 | body.SetInterpolationAngularVelocity(ref zeroVector); | ||
466 | IndexedMatrix bodytransform = body.GetWorldTransform(); | ||
467 | |||
468 | body.SetInterpolationWorldTransform(ref bodytransform); | ||
469 | |||
470 | if (body is RigidBody) | ||
471 | { | ||
472 | RigidBody rigidbody = body as RigidBody; | ||
473 | rigidbody.SetLinearVelocity(zeroVector); | ||
474 | rigidbody.SetAngularVelocity(zeroVector); | ||
475 | rigidbody.ClearForces(); | ||
476 | } | ||
477 | } | ||
478 | |||
479 | internal static void SetInterpolationAngularVelocity2(object pBody, Vector3 pVector3) | ||
480 | { | ||
481 | RigidBody body = pBody as RigidBody; | ||
482 | IndexedVector3 vec = new IndexedVector3(pVector3.X, pVector3.Y, pVector3.Z); | ||
483 | body.SetInterpolationAngularVelocity(ref vec); | ||
484 | } | ||
485 | |||
486 | internal static void SetAngularVelocity2(object pBody, Vector3 pVector3) | ||
487 | { | ||
488 | RigidBody body = pBody as RigidBody; | ||
489 | IndexedVector3 vec = new IndexedVector3(pVector3.X, pVector3.Y, pVector3.Z); | ||
490 | body.SetAngularVelocity(ref vec); | ||
491 | } | ||
492 | |||
493 | internal static void ClearForces2(object pBody) | ||
494 | { | ||
495 | RigidBody body = pBody as RigidBody; | ||
496 | body.ClearForces(); | ||
497 | } | ||
498 | |||
499 | internal static void SetTranslation2(object pBody, Vector3 _position, Quaternion _orientation) | ||
500 | { | ||
501 | RigidBody body = pBody as RigidBody; | ||
502 | IndexedVector3 vposition = new IndexedVector3(_position.X, _position.Y, _position.Z); | ||
503 | IndexedQuaternion vquaternion = new IndexedQuaternion(_orientation.X, _orientation.Y, _orientation.Z, | ||
504 | _orientation.W); | ||
505 | IndexedMatrix mat = IndexedMatrix.CreateFromQuaternion(vquaternion); | ||
506 | mat._origin = vposition; | ||
507 | body.SetWorldTransform(mat); | ||
508 | |||
509 | } | ||
510 | |||
511 | internal static Vector3 GetPosition2(object pBody) | ||
512 | { | ||
513 | RigidBody body = pBody as RigidBody; | ||
514 | IndexedVector3 pos = body.GetInterpolationWorldTransform()._origin; | ||
515 | return new Vector3(pos.X, pos.Y, pos.Z); | ||
516 | } | ||
517 | |||
518 | internal static Vector3 CalculateLocalInertia2(object pShape, float pphysMass) | ||
519 | { | ||
520 | CollisionShape shape = pShape as CollisionShape; | ||
521 | IndexedVector3 inertia = IndexedVector3.Zero; | ||
522 | shape.CalculateLocalInertia(pphysMass, out inertia); | ||
523 | return new Vector3(inertia.X, inertia.Y, inertia.Z); | ||
524 | } | ||
525 | |||
526 | internal static void SetMassProps2(object pBody, float pphysMass, Vector3 plocalInertia) | ||
527 | { | ||
528 | RigidBody body = pBody as RigidBody; | ||
529 | IndexedVector3 inertia = new IndexedVector3(plocalInertia.X, plocalInertia.Y, plocalInertia.Z); | ||
530 | body.SetMassProps(pphysMass, inertia); | ||
531 | } | ||
532 | |||
533 | |||
534 | internal static void SetObjectForce2(object pBody, Vector3 _force) | ||
535 | { | ||
536 | RigidBody body = pBody as RigidBody; | ||
537 | IndexedVector3 force = new IndexedVector3(_force.X, _force.Y, _force.Z); | ||
538 | body.SetTotalForce(ref force); | ||
539 | } | ||
540 | |||
541 | internal static void SetFriction2(object pBody, float _currentFriction) | ||
542 | { | ||
543 | RigidBody body = pBody as RigidBody; | ||
544 | body.SetFriction(_currentFriction); | ||
545 | } | ||
546 | |||
547 | internal static void SetLinearVelocity2(object pBody, Vector3 _velocity) | ||
548 | { | ||
549 | RigidBody body = pBody as RigidBody; | ||
550 | IndexedVector3 velocity = new IndexedVector3(_velocity.X, _velocity.Y, _velocity.Z); | ||
551 | body.SetLinearVelocity(velocity); | ||
552 | } | ||
553 | |||
554 | internal static void Activate2(object pBody, bool pforceactivation) | ||
555 | { | ||
556 | RigidBody body = pBody as RigidBody; | ||
557 | body.Activate(pforceactivation); | ||
558 | |||
559 | } | ||
560 | |||
561 | internal static Quaternion GetOrientation2(object pBody) | ||
562 | { | ||
563 | RigidBody body = pBody as RigidBody; | ||
564 | IndexedQuaternion mat = body.GetInterpolationWorldTransform().GetRotation(); | ||
565 | return new Quaternion(mat.X, mat.Y, mat.Z, mat.W); | ||
566 | } | ||
567 | |||
568 | internal static CollisionFlags RemoveFromCollisionFlags2(object pBody, CollisionFlags pcollisionFlags) | ||
569 | { | ||
570 | RigidBody body = pBody as RigidBody; | ||
571 | CollisionFlags existingcollisionFlags = (CollisionFlags)(uint)body.GetCollisionFlags(); | ||
572 | existingcollisionFlags &= ~pcollisionFlags; | ||
573 | body.SetCollisionFlags((BulletXNA.BulletCollision.CollisionFlags)(uint)existingcollisionFlags); | ||
574 | return (CollisionFlags)(uint)existingcollisionFlags; | ||
575 | } | ||
576 | |||
577 | internal static void SetGravity2(object pBody, Vector3 pGravity) | ||
578 | { | ||
579 | RigidBody body = pBody as RigidBody; | ||
580 | IndexedVector3 gravity = new IndexedVector3(pGravity.X, pGravity.Y, pGravity.Z); | ||
581 | body.SetGravity(gravity); | ||
582 | } | ||
583 | |||
584 | internal static bool DestroyConstraint2(object pBody, object pConstraint) | ||
585 | { | ||
586 | RigidBody body = pBody as RigidBody; | ||
587 | TypedConstraint constraint = pConstraint as TypedConstraint; | ||
588 | body.RemoveConstraintRef(constraint); | ||
589 | return true; | ||
590 | } | ||
591 | |||
592 | internal static bool SetLinearLimits2(object pConstraint, Vector3 low, Vector3 high) | ||
593 | { | ||
594 | Generic6DofConstraint constraint = pConstraint as Generic6DofConstraint; | ||
595 | IndexedVector3 lowlimit = new IndexedVector3(low.X, low.Y, low.Z); | ||
596 | IndexedVector3 highlimit = new IndexedVector3(high.X, high.Y, high.Z); | ||
597 | constraint.SetLinearLowerLimit(lowlimit); | ||
598 | constraint.SetLinearUpperLimit(highlimit); | ||
599 | return true; | ||
600 | } | ||
601 | |||
602 | internal static bool SetAngularLimits2(object pConstraint, Vector3 low, Vector3 high) | ||
603 | { | ||
604 | Generic6DofConstraint constraint = pConstraint as Generic6DofConstraint; | ||
605 | IndexedVector3 lowlimit = new IndexedVector3(low.X, low.Y, low.Z); | ||
606 | IndexedVector3 highlimit = new IndexedVector3(high.X, high.Y, high.Z); | ||
607 | constraint.SetAngularLowerLimit(lowlimit); | ||
608 | constraint.SetAngularUpperLimit(highlimit); | ||
609 | return true; | ||
610 | } | ||
611 | |||
612 | internal static void SetConstraintNumSolverIterations2(object pConstraint, float cnt) | ||
613 | { | ||
614 | Generic6DofConstraint constraint = pConstraint as Generic6DofConstraint; | ||
615 | constraint.SetOverrideNumSolverIterations((int)cnt); | ||
616 | } | ||
617 | |||
618 | internal static void CalculateTransforms2(object pConstraint) | ||
619 | { | ||
620 | Generic6DofConstraint constraint = pConstraint as Generic6DofConstraint; | ||
621 | constraint.CalculateTransforms(); | ||
622 | } | ||
623 | |||
624 | internal static void SetConstraintEnable2(object pConstraint, float p_2) | ||
625 | { | ||
626 | Generic6DofConstraint constraint = pConstraint as Generic6DofConstraint; | ||
627 | constraint.SetEnabled((p_2 == 0) ? false : true); | ||
628 | } | ||
629 | |||
630 | |||
631 | //BulletSimAPI.Create6DofConstraint2(m_world.ptr, m_body1.ptr, m_body2.ptr,frame1, frame1rot,frame2, frame2rot,useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies)); | ||
632 | internal static object Create6DofConstraint2(object pWorld, object pBody1, object pBody2, Vector3 pframe1, Quaternion pframe1rot, Vector3 pframe2, Quaternion pframe2rot, bool puseLinearReferenceFrameA, bool pdisableCollisionsBetweenLinkedBodies) | ||
633 | |||
634 | { | ||
635 | DiscreteDynamicsWorld world = pWorld as DiscreteDynamicsWorld; | ||
636 | RigidBody body1 = pBody1 as RigidBody; | ||
637 | RigidBody body2 = pBody2 as RigidBody; | ||
638 | IndexedVector3 frame1v = new IndexedVector3(pframe1.X, pframe1.Y, pframe1.Z); | ||
639 | IndexedQuaternion frame1rot = new IndexedQuaternion(pframe1rot.X, pframe1rot.Y, pframe1rot.Z, pframe1rot.W); | ||
640 | IndexedMatrix frame1 = IndexedMatrix.CreateFromQuaternion(frame1rot); | ||
641 | frame1._origin = frame1v; | ||
642 | |||
643 | IndexedVector3 frame2v = new IndexedVector3(pframe2.X, pframe2.Y, pframe2.Z); | ||
644 | IndexedQuaternion frame2rot = new IndexedQuaternion(pframe2rot.X, pframe2rot.Y, pframe2rot.Z, pframe2rot.W); | ||
645 | IndexedMatrix frame2 = IndexedMatrix.CreateFromQuaternion(frame2rot); | ||
646 | frame2._origin = frame1v; | ||
647 | |||
648 | Generic6DofConstraint consttr = new Generic6DofConstraint(body1, body2, ref frame1, ref frame2, | ||
649 | puseLinearReferenceFrameA); | ||
650 | consttr.CalculateTransforms(); | ||
651 | world.AddConstraint(consttr,pdisableCollisionsBetweenLinkedBodies); | ||
652 | |||
653 | return consttr; | ||
654 | } | ||
655 | |||
656 | |||
657 | /// <summary> | ||
658 | /// | ||
659 | /// </summary> | ||
660 | /// <param name="pWorld"></param> | ||
661 | /// <param name="pBody1"></param> | ||
662 | /// <param name="pBody2"></param> | ||
663 | /// <param name="pjoinPoint"></param> | ||
664 | /// <param name="puseLinearReferenceFrameA"></param> | ||
665 | /// <param name="pdisableCollisionsBetweenLinkedBodies"></param> | ||
666 | /// <returns></returns> | ||
667 | internal static object Create6DofConstraintToPoint2(object pWorld, object pBody1, object pBody2, Vector3 pjoinPoint, bool puseLinearReferenceFrameA, bool pdisableCollisionsBetweenLinkedBodies) | ||
668 | { | ||
669 | DiscreteDynamicsWorld world = pWorld as DiscreteDynamicsWorld; | ||
670 | RigidBody body1 = pBody1 as RigidBody; | ||
671 | RigidBody body2 = pBody2 as RigidBody; | ||
672 | IndexedMatrix frame1 = new IndexedMatrix(IndexedBasisMatrix.Identity, new IndexedVector3(0, 0, 0)); | ||
673 | IndexedMatrix frame2 = new IndexedMatrix(IndexedBasisMatrix.Identity, new IndexedVector3(0, 0, 0)); | ||
674 | |||
675 | IndexedVector3 joinPoint = new IndexedVector3(pjoinPoint.X, pjoinPoint.Y, pjoinPoint.Z); | ||
676 | IndexedMatrix mat = IndexedMatrix.Identity; | ||
677 | mat._origin = new IndexedVector3(pjoinPoint.X, pjoinPoint.Y, pjoinPoint.Z); | ||
678 | frame1._origin = body1.GetWorldTransform().Inverse()*joinPoint; | ||
679 | frame2._origin = body2.GetWorldTransform().Inverse()*joinPoint; | ||
680 | |||
681 | Generic6DofConstraint consttr = new Generic6DofConstraint(body1, body2, ref frame1, ref frame2, puseLinearReferenceFrameA); | ||
682 | consttr.CalculateTransforms(); | ||
683 | world.AddConstraint(consttr, pdisableCollisionsBetweenLinkedBodies); | ||
684 | |||
685 | return consttr; | ||
686 | } | ||
687 | //SetFrames2(m_constraint.ptr, frameA, frameArot, frameB, frameBrot); | ||
688 | internal static void SetFrames2(object pConstraint, Vector3 pframe1, Quaternion pframe1rot, Vector3 pframe2, Quaternion pframe2rot) | ||
689 | { | ||
690 | Generic6DofConstraint constraint = pConstraint as Generic6DofConstraint; | ||
691 | IndexedVector3 frame1v = new IndexedVector3(pframe1.X, pframe1.Y, pframe1.Z); | ||
692 | IndexedQuaternion frame1rot = new IndexedQuaternion(pframe1rot.X, pframe1rot.Y, pframe1rot.Z, pframe1rot.W); | ||
693 | IndexedMatrix frame1 = IndexedMatrix.CreateFromQuaternion(frame1rot); | ||
694 | frame1._origin = frame1v; | ||
695 | |||
696 | IndexedVector3 frame2v = new IndexedVector3(pframe2.X, pframe2.Y, pframe2.Z); | ||
697 | IndexedQuaternion frame2rot = new IndexedQuaternion(pframe2rot.X, pframe2rot.Y, pframe2rot.Z, pframe2rot.W); | ||
698 | IndexedMatrix frame2 = IndexedMatrix.CreateFromQuaternion(frame2rot); | ||
699 | frame2._origin = frame1v; | ||
700 | constraint.SetFrames(ref frame1, ref frame2); | ||
701 | } | ||
702 | |||
703 | |||
704 | |||
705 | |||
706 | internal static bool IsInWorld2(object pWorld, object pShapeObj) | ||
707 | { | ||
708 | DiscreteDynamicsWorld world = pWorld as DiscreteDynamicsWorld; | ||
709 | CollisionObject shape = pShapeObj as CollisionObject; | ||
710 | return world.IsInWorld(shape); | ||
711 | } | ||
712 | |||
713 | internal static void SetInterpolationLinearVelocity2(object pBody, Vector3 VehicleVelocity) | ||
714 | { | ||
715 | RigidBody body = pBody as RigidBody; | ||
716 | IndexedVector3 velocity = new IndexedVector3(VehicleVelocity.X, VehicleVelocity.Y, VehicleVelocity.Z); | ||
717 | body.SetInterpolationLinearVelocity(ref velocity); | ||
718 | } | ||
719 | |||
720 | internal static bool UseFrameOffset2(object pConstraint, float onOff) | ||
721 | { | ||
722 | Generic6DofConstraint constraint = pConstraint as Generic6DofConstraint; | ||
723 | constraint.SetUseFrameOffset((onOff == 0) ? false : true); | ||
724 | return true; | ||
725 | } | ||
726 | //SetBreakingImpulseThreshold2(m_constraint.ptr, threshold); | ||
727 | internal static bool SetBreakingImpulseThreshold2(object pConstraint, float threshold) | ||
728 | { | ||
729 | Generic6DofConstraint constraint = pConstraint as Generic6DofConstraint; | ||
730 | constraint.SetBreakingImpulseThreshold(threshold); | ||
731 | return true; | ||
732 | } | ||
733 | //BulletSimAPI.SetAngularDamping2(Prim.PhysBody.ptr, angularDamping); | ||
734 | internal static void SetAngularDamping2(object pBody, float angularDamping) | ||
735 | { | ||
736 | RigidBody body = pBody as RigidBody; | ||
737 | float lineardamping = body.GetLinearDamping(); | ||
738 | body.SetDamping(lineardamping, angularDamping); | ||
739 | |||
740 | } | ||
741 | |||
742 | internal static void UpdateInertiaTensor2(object pBody) | ||
743 | { | ||
744 | RigidBody body = pBody as RigidBody; | ||
745 | body.UpdateInertiaTensor(); | ||
746 | } | ||
747 | |||
748 | internal static void RecalculateCompoundShapeLocalAabb2( object pCompoundShape) | ||
749 | { | ||
750 | |||
751 | CompoundShape shape = pCompoundShape as CompoundShape; | ||
752 | shape.RecalculateLocalAabb(); | ||
753 | } | ||
754 | |||
755 | //BulletSimAPI.GetCollisionFlags2(PhysBody.ptr) | ||
756 | internal static CollisionFlags GetCollisionFlags2(object pBody) | ||
757 | { | ||
758 | RigidBody body = pBody as RigidBody; | ||
759 | uint flags = (uint)body.GetCollisionFlags(); | ||
760 | return (CollisionFlags) flags; | ||
761 | } | ||
762 | |||
763 | internal static void SetDamping2(object pBody, float pLinear, float pAngular) | ||
764 | { | ||
765 | RigidBody body = pBody as RigidBody; | ||
766 | body.SetDamping(pLinear, pAngular); | ||
767 | } | ||
768 | //PhysBody.ptr, PhysicsScene.Params.deactivationTime); | ||
769 | internal static void SetDeactivationTime2(object pBody, float pDeactivationTime) | ||
770 | { | ||
771 | RigidBody body = pBody as RigidBody; | ||
772 | body.SetDeactivationTime(pDeactivationTime); | ||
773 | } | ||
774 | //SetSleepingThresholds2(PhysBody.ptr, PhysicsScene.Params.linearSleepingThreshold, PhysicsScene.Params.angularSleepingThreshold); | ||
775 | internal static void SetSleepingThresholds2(object pBody, float plinearSleepingThreshold, float pangularSleepingThreshold) | ||
776 | { | ||
777 | RigidBody body = pBody as RigidBody; | ||
778 | body.SetSleepingThresholds(plinearSleepingThreshold, pangularSleepingThreshold); | ||
779 | } | ||
780 | |||
781 | internal static CollisionObjectTypes GetBodyType2(object pBody) | ||
782 | { | ||
783 | RigidBody body = pBody as RigidBody; | ||
784 | return (CollisionObjectTypes)(int) body.GetInternalType(); | ||
785 | } | ||
786 | |||
787 | //BulletSimAPI.ApplyCentralForce2(PhysBody.ptr, fSum); | ||
788 | internal static void ApplyCentralForce2(object pBody, Vector3 pfSum) | ||
789 | { | ||
790 | RigidBody body = pBody as RigidBody; | ||
791 | IndexedVector3 fSum = new IndexedVector3(pfSum.X, pfSum.Y, pfSum.Z); | ||
792 | body.ApplyCentralForce(ref fSum); | ||
793 | } | ||
794 | internal static void ApplyCentralImpulse2(object pBody, Vector3 pfSum) | ||
795 | { | ||
796 | RigidBody body = pBody as RigidBody; | ||
797 | IndexedVector3 fSum = new IndexedVector3(pfSum.X, pfSum.Y, pfSum.Z); | ||
798 | body.ApplyCentralImpulse(ref fSum); | ||
799 | } | ||
800 | internal static void ApplyTorque2(object pBody, Vector3 pfSum) | ||
801 | { | ||
802 | RigidBody body = pBody as RigidBody; | ||
803 | IndexedVector3 fSum = new IndexedVector3(pfSum.X, pfSum.Y, pfSum.Z); | ||
804 | body.ApplyTorque(ref fSum); | ||
805 | } | ||
806 | internal static void ApplyTorqueImpulse2(object pBody, Vector3 pfSum) | ||
807 | { | ||
808 | RigidBody body = pBody as RigidBody; | ||
809 | IndexedVector3 fSum = new IndexedVector3(pfSum.X, pfSum.Y, pfSum.Z); | ||
810 | body.ApplyTorqueImpulse(ref fSum); | ||
811 | } | ||
812 | |||
813 | internal static void DumpRigidBody2(object p, object p_2) | ||
814 | { | ||
815 | //TODO: | ||
816 | } | ||
817 | |||
818 | internal static void DumpCollisionShape2(object p, object p_2) | ||
819 | { | ||
820 | //TODO: | ||
821 | } | ||
822 | |||
823 | internal static void DestroyObject2(object p, object p_2) | ||
824 | { | ||
825 | //TODO: | ||
826 | } | ||
827 | |||
828 | internal static void Shutdown2(object pWorld) | ||
829 | { | ||
830 | DiscreteDynamicsWorld world = pWorld as DiscreteDynamicsWorld; | ||
831 | world.Cleanup(); | ||
832 | } | ||
833 | |||
834 | internal static void DeleteCollisionShape2(object p, object p_2) | ||
835 | { | ||
836 | //TODO: | ||
837 | } | ||
838 | //(sim.ptr, shape.ptr, prim.LocalID, prim.RawPosition, prim.RawOrientation); | ||
839 | |||
840 | internal static object CreateBodyFromShape2(object pWorld, object pShape, uint pLocalID, Vector3 pRawPosition, Quaternion pRawOrientation) | ||
841 | { | ||
842 | CollisionWorld world = pWorld as CollisionWorld; | ||
843 | IndexedMatrix mat = | ||
844 | IndexedMatrix.CreateFromQuaternion(new IndexedQuaternion(pRawOrientation.X, pRawOrientation.Y, | ||
845 | pRawOrientation.Z, pRawOrientation.W)); | ||
846 | mat._origin = new IndexedVector3(pRawPosition.X, pRawPosition.Y, pRawPosition.Z); | ||
847 | CollisionShape shape = pShape as CollisionShape; | ||
848 | //UpdateSingleAabb2(world, shape); | ||
849 | // TODO: Feed Update array into null | ||
850 | RigidBody body = new RigidBody(0,new SimMotionState(world,pLocalID,mat,null),shape,IndexedVector3.Zero); | ||
851 | |||
852 | body.SetUserPointer(pLocalID); | ||
853 | return body; | ||
854 | } | ||
855 | |||
856 | |||
857 | internal static object CreateBodyWithDefaultMotionState2( object pShape, uint pLocalID, Vector3 pRawPosition, Quaternion pRawOrientation) | ||
858 | { | ||
859 | |||
860 | IndexedMatrix mat = | ||
861 | IndexedMatrix.CreateFromQuaternion(new IndexedQuaternion(pRawOrientation.X, pRawOrientation.Y, | ||
862 | pRawOrientation.Z, pRawOrientation.W)); | ||
863 | mat._origin = new IndexedVector3(pRawPosition.X, pRawPosition.Y, pRawPosition.Z); | ||
864 | |||
865 | CollisionShape shape = pShape as CollisionShape; | ||
866 | |||
867 | // TODO: Feed Update array into null | ||
868 | RigidBody body = new RigidBody(0, new DefaultMotionState( mat, IndexedMatrix.Identity), shape, IndexedVector3.Zero); | ||
869 | body.SetWorldTransform(mat); | ||
870 | body.SetUserPointer(pLocalID); | ||
871 | return body; | ||
872 | } | ||
873 | //(m_mapInfo.terrainBody.ptr, CollisionFlags.CF_STATIC_OBJECT); | ||
874 | internal static void SetCollisionFlags2(object pBody, CollisionFlags collisionFlags) | ||
875 | { | ||
876 | RigidBody body = pBody as RigidBody; | ||
877 | body.SetCollisionFlags((BulletXNA.BulletCollision.CollisionFlags) (uint) collisionFlags); | ||
878 | } | ||
879 | //(m_mapInfo.terrainBody.ptr, PhysicsScene.Params.terrainHitFraction); | ||
880 | internal static void SetHitFraction2(object pBody, float pHitFraction) | ||
881 | { | ||
882 | RigidBody body = pBody as RigidBody; | ||
883 | body.SetHitFraction(pHitFraction); | ||
884 | } | ||
885 | //BuildCapsuleShape2(physicsScene.World.ptr, 1f, 1f, prim.Scale); | ||
886 | internal static object BuildCapsuleShape2(object pWorld, float pRadius, float pHeight, Vector3 pScale) | ||
887 | { | ||
888 | DiscreteDynamicsWorld world = pWorld as DiscreteDynamicsWorld; | ||
889 | IndexedVector3 scale = new IndexedVector3(pScale.X, pScale.Y, pScale.Z); | ||
890 | CapsuleShapeZ capsuleShapeZ = new CapsuleShapeZ(pRadius, pHeight); | ||
891 | capsuleShapeZ.SetMargin(world.WorldSettings.Params.collisionMargin); | ||
892 | capsuleShapeZ.SetLocalScaling(ref scale); | ||
893 | |||
894 | return capsuleShapeZ; | ||
895 | } | ||
896 | |||
897 | public static object Initialize2(Vector3 worldExtent, ConfigurationParameters[] o, int mMaxCollisionsPerFrame, ref List<BulletXNA.CollisionDesc> collisionArray, int mMaxUpdatesPerFrame, ref List<BulletXNA.EntityProperties> updateArray, object mDebugLogCallbackHandle) | ||
898 | { | ||
899 | CollisionWorld.WorldData.ParamData p = new CollisionWorld.WorldData.ParamData(); | ||
900 | |||
901 | p.angularDamping = o[0].XangularDamping; | ||
902 | p.defaultFriction = o[0].defaultFriction; | ||
903 | p.defaultFriction = o[0].defaultFriction; | ||
904 | p.defaultDensity = o[0].defaultDensity; | ||
905 | p.defaultRestitution = o[0].defaultRestitution; | ||
906 | p.collisionMargin = o[0].collisionMargin; | ||
907 | p.gravity = o[0].gravity; | ||
908 | |||
909 | p.linearDamping = o[0].XlinearDamping; | ||
910 | p.angularDamping = o[0].XangularDamping; | ||
911 | p.deactivationTime = o[0].XdeactivationTime; | ||
912 | p.linearSleepingThreshold = o[0].XlinearSleepingThreshold; | ||
913 | p.angularSleepingThreshold = o[0].XangularSleepingThreshold; | ||
914 | p.ccdMotionThreshold = o[0].XccdMotionThreshold; | ||
915 | p.ccdSweptSphereRadius = o[0].XccdSweptSphereRadius; | ||
916 | p.contactProcessingThreshold = o[0].XcontactProcessingThreshold; | ||
917 | |||
918 | p.terrainImplementation = o[0].XterrainImplementation; | ||
919 | p.terrainFriction = o[0].XterrainFriction; | ||
920 | |||
921 | p.terrainHitFraction = o[0].XterrainHitFraction; | ||
922 | p.terrainRestitution = o[0].XterrainRestitution; | ||
923 | p.terrainCollisionMargin = o[0].XterrainCollisionMargin; | ||
924 | |||
925 | p.avatarFriction = o[0].XavatarFriction; | ||
926 | p.avatarStandingFriction = o[0].XavatarStandingFriction; | ||
927 | p.avatarDensity = o[0].XavatarDensity; | ||
928 | p.avatarRestitution = o[0].XavatarRestitution; | ||
929 | p.avatarCapsuleWidth = o[0].XavatarCapsuleWidth; | ||
930 | p.avatarCapsuleDepth = o[0].XavatarCapsuleDepth; | ||
931 | p.avatarCapsuleHeight = o[0].XavatarCapsuleHeight; | ||
932 | p.avatarContactProcessingThreshold = o[0].XavatarContactProcessingThreshold; | ||
933 | |||
934 | p.vehicleAngularDamping = o[0].XvehicleAngularDamping; | ||
935 | |||
936 | p.maxPersistantManifoldPoolSize = o[0].maxPersistantManifoldPoolSize; | ||
937 | p.maxCollisionAlgorithmPoolSize = o[0].maxCollisionAlgorithmPoolSize; | ||
938 | p.shouldDisableContactPoolDynamicAllocation = o[0].shouldDisableContactPoolDynamicAllocation; | ||
939 | p.shouldForceUpdateAllAabbs = o[0].shouldForceUpdateAllAabbs; | ||
940 | p.shouldRandomizeSolverOrder = o[0].shouldRandomizeSolverOrder; | ||
941 | p.shouldSplitSimulationIslands = o[0].shouldSplitSimulationIslands; | ||
942 | p.shouldEnableFrictionCaching = o[0].shouldEnableFrictionCaching; | ||
943 | p.numberOfSolverIterations = o[0].numberOfSolverIterations; | ||
944 | |||
945 | p.linksetImplementation = o[0].XlinksetImplementation; | ||
946 | p.linkConstraintUseFrameOffset = o[0].XlinkConstraintUseFrameOffset; | ||
947 | p.linkConstraintEnableTransMotor = o[0].XlinkConstraintEnableTransMotor; | ||
948 | p.linkConstraintTransMotorMaxVel = o[0].XlinkConstraintTransMotorMaxVel; | ||
949 | p.linkConstraintTransMotorMaxForce = o[0].XlinkConstraintTransMotorMaxForce; | ||
950 | p.linkConstraintERP = o[0].XlinkConstraintERP; | ||
951 | p.linkConstraintCFM = o[0].XlinkConstraintCFM; | ||
952 | p.linkConstraintSolverIterations = o[0].XlinkConstraintSolverIterations; | ||
953 | p.physicsLoggingFrames = o[0].physicsLoggingFrames; | ||
954 | DefaultCollisionConstructionInfo ccci = new DefaultCollisionConstructionInfo(); | ||
955 | |||
956 | DefaultCollisionConfiguration cci = new DefaultCollisionConfiguration(); | ||
957 | CollisionDispatcher m_dispatcher = new CollisionDispatcher(cci); | ||
958 | |||
959 | |||
960 | if (p.maxPersistantManifoldPoolSize > 0) | ||
961 | cci.m_persistentManifoldPoolSize = (int)p.maxPersistantManifoldPoolSize; | ||
962 | if (p.shouldDisableContactPoolDynamicAllocation !=0) | ||
963 | m_dispatcher.SetDispatcherFlags(DispatcherFlags.CD_DISABLE_CONTACTPOOL_DYNAMIC_ALLOCATION); | ||
964 | //if (p.maxCollisionAlgorithmPoolSize >0 ) | ||
965 | |||
966 | DbvtBroadphase m_broadphase = new DbvtBroadphase(); | ||
967 | //IndexedVector3 aabbMin = new IndexedVector3(0, 0, 0); | ||
968 | //IndexedVector3 aabbMax = new IndexedVector3(256, 256, 256); | ||
969 | |||
970 | //AxisSweep3Internal m_broadphase2 = new AxisSweep3Internal(ref aabbMin, ref aabbMax, Convert.ToInt32(0xfffe), 0xffff, ushort.MaxValue/2, null, true); | ||
971 | m_broadphase.GetOverlappingPairCache().SetInternalGhostPairCallback(new GhostPairCallback()); | ||
972 | |||
973 | SequentialImpulseConstraintSolver m_solver = new SequentialImpulseConstraintSolver(); | ||
974 | |||
975 | DiscreteDynamicsWorld world = new DiscreteDynamicsWorld(m_dispatcher, m_broadphase, m_solver, cci); | ||
976 | world.UpdatedObjects = updateArray; | ||
977 | world.UpdatedCollisions = collisionArray; | ||
978 | world.WorldSettings.Params = p; | ||
979 | world.SetForceUpdateAllAabbs(p.shouldForceUpdateAllAabbs != 0); | ||
980 | world.GetSolverInfo().m_solverMode = SolverMode.SOLVER_USE_WARMSTARTING | SolverMode.SOLVER_SIMD; | ||
981 | if (p.shouldRandomizeSolverOrder != 0) | ||
982 | world.GetSolverInfo().m_solverMode |= SolverMode.SOLVER_RANDMIZE_ORDER; | ||
983 | |||
984 | world.GetSimulationIslandManager().SetSplitIslands(p.shouldSplitSimulationIslands != 0); | ||
985 | //world.GetDispatchInfo().m_enableSatConvex Not implemented in C# port | ||
986 | |||
987 | if (p.shouldEnableFrictionCaching != 0) | ||
988 | world.GetSolverInfo().m_solverMode |= SolverMode.SOLVER_ENABLE_FRICTION_DIRECTION_CACHING; | ||
989 | |||
990 | if (p.numberOfSolverIterations > 0) | ||
991 | world.GetSolverInfo().m_numIterations = (int) p.numberOfSolverIterations; | ||
992 | |||
993 | |||
994 | world.GetSolverInfo().m_damping = world.WorldSettings.Params.linearDamping; | ||
995 | world.GetSolverInfo().m_restitution = world.WorldSettings.Params.defaultRestitution; | ||
996 | world.GetSolverInfo().m_globalCfm = 0.0f; | ||
997 | world.GetSolverInfo().m_tau = 0.6f; | ||
998 | world.GetSolverInfo().m_friction = 0.3f; | ||
999 | world.GetSolverInfo().m_maxErrorReduction = 20f; | ||
1000 | world.GetSolverInfo().m_numIterations = 10; | ||
1001 | world.GetSolverInfo().m_erp = 0.2f; | ||
1002 | world.GetSolverInfo().m_erp2 = 0.1f; | ||
1003 | world.GetSolverInfo().m_sor = 1.0f; | ||
1004 | world.GetSolverInfo().m_splitImpulse = false; | ||
1005 | world.GetSolverInfo().m_splitImpulsePenetrationThreshold = -0.02f; | ||
1006 | world.GetSolverInfo().m_linearSlop = 0.0f; | ||
1007 | world.GetSolverInfo().m_warmstartingFactor = 0.85f; | ||
1008 | world.GetSolverInfo().m_restingContactRestitutionThreshold = 2; | ||
1009 | world.SetForceUpdateAllAabbs(true); | ||
1010 | |||
1011 | |||
1012 | world.SetGravity(new IndexedVector3(0,0,p.gravity)); | ||
1013 | |||
1014 | return world; | ||
1015 | } | ||
1016 | //m_constraint.ptr, ConstraintParams.BT_CONSTRAINT_STOP_CFM, cfm, ConstraintParamAxis.AXIS_ALL | ||
1017 | internal static bool SetConstraintParam2(object pConstraint, ConstraintParams paramIndex, float paramvalue, ConstraintParamAxis axis) | ||
1018 | { | ||
1019 | Generic6DofConstraint constrain = pConstraint as Generic6DofConstraint; | ||
1020 | if (axis == ConstraintParamAxis.AXIS_LINEAR_ALL || axis == ConstraintParamAxis.AXIS_ALL) | ||
1021 | { | ||
1022 | constrain.SetParam((BulletXNA.BulletDynamics.ConstraintParams) (int) paramIndex, paramvalue, 0); | ||
1023 | constrain.SetParam((BulletXNA.BulletDynamics.ConstraintParams) (int) paramIndex, paramvalue, 1); | ||
1024 | constrain.SetParam((BulletXNA.BulletDynamics.ConstraintParams) (int) paramIndex, paramvalue, 2); | ||
1025 | } | ||
1026 | if (axis == ConstraintParamAxis.AXIS_ANGULAR_ALL || axis == ConstraintParamAxis.AXIS_ALL) | ||
1027 | { | ||
1028 | constrain.SetParam((BulletXNA.BulletDynamics.ConstraintParams)(int)paramIndex, paramvalue, 3); | ||
1029 | constrain.SetParam((BulletXNA.BulletDynamics.ConstraintParams)(int)paramIndex, paramvalue, 4); | ||
1030 | constrain.SetParam((BulletXNA.BulletDynamics.ConstraintParams)(int)paramIndex, paramvalue, 5); | ||
1031 | } | ||
1032 | if (axis == ConstraintParamAxis.AXIS_LINEAR_ALL) | ||
1033 | { | ||
1034 | constrain.SetParam((BulletXNA.BulletDynamics.ConstraintParams)(int)paramIndex, paramvalue, (int)axis); | ||
1035 | } | ||
1036 | return true; | ||
1037 | } | ||
1038 | |||
1039 | internal static bool PushUpdate2(object pCollisionObject) | ||
1040 | { | ||
1041 | bool ret = false; | ||
1042 | RigidBody rb = pCollisionObject as RigidBody; | ||
1043 | if (rb != null) | ||
1044 | { | ||
1045 | SimMotionState sms = rb.GetMotionState() as SimMotionState; | ||
1046 | if (sms != null) | ||
1047 | { | ||
1048 | IndexedMatrix wt = IndexedMatrix.Identity; | ||
1049 | sms.GetWorldTransform(out wt); | ||
1050 | sms.SetWorldTransform(ref wt, true); | ||
1051 | ret = true; | ||
1052 | } | ||
1053 | } | ||
1054 | return ret; | ||
1055 | |||
1056 | } | ||
1057 | |||
1058 | internal static bool IsCompound2(object pShape) | ||
1059 | { | ||
1060 | CollisionShape shape = pShape as CollisionShape; | ||
1061 | return shape.IsCompound(); | ||
1062 | } | ||
1063 | internal static bool IsPloyhedral2(object pShape) | ||
1064 | { | ||
1065 | CollisionShape shape = pShape as CollisionShape; | ||
1066 | return shape.IsPolyhedral(); | ||
1067 | } | ||
1068 | internal static bool IsConvex2d2(object pShape) | ||
1069 | { | ||
1070 | CollisionShape shape = pShape as CollisionShape; | ||
1071 | return shape.IsConvex2d(); | ||
1072 | } | ||
1073 | internal static bool IsConvex2(object pShape) | ||
1074 | { | ||
1075 | CollisionShape shape = pShape as CollisionShape; | ||
1076 | return shape.IsConvex(); | ||
1077 | } | ||
1078 | internal static bool IsNonMoving2(object pShape) | ||
1079 | { | ||
1080 | CollisionShape shape = pShape as CollisionShape; | ||
1081 | return shape.IsNonMoving(); | ||
1082 | } | ||
1083 | internal static bool IsConcave2(object pShape) | ||
1084 | { | ||
1085 | CollisionShape shape = pShape as CollisionShape; | ||
1086 | return shape.IsConcave(); | ||
1087 | } | ||
1088 | internal static bool IsInfinite2(object pShape) | ||
1089 | { | ||
1090 | CollisionShape shape = pShape as CollisionShape; | ||
1091 | return shape.IsInfinite(); | ||
1092 | } | ||
1093 | internal static bool IsNativeShape2(object pShape) | ||
1094 | { | ||
1095 | CollisionShape shape = pShape as CollisionShape; | ||
1096 | bool ret; | ||
1097 | switch (shape.GetShapeType()) | ||
1098 | { | ||
1099 | case BroadphaseNativeTypes.BOX_SHAPE_PROXYTYPE: | ||
1100 | case BroadphaseNativeTypes.CONE_SHAPE_PROXYTYPE: | ||
1101 | case BroadphaseNativeTypes.SPHERE_SHAPE_PROXYTYPE: | ||
1102 | case BroadphaseNativeTypes.CYLINDER_SHAPE_PROXYTYPE: | ||
1103 | ret = true; | ||
1104 | break; | ||
1105 | default: | ||
1106 | ret = false; | ||
1107 | break; | ||
1108 | } | ||
1109 | return ret; | ||
1110 | } | ||
1111 | //sim.ptr, shape.ptr,prim.LocalID, prim.RawPosition, prim.RawOrientation | ||
1112 | internal static object CreateGhostFromShape2(object pWorld, object pShape, uint pLocalID, Vector3 pRawPosition, Quaternion pRawOrientation) | ||
1113 | { | ||
1114 | IndexedMatrix bodyTransform = new IndexedMatrix(); | ||
1115 | bodyTransform._origin = new IndexedVector3(pRawPosition.X, pRawPosition.Y, pRawPosition.Z); | ||
1116 | bodyTransform.SetRotation(new IndexedQuaternion(pRawOrientation.X,pRawOrientation.Y,pRawOrientation.Z,pRawOrientation.W)); | ||
1117 | GhostObject gObj = new PairCachingGhostObject(); | ||
1118 | gObj.SetWorldTransform(bodyTransform); | ||
1119 | CollisionShape shape = pShape as CollisionShape; | ||
1120 | gObj.SetCollisionShape(shape); | ||
1121 | gObj.SetUserPointer(pLocalID); | ||
1122 | // TODO: Add to Special CollisionObjects! | ||
1123 | return gObj; | ||
1124 | } | ||
1125 | |||
1126 | public static void SetCollisionShape2(object pWorld, object pObj, object pShape) | ||
1127 | { | ||
1128 | var world = pWorld as DiscreteDynamicsWorld; | ||
1129 | var obj = pObj as CollisionObject; | ||
1130 | var shape = pShape as CollisionShape; | ||
1131 | obj.SetCollisionShape(shape); | ||
1132 | |||
1133 | } | ||
1134 | //(PhysicsScene.World.ptr, nativeShapeData) | ||
1135 | internal static object BuildNativeShape2(object pWorld, ShapeData pShapeData) | ||
1136 | { | ||
1137 | var world = pWorld as DiscreteDynamicsWorld; | ||
1138 | CollisionShape shape = null; | ||
1139 | switch (pShapeData.Type) | ||
1140 | { | ||
1141 | case BSPhysicsShapeType.SHAPE_BOX: | ||
1142 | shape = new BoxShape(new IndexedVector3(0.5f,0.5f,0.5f)); | ||
1143 | break; | ||
1144 | case BSPhysicsShapeType.SHAPE_CONE: | ||
1145 | shape = new ConeShapeZ(0.5f, 1.0f); | ||
1146 | break; | ||
1147 | case BSPhysicsShapeType.SHAPE_CYLINDER: | ||
1148 | shape = new CylinderShapeZ(new IndexedVector3(0.5f, 0.5f, 0.5f)); | ||
1149 | break; | ||
1150 | case BSPhysicsShapeType.SHAPE_SPHERE: | ||
1151 | shape = new SphereShape(0.5f); | ||
1152 | break; | ||
1153 | |||
1154 | } | ||
1155 | if (shape != null) | ||
1156 | { | ||
1157 | IndexedVector3 scaling = new IndexedVector3(pShapeData.Scale.X, pShapeData.Scale.Y, pShapeData.Scale.Z); | ||
1158 | shape.SetMargin(world.WorldSettings.Params.collisionMargin); | ||
1159 | shape.SetLocalScaling(ref scaling); | ||
1160 | |||
1161 | } | ||
1162 | return shape; | ||
1163 | } | ||
1164 | //PhysicsScene.World.ptr, false | ||
1165 | internal static object CreateCompoundShape2(object pWorld, bool enableDynamicAabbTree) | ||
1166 | { | ||
1167 | return new CompoundShape(enableDynamicAabbTree); | ||
1168 | } | ||
1169 | |||
1170 | internal static int GetNumberOfCompoundChildren2(object pCompoundShape) | ||
1171 | { | ||
1172 | var compoundshape = pCompoundShape as CompoundShape; | ||
1173 | return compoundshape.GetNumChildShapes(); | ||
1174 | } | ||
1175 | //LinksetRoot.PhysShape.ptr, newShape.ptr, displacementPos, displacementRot | ||
1176 | internal static void AddChildShapeToCompoundShape2(object pCShape, object paddShape, Vector3 displacementPos, Quaternion displacementRot) | ||
1177 | { | ||
1178 | IndexedMatrix relativeTransform = new IndexedMatrix(); | ||
1179 | var compoundshape = pCShape as CompoundShape; | ||
1180 | var addshape = paddShape as CollisionShape; | ||
1181 | |||
1182 | relativeTransform._origin = new IndexedVector3(displacementPos.X, displacementPos.Y, displacementPos.Z); | ||
1183 | relativeTransform.SetRotation(new IndexedQuaternion(displacementRot.X,displacementRot.Y,displacementRot.Z,displacementRot.W)); | ||
1184 | compoundshape.AddChildShape(ref relativeTransform, addshape); | ||
1185 | |||
1186 | } | ||
1187 | |||
1188 | internal static object RemoveChildShapeFromCompoundShapeIndex2(object pCShape, int pii) | ||
1189 | { | ||
1190 | var compoundshape = pCShape as CompoundShape; | ||
1191 | CollisionShape ret = null; | ||
1192 | ret = compoundshape.GetChildShape(pii); | ||
1193 | compoundshape.RemoveChildShapeByIndex(pii); | ||
1194 | return ret; | ||
1195 | } | ||
1196 | |||
1197 | internal static object CreateGroundPlaneShape2(uint pLocalId, float pheight, float pcollisionMargin) | ||
1198 | { | ||
1199 | StaticPlaneShape m_planeshape = new StaticPlaneShape(new IndexedVector3(0,0,1),(int)pheight ); | ||
1200 | m_planeshape.SetMargin(pcollisionMargin); | ||
1201 | m_planeshape.SetUserPointer(pLocalId); | ||
1202 | return m_planeshape; | ||
1203 | } | ||
1204 | |||
1205 | internal static object CreateHingeConstraint2(object pWorld, object pBody1, object ppBody2, Vector3 ppivotInA, Vector3 ppivotInB, Vector3 paxisInA, Vector3 paxisInB, bool puseLinearReferenceFrameA, bool pdisableCollisionsBetweenLinkedBodies) | ||
1206 | { | ||
1207 | HingeConstraint constrain = null; | ||
1208 | var rb1 = pBody1 as RigidBody; | ||
1209 | var rb2 = ppBody2 as RigidBody; | ||
1210 | if (rb1 != null && rb2 != null) | ||
1211 | { | ||
1212 | IndexedVector3 pivotInA = new IndexedVector3(ppivotInA.X, ppivotInA.Y, ppivotInA.Z); | ||
1213 | IndexedVector3 pivotInB = new IndexedVector3(ppivotInB.X, ppivotInB.Y, ppivotInB.Z); | ||
1214 | IndexedVector3 axisInA = new IndexedVector3(paxisInA.X, paxisInA.Y, paxisInA.Z); | ||
1215 | IndexedVector3 axisInB = new IndexedVector3(paxisInB.X, paxisInB.Y, paxisInB.Z); | ||
1216 | var world = pWorld as DiscreteDynamicsWorld; | ||
1217 | world.AddConstraint(constrain, pdisableCollisionsBetweenLinkedBodies); | ||
1218 | } | ||
1219 | return constrain; | ||
1220 | } | ||
1221 | |||
1222 | internal static bool ReleaseHeightMapInfo2(object pMapInfo) | ||
1223 | { | ||
1224 | if (pMapInfo != null) | ||
1225 | { | ||
1226 | BulletHeightMapInfo mapinfo = pMapInfo as BulletHeightMapInfo; | ||
1227 | if (mapinfo.heightMap != null) | ||
1228 | mapinfo.heightMap = null; | ||
1229 | |||
1230 | |||
1231 | } | ||
1232 | return true; | ||
1233 | } | ||
1234 | |||
1235 | internal static object CreateHullShape2(object pWorld, int pHullCount, float[] pConvHulls) | ||
1236 | { | ||
1237 | CompoundShape compoundshape = new CompoundShape(false); | ||
1238 | var world = pWorld as DiscreteDynamicsWorld; | ||
1239 | |||
1240 | |||
1241 | compoundshape.SetMargin(world.WorldSettings.Params.collisionMargin); | ||
1242 | int ii = 1; | ||
1243 | |||
1244 | for (int i = 0; i < pHullCount; i++) | ||
1245 | { | ||
1246 | int vertexCount = (int) pConvHulls[ii]; | ||
1247 | |||
1248 | IndexedVector3 centroid = new IndexedVector3(pConvHulls[ii + 1], pConvHulls[ii + 2], pConvHulls[ii + 3]); | ||
1249 | IndexedMatrix childTrans = IndexedMatrix.Identity; | ||
1250 | childTrans._origin = centroid; | ||
1251 | |||
1252 | List<IndexedVector3> virts = new List<IndexedVector3>(); | ||
1253 | int ender = ((ii + 4) + (vertexCount*3)); | ||
1254 | for (int iii = ii + 4; iii < ender; iii+=3) | ||
1255 | { | ||
1256 | |||
1257 | virts.Add(new IndexedVector3(pConvHulls[iii], pConvHulls[iii + 1], pConvHulls[iii +2])); | ||
1258 | } | ||
1259 | ConvexHullShape convexShape = new ConvexHullShape(virts, vertexCount); | ||
1260 | convexShape.SetMargin(world.WorldSettings.Params.collisionMargin); | ||
1261 | compoundshape.AddChildShape(ref childTrans, convexShape); | ||
1262 | ii += (vertexCount*3 + 4); | ||
1263 | } | ||
1264 | |||
1265 | |||
1266 | return compoundshape; | ||
1267 | } | ||
1268 | |||
1269 | internal static object CreateMeshShape2(object pWorld, int pIndicesCount, int[] indices, int pVerticesCount, float[] verticesAsFloats) | ||
1270 | { | ||
1271 | //DumpRaw(indices,verticesAsFloats,pIndicesCount,pVerticesCount); | ||
1272 | |||
1273 | for (int iter = 0; iter < pVerticesCount; iter++) | ||
1274 | { | ||
1275 | if (verticesAsFloats[iter] > 0 && verticesAsFloats[iter] < 0.0001) verticesAsFloats[iter] = 0; | ||
1276 | if (verticesAsFloats[iter] < 0 && verticesAsFloats[iter] > -0.0001) verticesAsFloats[iter] = 0; | ||
1277 | } | ||
1278 | |||
1279 | ObjectArray<int> indicesarr = new ObjectArray<int>(indices); | ||
1280 | ObjectArray<float> vertices = new ObjectArray<float>(verticesAsFloats); | ||
1281 | DumpRaw(indicesarr,vertices,pIndicesCount,pVerticesCount); | ||
1282 | var world = pWorld as DiscreteDynamicsWorld; | ||
1283 | IndexedMesh mesh = new IndexedMesh(); | ||
1284 | mesh.m_indexType = PHY_ScalarType.PHY_INTEGER; | ||
1285 | mesh.m_numTriangles = pIndicesCount/3; | ||
1286 | mesh.m_numVertices = pVerticesCount; | ||
1287 | mesh.m_triangleIndexBase = indicesarr; | ||
1288 | mesh.m_vertexBase = vertices; | ||
1289 | mesh.m_vertexStride = 3; | ||
1290 | mesh.m_vertexType = PHY_ScalarType.PHY_FLOAT; | ||
1291 | mesh.m_triangleIndexStride = 3; | ||
1292 | |||
1293 | TriangleIndexVertexArray tribuilder = new TriangleIndexVertexArray(); | ||
1294 | tribuilder.AddIndexedMesh(mesh, PHY_ScalarType.PHY_INTEGER); | ||
1295 | BvhTriangleMeshShape meshShape = new BvhTriangleMeshShape(tribuilder, true,true); | ||
1296 | meshShape.SetMargin(world.WorldSettings.Params.collisionMargin); | ||
1297 | // world.UpdateSingleAabb(meshShape); | ||
1298 | return meshShape; | ||
1299 | |||
1300 | } | ||
1301 | public static void DumpRaw(ObjectArray<int>indices, ObjectArray<float> vertices, int pIndicesCount,int pVerticesCount ) | ||
1302 | { | ||
1303 | |||
1304 | String fileName = "objTest3.raw"; | ||
1305 | String completePath = System.IO.Path.Combine(Util.configDir(), fileName); | ||
1306 | StreamWriter sw = new StreamWriter(completePath); | ||
1307 | IndexedMesh mesh = new IndexedMesh(); | ||
1308 | |||
1309 | mesh.m_indexType = PHY_ScalarType.PHY_INTEGER; | ||
1310 | mesh.m_numTriangles = pIndicesCount / 3; | ||
1311 | mesh.m_numVertices = pVerticesCount; | ||
1312 | mesh.m_triangleIndexBase = indices; | ||
1313 | mesh.m_vertexBase = vertices; | ||
1314 | mesh.m_vertexStride = 3; | ||
1315 | mesh.m_vertexType = PHY_ScalarType.PHY_FLOAT; | ||
1316 | mesh.m_triangleIndexStride = 3; | ||
1317 | |||
1318 | TriangleIndexVertexArray tribuilder = new TriangleIndexVertexArray(); | ||
1319 | tribuilder.AddIndexedMesh(mesh, PHY_ScalarType.PHY_INTEGER); | ||
1320 | |||
1321 | |||
1322 | |||
1323 | for (int i = 0; i < pVerticesCount; i++) | ||
1324 | { | ||
1325 | |||
1326 | string s = vertices[indices[i * 3]].ToString("0.0000"); | ||
1327 | s += " " + vertices[indices[i * 3 + 1]].ToString("0.0000"); | ||
1328 | s += " " + vertices[indices[i * 3 + 2]].ToString("0.0000"); | ||
1329 | |||
1330 | sw.Write(s + "\n"); | ||
1331 | } | ||
1332 | |||
1333 | sw.Close(); | ||
1334 | } | ||
1335 | public static void DumpRaw(int[] indices, float[] vertices, int pIndicesCount, int pVerticesCount) | ||
1336 | { | ||
1337 | |||
1338 | String fileName = "objTest6.raw"; | ||
1339 | String completePath = System.IO.Path.Combine(Util.configDir(), fileName); | ||
1340 | StreamWriter sw = new StreamWriter(completePath); | ||
1341 | IndexedMesh mesh = new IndexedMesh(); | ||
1342 | |||
1343 | mesh.m_indexType = PHY_ScalarType.PHY_INTEGER; | ||
1344 | mesh.m_numTriangles = pIndicesCount / 3; | ||
1345 | mesh.m_numVertices = pVerticesCount; | ||
1346 | mesh.m_triangleIndexBase = indices; | ||
1347 | mesh.m_vertexBase = vertices; | ||
1348 | mesh.m_vertexStride = 3; | ||
1349 | mesh.m_vertexType = PHY_ScalarType.PHY_FLOAT; | ||
1350 | mesh.m_triangleIndexStride = 3; | ||
1351 | |||
1352 | TriangleIndexVertexArray tribuilder = new TriangleIndexVertexArray(); | ||
1353 | tribuilder.AddIndexedMesh(mesh, PHY_ScalarType.PHY_INTEGER); | ||
1354 | |||
1355 | |||
1356 | sw.WriteLine("Indices"); | ||
1357 | sw.WriteLine(string.Format("int[] indices = new int[{0}];",pIndicesCount)); | ||
1358 | for (int iter = 0; iter < indices.Length; iter++) | ||
1359 | { | ||
1360 | sw.WriteLine(string.Format("indices[{0}]={1};",iter,indices[iter])); | ||
1361 | } | ||
1362 | sw.WriteLine("VerticesFloats"); | ||
1363 | sw.WriteLine(string.Format("float[] vertices = new float[{0}];", pVerticesCount)); | ||
1364 | for (int iter = 0; iter < vertices.Length; iter++) | ||
1365 | { | ||
1366 | sw.WriteLine(string.Format("Vertices[{0}]={1};", iter, vertices[iter].ToString("0.0000"))); | ||
1367 | } | ||
1368 | |||
1369 | // for (int i = 0; i < pVerticesCount; i++) | ||
1370 | // { | ||
1371 | // | ||
1372 | // string s = vertices[indices[i * 3]].ToString("0.0000"); | ||
1373 | // s += " " + vertices[indices[i * 3 + 1]].ToString("0.0000"); | ||
1374 | // s += " " + vertices[indices[i * 3 + 2]].ToString("0.0000"); | ||
1375 | // | ||
1376 | // sw.Write(s + "\n"); | ||
1377 | //} | ||
1378 | |||
1379 | sw.Close(); | ||
1380 | } | ||
1381 | //PhysicsScene.World.ptr, m_mapInfo.ID, m_mapInfo.minCoords, m_mapInfo.maxCoords, m_mapInfo.heightMap, PhysicsScene.Params.terrainCollisionMargin | ||
1382 | internal static object CreateHeightMapInfo2(object pWorld, uint pId, Vector3 pminCoords, Vector3 pmaxCoords, float[] pheightMap, float pCollisionMargin) | ||
1383 | { | ||
1384 | BulletHeightMapInfo mapInfo = new BulletHeightMapInfo(pId, pheightMap, null); | ||
1385 | mapInfo.heightMap = null; | ||
1386 | mapInfo.minCoords = pminCoords; | ||
1387 | mapInfo.maxCoords = pmaxCoords; | ||
1388 | mapInfo.sizeX = (int) (pmaxCoords.X - pminCoords.X); | ||
1389 | mapInfo.sizeY = (int) (pmaxCoords.Y - pminCoords.Y); | ||
1390 | mapInfo.ID = pId; | ||
1391 | mapInfo.minZ = pminCoords.Z; | ||
1392 | mapInfo.maxZ = pmaxCoords.Z; | ||
1393 | mapInfo.collisionMargin = pCollisionMargin; | ||
1394 | if (mapInfo.minZ == mapInfo.maxZ) | ||
1395 | mapInfo.minZ -= 0.2f; | ||
1396 | mapInfo.heightMap = pheightMap; | ||
1397 | |||
1398 | return mapInfo; | ||
1399 | |||
1400 | } | ||
1401 | |||
1402 | internal static object CreateTerrainShape2(object pMapInfo) | ||
1403 | { | ||
1404 | BulletHeightMapInfo mapinfo = pMapInfo as BulletHeightMapInfo; | ||
1405 | const int upAxis = 2; | ||
1406 | const float scaleFactor = 1.0f; | ||
1407 | HeightfieldTerrainShape terrainShape = new HeightfieldTerrainShape((int)mapinfo.sizeX, (int)mapinfo.sizeY, | ||
1408 | mapinfo.heightMap, scaleFactor, | ||
1409 | mapinfo.minZ, mapinfo.maxZ, upAxis, | ||
1410 | false); | ||
1411 | terrainShape.SetMargin(mapinfo.collisionMargin + 0.5f); | ||
1412 | terrainShape.SetUseDiamondSubdivision(true); | ||
1413 | terrainShape.SetUserPointer(mapinfo.ID); | ||
1414 | return terrainShape; | ||
1415 | } | ||
1416 | |||
1417 | internal static bool TranslationalLimitMotor2(object pConstraint, float ponOff, float targetVelocity, float maxMotorForce) | ||
1418 | { | ||
1419 | TypedConstraint tconstrain = pConstraint as TypedConstraint; | ||
1420 | bool onOff = ponOff != 0; | ||
1421 | bool ret = false; | ||
1422 | |||
1423 | switch (tconstrain.GetConstraintType()) | ||
1424 | { | ||
1425 | case TypedConstraintType.D6_CONSTRAINT_TYPE: | ||
1426 | Generic6DofConstraint constrain = pConstraint as Generic6DofConstraint; | ||
1427 | constrain.GetTranslationalLimitMotor().m_enableMotor[0] = onOff; | ||
1428 | constrain.GetTranslationalLimitMotor().m_targetVelocity[0] = targetVelocity; | ||
1429 | constrain.GetTranslationalLimitMotor().m_maxMotorForce[0] = maxMotorForce; | ||
1430 | ret = true; | ||
1431 | break; | ||
1432 | } | ||
1433 | |||
1434 | |||
1435 | return ret; | ||
1436 | |||
1437 | } | ||
1438 | |||
1439 | internal static int PhysicsStep2(object pWorld, float timeStep, int m_maxSubSteps, float m_fixedTimeStep, out int updatedEntityCount, out List<BulletXNA.EntityProperties> updatedEntities, out int collidersCount, out List<BulletXNA.CollisionDesc>colliders) | ||
1440 | { | ||
1441 | int epic = PhysicsStepint2(pWorld, timeStep, m_maxSubSteps, m_fixedTimeStep, out updatedEntityCount, out updatedEntities, | ||
1442 | out collidersCount, out colliders); | ||
1443 | return epic; | ||
1444 | } | ||
1445 | |||
1446 | private static int PhysicsStepint2(object pWorld,float timeStep, int m_maxSubSteps, float m_fixedTimeStep, out int updatedEntityCount, out List<BulletXNA.EntityProperties> updatedEntities, out int collidersCount, out List<BulletXNA.CollisionDesc> colliders) | ||
1447 | { | ||
1448 | int numSimSteps = 0; | ||
1449 | |||
1450 | |||
1451 | //if (updatedEntities is null) | ||
1452 | // updatedEntities = new List<BulletXNA.EntityProperties>(); | ||
1453 | |||
1454 | //if (colliders is null) | ||
1455 | // colliders = new List<BulletXNA.CollisionDesc>(); | ||
1456 | |||
1457 | |||
1458 | if (pWorld is DiscreteDynamicsWorld) | ||
1459 | { | ||
1460 | DiscreteDynamicsWorld world = pWorld as DiscreteDynamicsWorld; | ||
1461 | |||
1462 | numSimSteps = world.StepSimulation(timeStep, m_maxSubSteps, m_fixedTimeStep); | ||
1463 | int updates = 0; | ||
1464 | |||
1465 | updatedEntityCount = world.UpdatedObjects.Count; | ||
1466 | updatedEntities = new List<BulletXNA.EntityProperties>(world.UpdatedObjects); | ||
1467 | updatedEntityCount = updatedEntities.Count; | ||
1468 | world.UpdatedObjects.Clear(); | ||
1469 | |||
1470 | |||
1471 | collidersCount = world.UpdatedCollisions.Count; | ||
1472 | colliders = new List<BulletXNA.CollisionDesc>(world.UpdatedCollisions); | ||
1473 | |||
1474 | world.UpdatedCollisions.Clear(); | ||
1475 | m_collisionsThisFrame = 0; | ||
1476 | int numManifolds = world.GetDispatcher().GetNumManifolds(); | ||
1477 | for (int j = 0; j < numManifolds; j++) | ||
1478 | { | ||
1479 | PersistentManifold contactManifold = world.GetDispatcher().GetManifoldByIndexInternal(j); | ||
1480 | int numContacts = contactManifold.GetNumContacts(); | ||
1481 | if (numContacts == 0) | ||
1482 | continue; | ||
1483 | |||
1484 | CollisionObject objA = contactManifold.GetBody0() as CollisionObject; | ||
1485 | CollisionObject objB = contactManifold.GetBody1() as CollisionObject; | ||
1486 | |||
1487 | ManifoldPoint manifoldPoint = contactManifold.GetContactPoint(0); | ||
1488 | IndexedVector3 contactPoint = manifoldPoint.GetPositionWorldOnB(); | ||
1489 | IndexedVector3 contactNormal = -manifoldPoint.m_normalWorldOnB; // make relative to A | ||
1490 | |||
1491 | RecordCollision(world, objA, objB, contactPoint, contactNormal); | ||
1492 | m_collisionsThisFrame ++; | ||
1493 | if (m_collisionsThisFrame >= 9999999) | ||
1494 | break; | ||
1495 | |||
1496 | |||
1497 | } | ||
1498 | |||
1499 | |||
1500 | } | ||
1501 | else | ||
1502 | { | ||
1503 | //if (updatedEntities is null) | ||
1504 | updatedEntities = new List<BulletXNA.EntityProperties>(); | ||
1505 | updatedEntityCount = 0; | ||
1506 | //if (colliders is null) | ||
1507 | colliders = new List<BulletXNA.CollisionDesc>(); | ||
1508 | collidersCount = 0; | ||
1509 | } | ||
1510 | return numSimSteps; | ||
1511 | } | ||
1512 | |||
1513 | private static void RecordCollision(CollisionWorld world,CollisionObject objA, CollisionObject objB, IndexedVector3 contact, IndexedVector3 norm) | ||
1514 | { | ||
1515 | |||
1516 | IndexedVector3 contactNormal = norm; | ||
1517 | if ((objA.GetCollisionFlags() & BulletXNA.BulletCollision.CollisionFlags.BS_WANTS_COLLISIONS) == 0 && | ||
1518 | (objB.GetCollisionFlags() & BulletXNA.BulletCollision.CollisionFlags.BS_WANTS_COLLISIONS) == 0) | ||
1519 | { | ||
1520 | return; | ||
1521 | } | ||
1522 | uint idA = (uint)objA.GetUserPointer(); | ||
1523 | uint idB = (uint)objB.GetUserPointer(); | ||
1524 | if (idA > idB) | ||
1525 | { | ||
1526 | uint temp = idA; | ||
1527 | idA = idB; | ||
1528 | idB = temp; | ||
1529 | contactNormal = -contactNormal; | ||
1530 | } | ||
1531 | |||
1532 | ulong collisionID = ((ulong) idA << 32) | idB; | ||
1533 | |||
1534 | BulletXNA.CollisionDesc cDesc = new BulletXNA.CollisionDesc() | ||
1535 | { | ||
1536 | aID = idA, | ||
1537 | bID = idB, | ||
1538 | point = contact, | ||
1539 | normal = contactNormal | ||
1540 | }; | ||
1541 | world.UpdatedCollisions.Add(cDesc); | ||
1542 | m_collisionsThisFrame++; | ||
1543 | |||
1544 | |||
1545 | } | ||
1546 | private static EntityProperties GetDebugProperties(object pWorld, object pBody) | ||
1547 | { | ||
1548 | EntityProperties ent = new EntityProperties(); | ||
1549 | DiscreteDynamicsWorld world = pWorld as DiscreteDynamicsWorld; | ||
1550 | RigidBody body = pBody as RigidBody; | ||
1551 | IndexedMatrix transform = body.GetWorldTransform(); | ||
1552 | IndexedVector3 LinearVelocity = body.GetInterpolationLinearVelocity(); | ||
1553 | IndexedVector3 AngularVelocity = body.GetInterpolationAngularVelocity(); | ||
1554 | IndexedQuaternion rotation = transform.GetRotation(); | ||
1555 | ent.Acceleration = Vector3.Zero; | ||
1556 | ent.ID = (uint)body.GetUserPointer(); | ||
1557 | ent.Position = new Vector3(transform._origin.X,transform._origin.Y,transform._origin.Z); | ||
1558 | ent.Rotation = new Quaternion(rotation.X,rotation.Y,rotation.Z,rotation.W); | ||
1559 | ent.Velocity = new Vector3(LinearVelocity.X, LinearVelocity.Y, LinearVelocity.Z); | ||
1560 | ent.RotationalVelocity = new Vector3(AngularVelocity.X, AngularVelocity.Y, AngularVelocity.Z); | ||
1561 | return ent; | ||
1562 | |||
1563 | |||
1564 | } | ||
1565 | |||
1566 | |||
1567 | internal static Vector3 GetLocalScaling2(object pBody) | ||
1568 | { | ||
1569 | CollisionShape shape = pBody as CollisionShape; | ||
1570 | IndexedVector3 scale = shape.GetLocalScaling(); | ||
1571 | return new Vector3(scale.X,scale.Y,scale.Z); | ||
1572 | } | ||
1573 | |||
1574 | internal static bool RayCastGround(object pWorld, Vector3 _RayOrigin, float pRayHeight, object NotMe) | ||
1575 | { | ||
1576 | DynamicsWorld world = pWorld as DynamicsWorld; | ||
1577 | if (world != null) | ||
1578 | { | ||
1579 | if (NotMe is CollisionObject || NotMe is RigidBody) | ||
1580 | { | ||
1581 | CollisionObject AvoidBody = NotMe as CollisionObject; | ||
1582 | |||
1583 | IndexedVector3 rOrigin = new IndexedVector3(_RayOrigin.X, _RayOrigin.Y, _RayOrigin.Z); | ||
1584 | IndexedVector3 rEnd = new IndexedVector3(_RayOrigin.X, _RayOrigin.Y, _RayOrigin.Z - pRayHeight); | ||
1585 | using ( | ||
1586 | ClosestNotMeRayResultCallback rayCallback = new ClosestNotMeRayResultCallback(rOrigin, | ||
1587 | rEnd, AvoidBody) | ||
1588 | ) | ||
1589 | { | ||
1590 | world.RayTest(ref rOrigin, ref rEnd, rayCallback); | ||
1591 | if (rayCallback.HasHit()) | ||
1592 | { | ||
1593 | IndexedVector3 hitLocation = rayCallback.m_hitPointWorld; | ||
1594 | |||
1595 | } | ||
1596 | return rayCallback.HasHit(); | ||
1597 | } | ||
1598 | } | ||
1599 | } | ||
1600 | return false; | ||
1601 | } | ||
1602 | } | ||
1603 | } | ||