1
0

BSApiTemplate.cs 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748
  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. using System;
  28. using System.Collections.Generic;
  29. using System.Runtime.InteropServices;
  30. using System.Security;
  31. using System.Text;
  32. using OpenMetaverse;
  33. namespace OpenSim.Region.Physics.BulletSPlugin {
  34. // Constraint type values as defined by Bullet
  35. public enum ConstraintType : int
  36. {
  37. POINT2POINT_CONSTRAINT_TYPE = 3,
  38. HINGE_CONSTRAINT_TYPE,
  39. CONETWIST_CONSTRAINT_TYPE,
  40. D6_CONSTRAINT_TYPE,
  41. SLIDER_CONSTRAINT_TYPE,
  42. CONTACT_CONSTRAINT_TYPE,
  43. D6_SPRING_CONSTRAINT_TYPE,
  44. GEAR_CONSTRAINT_TYPE, // added in Bullet 2.82
  45. FIXED_CONSTRAINT_TYPE, // added in Bullet 2.82
  46. MAX_CONSTRAINT_TYPE, // last type defined by Bullet
  47. //
  48. BS_FIXED_CONSTRAINT_TYPE = 1234 // BulletSim constraint that is fixed and unmoving
  49. }
  50. // ===============================================================================
  51. [StructLayout(LayoutKind.Sequential)]
  52. public struct ConvexHull
  53. {
  54. Vector3 Offset;
  55. int VertexCount;
  56. Vector3[] Vertices;
  57. }
  58. public enum BSPhysicsShapeType
  59. {
  60. SHAPE_UNKNOWN = 0,
  61. SHAPE_CAPSULE = 1,
  62. SHAPE_BOX = 2,
  63. SHAPE_CONE = 3,
  64. SHAPE_CYLINDER = 4,
  65. SHAPE_SPHERE = 5,
  66. SHAPE_MESH = 6,
  67. SHAPE_HULL = 7,
  68. // following defined by BulletSim
  69. SHAPE_GROUNDPLANE = 20,
  70. SHAPE_TERRAIN = 21,
  71. SHAPE_COMPOUND = 22,
  72. SHAPE_HEIGHTMAP = 23,
  73. SHAPE_AVATAR = 24,
  74. SHAPE_CONVEXHULL= 25,
  75. SHAPE_GIMPACT = 26,
  76. };
  77. // The native shapes have predefined shape hash keys
  78. public enum FixedShapeKey : ulong
  79. {
  80. KEY_NONE = 0,
  81. KEY_BOX = 1,
  82. KEY_SPHERE = 2,
  83. KEY_CONE = 3,
  84. KEY_CYLINDER = 4,
  85. KEY_CAPSULE = 5,
  86. KEY_AVATAR = 6,
  87. }
  88. [StructLayout(LayoutKind.Sequential)]
  89. public struct ShapeData
  90. {
  91. public UInt32 ID;
  92. public BSPhysicsShapeType Type;
  93. public Vector3 Position;
  94. public Quaternion Rotation;
  95. public Vector3 Velocity;
  96. public Vector3 Scale;
  97. public float Mass;
  98. public float Buoyancy;
  99. public System.UInt64 HullKey;
  100. public System.UInt64 MeshKey;
  101. public float Friction;
  102. public float Restitution;
  103. public float Collidable; // true of things bump into this
  104. public float Static; // true if a static object. Otherwise gravity, etc.
  105. public float Solid; // true if object cannot be passed through
  106. public Vector3 Size;
  107. // note that bools are passed as floats since bool size changes by language and architecture
  108. public const float numericTrue = 1f;
  109. public const float numericFalse = 0f;
  110. }
  111. [StructLayout(LayoutKind.Sequential)]
  112. public struct SweepHit
  113. {
  114. public UInt32 ID;
  115. public float Fraction;
  116. public Vector3 Normal;
  117. public Vector3 Point;
  118. }
  119. [StructLayout(LayoutKind.Sequential)]
  120. public struct RaycastHit
  121. {
  122. public UInt32 ID;
  123. public float Fraction;
  124. public Vector3 Normal;
  125. }
  126. [StructLayout(LayoutKind.Sequential)]
  127. public struct CollisionDesc
  128. {
  129. public UInt32 aID;
  130. public UInt32 bID;
  131. public Vector3 point;
  132. public Vector3 normal;
  133. public float penetration;
  134. }
  135. [StructLayout(LayoutKind.Sequential)]
  136. public struct EntityProperties
  137. {
  138. public UInt32 ID;
  139. public Vector3 Position;
  140. public Quaternion Rotation;
  141. public Vector3 Velocity;
  142. public Vector3 Acceleration;
  143. public Vector3 RotationalVelocity;
  144. public override string ToString()
  145. {
  146. StringBuilder buff = new StringBuilder();
  147. buff.Append("<i=");
  148. buff.Append(ID.ToString());
  149. buff.Append(",p=");
  150. buff.Append(Position.ToString());
  151. buff.Append(",r=");
  152. buff.Append(Rotation.ToString());
  153. buff.Append(",v=");
  154. buff.Append(Velocity.ToString());
  155. buff.Append(",a=");
  156. buff.Append(Acceleration.ToString());
  157. buff.Append(",rv=");
  158. buff.Append(RotationalVelocity.ToString());
  159. buff.Append(">");
  160. return buff.ToString();
  161. }
  162. }
  163. // Format of this structure must match the definition in the C++ code
  164. // NOTE: adding the X causes compile breaks if used. These are unused symbols
  165. // that can be removed from both here and the unmanaged definition of this structure.
  166. [StructLayout(LayoutKind.Sequential)]
  167. public struct ConfigurationParameters
  168. {
  169. public float defaultFriction;
  170. public float defaultDensity;
  171. public float defaultRestitution;
  172. public float collisionMargin;
  173. public float gravity;
  174. public float maxPersistantManifoldPoolSize;
  175. public float maxCollisionAlgorithmPoolSize;
  176. public float shouldDisableContactPoolDynamicAllocation;
  177. public float shouldForceUpdateAllAabbs;
  178. public float shouldRandomizeSolverOrder;
  179. public float shouldSplitSimulationIslands;
  180. public float shouldEnableFrictionCaching;
  181. public float numberOfSolverIterations;
  182. public float useSingleSidedMeshes;
  183. public float globalContactBreakingThreshold;
  184. public float physicsLoggingFrames;
  185. public const float numericTrue = 1f;
  186. public const float numericFalse = 0f;
  187. }
  188. // Parameters passed for the conversion of a mesh to a hull using Bullet's HACD library.
  189. [StructLayout(LayoutKind.Sequential)]
  190. public struct HACDParams
  191. {
  192. // usual default values
  193. public float maxVerticesPerHull; // 100
  194. public float minClusters; // 2
  195. public float compacityWeight; // 0.1
  196. public float volumeWeight; // 0.0
  197. public float concavity; // 100
  198. public float addExtraDistPoints; // false
  199. public float addNeighboursDistPoints; // false
  200. public float addFacesPoints; // false
  201. public float shouldAdjustCollisionMargin; // false
  202. }
  203. // The states a bullet collision object can have
  204. public enum ActivationState : uint
  205. {
  206. ACTIVE_TAG = 1,
  207. ISLAND_SLEEPING,
  208. WANTS_DEACTIVATION,
  209. DISABLE_DEACTIVATION,
  210. DISABLE_SIMULATION,
  211. }
  212. public enum CollisionObjectTypes : int
  213. {
  214. CO_COLLISION_OBJECT = 1 << 0,
  215. CO_RIGID_BODY = 1 << 1,
  216. CO_GHOST_OBJECT = 1 << 2,
  217. CO_SOFT_BODY = 1 << 3,
  218. CO_HF_FLUID = 1 << 4,
  219. CO_USER_TYPE = 1 << 5,
  220. }
  221. // Values used by Bullet and BulletSim to control object properties.
  222. // Bullet's "CollisionFlags" has more to do with operations on the
  223. // object (if collisions happen, if gravity effects it, ...).
  224. public enum CollisionFlags : uint
  225. {
  226. CF_STATIC_OBJECT = 1 << 0,
  227. CF_KINEMATIC_OBJECT = 1 << 1,
  228. CF_NO_CONTACT_RESPONSE = 1 << 2,
  229. CF_CUSTOM_MATERIAL_CALLBACK = 1 << 3,
  230. CF_CHARACTER_OBJECT = 1 << 4,
  231. CF_DISABLE_VISUALIZE_OBJECT = 1 << 5,
  232. CF_DISABLE_SPU_COLLISION_PROCESS = 1 << 6,
  233. // Following used by BulletSim to control collisions and updates
  234. BS_SUBSCRIBE_COLLISION_EVENTS = 1 << 10, // return collision events from unmanaged to managed
  235. BS_FLOATS_ON_WATER = 1 << 11, // the object should float at water level
  236. BS_VEHICLE_COLLISIONS = 1 << 12, // return collisions for vehicle ground checking
  237. BS_RETURN_ROOT_COMPOUND_SHAPE = 1 << 13, // return the pos/rot of the root shape in a compound shape
  238. BS_NONE = 0,
  239. BS_ALL = 0x7FFF // collision flags are a signed short
  240. };
  241. // Values f collisions groups and masks
  242. public enum CollisionFilterGroups : uint
  243. {
  244. // Don't use the bit definitions!! Define the use in a
  245. // filter/mask definition below. This way collision interactions
  246. // are more easily found and debugged.
  247. BNoneGroup = 0,
  248. BDefaultGroup = 1 << 0, // 0001
  249. BStaticGroup = 1 << 1, // 0002
  250. BKinematicGroup = 1 << 2, // 0004
  251. BDebrisGroup = 1 << 3, // 0008
  252. BSensorTrigger = 1 << 4, // 0010
  253. BCharacterGroup = 1 << 5, // 0020
  254. BAllGroup = 0x0007FFF, // collision flags are a signed short
  255. // Filter groups defined by BulletSim
  256. BGroundPlaneGroup = 1 << 8, // 0400
  257. BTerrainGroup = 1 << 9, // 0800
  258. BRaycastGroup = 1 << 10, // 1000
  259. BSolidGroup = 1 << 11, // 2000
  260. // BLinksetGroup = xx // a linkset proper is either static or dynamic
  261. BLinksetChildGroup = 1 << 12, // 4000
  262. };
  263. // CFM controls the 'hardness' of the constraint. 0=fixed, 0..1=violatable. Default=0
  264. // ERP controls amount of correction per tick. Usable range=0.1..0.8. Default=0.2.
  265. public enum ConstraintParams : int
  266. {
  267. BT_CONSTRAINT_ERP = 1, // this one is not used in Bullet as of 20120730
  268. BT_CONSTRAINT_STOP_ERP,
  269. BT_CONSTRAINT_CFM,
  270. BT_CONSTRAINT_STOP_CFM,
  271. };
  272. public enum ConstraintParamAxis : int
  273. {
  274. AXIS_LINEAR_X = 0,
  275. AXIS_LINEAR_Y,
  276. AXIS_LINEAR_Z,
  277. AXIS_ANGULAR_X,
  278. AXIS_ANGULAR_Y,
  279. AXIS_ANGULAR_Z,
  280. AXIS_LINEAR_ALL = 20, // added by BulletSim so we don't have to do zillions of calls
  281. AXIS_ANGULAR_ALL,
  282. AXIS_ALL
  283. };
  284. public abstract class BSAPITemplate
  285. {
  286. // Returns the name of the underlying Bullet engine
  287. public abstract string BulletEngineName { get; }
  288. public abstract string BulletEngineVersion { get; protected set;}
  289. // Initialization and simulation
  290. public abstract BulletWorld Initialize(Vector3 maxPosition, ConfigurationParameters parms,
  291. int maxCollisions, ref CollisionDesc[] collisionArray,
  292. int maxUpdates, ref EntityProperties[] updateArray
  293. );
  294. public abstract int PhysicsStep(BulletWorld world, float timeStep, int maxSubSteps, float fixedTimeStep,
  295. out int updatedEntityCount, out int collidersCount);
  296. public abstract bool UpdateParameter(BulletWorld world, UInt32 localID, String parm, float value);
  297. public abstract void Shutdown(BulletWorld sim);
  298. public abstract bool PushUpdate(BulletBody obj);
  299. // =====================================================================================
  300. // Mesh, hull, shape and body creation helper routines
  301. public abstract BulletShape CreateMeshShape(BulletWorld world,
  302. int indicesCount, int[] indices,
  303. int verticesCount, float[] vertices );
  304. public abstract BulletShape CreateGImpactShape(BulletWorld world,
  305. int indicesCount, int[] indices,
  306. int verticesCount, float[] vertices );
  307. public abstract BulletShape CreateHullShape(BulletWorld world,
  308. int hullCount, float[] hulls);
  309. public abstract BulletShape BuildHullShapeFromMesh(BulletWorld world, BulletShape meshShape, HACDParams parms);
  310. public abstract BulletShape BuildConvexHullShapeFromMesh(BulletWorld world, BulletShape meshShape);
  311. public abstract BulletShape CreateConvexHullShape(BulletWorld world,
  312. int indicesCount, int[] indices,
  313. int verticesCount, float[] vertices );
  314. public abstract BulletShape BuildNativeShape(BulletWorld world, ShapeData shapeData);
  315. public abstract bool IsNativeShape(BulletShape shape);
  316. public abstract void SetShapeCollisionMargin(BulletShape shape, float margin);
  317. public abstract BulletShape BuildCapsuleShape(BulletWorld world, float radius, float height, Vector3 scale);
  318. public abstract BulletShape CreateCompoundShape(BulletWorld sim, bool enableDynamicAabbTree);
  319. public abstract int GetNumberOfCompoundChildren(BulletShape cShape);
  320. public abstract void AddChildShapeToCompoundShape(BulletShape cShape, BulletShape addShape, Vector3 pos, Quaternion rot);
  321. public abstract BulletShape GetChildShapeFromCompoundShapeIndex(BulletShape cShape, int indx);
  322. public abstract BulletShape RemoveChildShapeFromCompoundShapeIndex(BulletShape cShape, int indx);
  323. public abstract void RemoveChildShapeFromCompoundShape(BulletShape cShape, BulletShape removeShape);
  324. public abstract void UpdateChildTransform(BulletShape pShape, int childIndex, Vector3 pos, Quaternion rot, bool shouldRecalculateLocalAabb);
  325. public abstract void RecalculateCompoundShapeLocalAabb(BulletShape cShape);
  326. public abstract BulletShape DuplicateCollisionShape(BulletWorld sim, BulletShape srcShape, UInt32 id);
  327. public abstract bool DeleteCollisionShape(BulletWorld world, BulletShape shape);
  328. public abstract CollisionObjectTypes GetBodyType(BulletBody obj);
  329. public abstract BulletBody CreateBodyFromShape(BulletWorld sim, BulletShape shape, UInt32 id, Vector3 pos, Quaternion rot);
  330. public abstract BulletBody CreateBodyWithDefaultMotionState(BulletShape shape, UInt32 id, Vector3 pos, Quaternion rot);
  331. public abstract BulletBody CreateGhostFromShape(BulletWorld sim, BulletShape shape, UInt32 id, Vector3 pos, Quaternion rot);
  332. public abstract void DestroyObject(BulletWorld sim, BulletBody obj);
  333. // =====================================================================================
  334. public abstract BulletShape CreateGroundPlaneShape(UInt32 id, float height, float collisionMargin);
  335. public abstract BulletShape CreateTerrainShape(UInt32 id, Vector3 size, float minHeight, float maxHeight, float[] heightMap,
  336. float scaleFactor, float collisionMargin);
  337. // =====================================================================================
  338. // Constraint creation and helper routines
  339. public abstract BulletConstraint Create6DofConstraint(BulletWorld world, BulletBody obj1, BulletBody obj2,
  340. Vector3 frame1loc, Quaternion frame1rot,
  341. Vector3 frame2loc, Quaternion frame2rot,
  342. bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies);
  343. public abstract BulletConstraint Create6DofConstraintToPoint(BulletWorld world, BulletBody obj1, BulletBody obj2,
  344. Vector3 joinPoint,
  345. bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies);
  346. public abstract BulletConstraint Create6DofConstraintFixed(BulletWorld world, BulletBody obj1,
  347. Vector3 frameInBloc, Quaternion frameInBrot,
  348. bool useLinearReferenceFrameB, bool disableCollisionsBetweenLinkedBodies);
  349. public abstract BulletConstraint Create6DofSpringConstraint(BulletWorld world, BulletBody obj1, BulletBody obj2,
  350. Vector3 frame1loc, Quaternion frame1rot,
  351. Vector3 frame2loc, Quaternion frame2rot,
  352. bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies);
  353. public abstract BulletConstraint CreateHingeConstraint(BulletWorld world, BulletBody obj1, BulletBody obj2,
  354. Vector3 pivotinA, Vector3 pivotinB,
  355. Vector3 axisInA, Vector3 axisInB,
  356. bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies);
  357. public abstract BulletConstraint CreateSliderConstraint(BulletWorld world, BulletBody obj1, BulletBody obj2,
  358. Vector3 frameInAloc, Quaternion frameInArot,
  359. Vector3 frameInBloc, Quaternion frameInBrot,
  360. bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies);
  361. public abstract BulletConstraint CreateConeTwistConstraint(BulletWorld world, BulletBody obj1, BulletBody obj2,
  362. Vector3 frameInAloc, Quaternion frameInArot,
  363. Vector3 frameInBloc, Quaternion frameInBrot,
  364. bool disableCollisionsBetweenLinkedBodies);
  365. public abstract BulletConstraint CreateGearConstraint(BulletWorld world, BulletBody obj1, BulletBody obj2,
  366. Vector3 axisInA, Vector3 axisInB,
  367. float ratio, bool disableCollisionsBetweenLinkedBodies);
  368. public abstract BulletConstraint CreatePoint2PointConstraint(BulletWorld world, BulletBody obj1, BulletBody obj2,
  369. Vector3 pivotInA, Vector3 pivotInB,
  370. bool disableCollisionsBetweenLinkedBodies);
  371. public abstract void SetConstraintEnable(BulletConstraint constrain, float numericTrueFalse);
  372. public abstract void SetConstraintNumSolverIterations(BulletConstraint constrain, float iterations);
  373. public abstract bool SetFrames(BulletConstraint constrain,
  374. Vector3 frameA, Quaternion frameArot, Vector3 frameB, Quaternion frameBrot);
  375. public abstract bool SetLinearLimits(BulletConstraint constrain, Vector3 low, Vector3 hi);
  376. public abstract bool SetAngularLimits(BulletConstraint constrain, Vector3 low, Vector3 hi);
  377. public abstract bool UseFrameOffset(BulletConstraint constrain, float enable);
  378. public abstract bool TranslationalLimitMotor(BulletConstraint constrain, float enable, float targetVel, float maxMotorForce);
  379. public abstract bool SetBreakingImpulseThreshold(BulletConstraint constrain, float threshold);
  380. public const int HINGE_NOT_SPECIFIED = -1;
  381. public abstract bool HingeSetLimits(BulletConstraint constrain, float low, float high, float softness, float bias, float relaxation);
  382. public abstract bool SpringEnable(BulletConstraint constrain, int index, float numericTrueFalse);
  383. public const int SPRING_NOT_SPECIFIED = -1;
  384. public abstract bool SpringSetEquilibriumPoint(BulletConstraint constrain, int index, float equilibriumPoint);
  385. public abstract bool SpringSetStiffness(BulletConstraint constrain, int index, float stiffnesss);
  386. public abstract bool SpringSetDamping(BulletConstraint constrain, int index, float damping);
  387. public const int SLIDER_LOWER_LIMIT = 0;
  388. public const int SLIDER_UPPER_LIMIT = 1;
  389. public const int SLIDER_LINEAR = 2;
  390. public const int SLIDER_ANGULAR = 3;
  391. public abstract bool SliderSetLimits(BulletConstraint constrain, int lowerUpper, int linAng, float val);
  392. public const int SLIDER_SET_SOFTNESS = 4;
  393. public const int SLIDER_SET_RESTITUTION = 5;
  394. public const int SLIDER_SET_DAMPING = 6;
  395. public const int SLIDER_SET_DIRECTION = 7;
  396. public const int SLIDER_SET_LIMIT = 8;
  397. public const int SLIDER_SET_ORTHO = 9;
  398. public abstract bool SliderSet(BulletConstraint constrain, int softRestDamp, int dirLimOrtho, int linAng, float val);
  399. public abstract bool SliderMotorEnable(BulletConstraint constrain, int linAng, float numericTrueFalse);
  400. public const int SLIDER_MOTOR_VELOCITY = 10;
  401. public const int SLIDER_MAX_MOTOR_FORCE = 11;
  402. public abstract bool SliderMotor(BulletConstraint constrain, int forceVel, int linAng, float val);
  403. public abstract bool CalculateTransforms(BulletConstraint constrain);
  404. public abstract bool SetConstraintParam(BulletConstraint constrain, ConstraintParams paramIndex, float value, ConstraintParamAxis axis);
  405. public abstract bool DestroyConstraint(BulletWorld world, BulletConstraint constrain);
  406. // =====================================================================================
  407. // btCollisionWorld entries
  408. public abstract void UpdateSingleAabb(BulletWorld world, BulletBody obj);
  409. public abstract void UpdateAabbs(BulletWorld world);
  410. public abstract bool GetForceUpdateAllAabbs(BulletWorld world);
  411. public abstract void SetForceUpdateAllAabbs(BulletWorld world, bool force);
  412. // =====================================================================================
  413. // btDynamicsWorld entries
  414. // public abstract bool AddObjectToWorld(BulletWorld world, BulletBody obj, Vector3 pos, Quaternion rot);
  415. public abstract bool AddObjectToWorld(BulletWorld world, BulletBody obj);
  416. public abstract bool RemoveObjectFromWorld(BulletWorld world, BulletBody obj);
  417. public abstract bool ClearCollisionProxyCache(BulletWorld world, BulletBody obj);
  418. public abstract bool AddConstraintToWorld(BulletWorld world, BulletConstraint constrain, bool disableCollisionsBetweenLinkedObjects);
  419. public abstract bool RemoveConstraintFromWorld(BulletWorld world, BulletConstraint constrain);
  420. // =====================================================================================
  421. // btCollisionObject entries
  422. public abstract Vector3 GetAnisotripicFriction(BulletConstraint constrain);
  423. public abstract Vector3 SetAnisotripicFriction(BulletConstraint constrain, Vector3 frict);
  424. public abstract bool HasAnisotripicFriction(BulletConstraint constrain);
  425. public abstract void SetContactProcessingThreshold(BulletBody obj, float val);
  426. public abstract float GetContactProcessingThreshold(BulletBody obj);
  427. public abstract bool IsStaticObject(BulletBody obj);
  428. public abstract bool IsKinematicObject(BulletBody obj);
  429. public abstract bool IsStaticOrKinematicObject(BulletBody obj);
  430. public abstract bool HasContactResponse(BulletBody obj);
  431. public abstract void SetCollisionShape(BulletWorld sim, BulletBody obj, BulletShape shape);
  432. public abstract BulletShape GetCollisionShape(BulletBody obj);
  433. public abstract int GetActivationState(BulletBody obj);
  434. public abstract void SetActivationState(BulletBody obj, int state);
  435. public abstract void SetDeactivationTime(BulletBody obj, float dtime);
  436. public abstract float GetDeactivationTime(BulletBody obj);
  437. public abstract void ForceActivationState(BulletBody obj, ActivationState state);
  438. public abstract void Activate(BulletBody obj, bool forceActivation);
  439. public abstract bool IsActive(BulletBody obj);
  440. public abstract void SetRestitution(BulletBody obj, float val);
  441. public abstract float GetRestitution(BulletBody obj);
  442. public abstract void SetFriction(BulletBody obj, float val);
  443. public abstract float GetFriction(BulletBody obj);
  444. public abstract Vector3 GetPosition(BulletBody obj);
  445. public abstract Quaternion GetOrientation(BulletBody obj);
  446. public abstract void SetTranslation(BulletBody obj, Vector3 position, Quaternion rotation);
  447. // public abstract IntPtr GetBroadphaseHandle(BulletBody obj);
  448. // public abstract void SetBroadphaseHandle(BulletBody obj, IntPtr handle);
  449. public abstract void SetInterpolationLinearVelocity(BulletBody obj, Vector3 vel);
  450. public abstract void SetInterpolationAngularVelocity(BulletBody obj, Vector3 vel);
  451. public abstract void SetInterpolationVelocity(BulletBody obj, Vector3 linearVel, Vector3 angularVel);
  452. public abstract float GetHitFraction(BulletBody obj);
  453. public abstract void SetHitFraction(BulletBody obj, float val);
  454. public abstract CollisionFlags GetCollisionFlags(BulletBody obj);
  455. public abstract CollisionFlags SetCollisionFlags(BulletBody obj, CollisionFlags flags);
  456. public abstract CollisionFlags AddToCollisionFlags(BulletBody obj, CollisionFlags flags);
  457. public abstract CollisionFlags RemoveFromCollisionFlags(BulletBody obj, CollisionFlags flags);
  458. public abstract float GetCcdMotionThreshold(BulletBody obj);
  459. public abstract void SetCcdMotionThreshold(BulletBody obj, float val);
  460. public abstract float GetCcdSweptSphereRadius(BulletBody obj);
  461. public abstract void SetCcdSweptSphereRadius(BulletBody obj, float val);
  462. public abstract IntPtr GetUserPointer(BulletBody obj);
  463. public abstract void SetUserPointer(BulletBody obj, IntPtr val);
  464. // =====================================================================================
  465. // btRigidBody entries
  466. public abstract void ApplyGravity(BulletBody obj);
  467. public abstract void SetGravity(BulletBody obj, Vector3 val);
  468. public abstract Vector3 GetGravity(BulletBody obj);
  469. public abstract void SetDamping(BulletBody obj, float lin_damping, float ang_damping);
  470. public abstract void SetLinearDamping(BulletBody obj, float lin_damping);
  471. public abstract void SetAngularDamping(BulletBody obj, float ang_damping);
  472. public abstract float GetLinearDamping(BulletBody obj);
  473. public abstract float GetAngularDamping(BulletBody obj);
  474. public abstract float GetLinearSleepingThreshold(BulletBody obj);
  475. public abstract void ApplyDamping(BulletBody obj, float timeStep);
  476. public abstract void SetMassProps(BulletBody obj, float mass, Vector3 inertia);
  477. public abstract Vector3 GetLinearFactor(BulletBody obj);
  478. public abstract void SetLinearFactor(BulletBody obj, Vector3 factor);
  479. public abstract void SetCenterOfMassByPosRot(BulletBody obj, Vector3 pos, Quaternion rot);
  480. // Add a force to the object as if its mass is one.
  481. public abstract void ApplyCentralForce(BulletBody obj, Vector3 force);
  482. // Set the force being applied to the object as if its mass is one.
  483. public abstract void SetObjectForce(BulletBody obj, Vector3 force);
  484. public abstract Vector3 GetTotalForce(BulletBody obj);
  485. public abstract Vector3 GetTotalTorque(BulletBody obj);
  486. public abstract Vector3 GetInvInertiaDiagLocal(BulletBody obj);
  487. public abstract void SetInvInertiaDiagLocal(BulletBody obj, Vector3 inert);
  488. public abstract void SetSleepingThresholds(BulletBody obj, float lin_threshold, float ang_threshold);
  489. public abstract void ApplyTorque(BulletBody obj, Vector3 torque);
  490. // Apply force at the given point. Will add torque to the object.
  491. public abstract void ApplyForce(BulletBody obj, Vector3 force, Vector3 pos);
  492. // Apply impulse to the object. Same as "ApplycentralForce" but force scaled by object's mass.
  493. public abstract void ApplyCentralImpulse(BulletBody obj, Vector3 imp);
  494. // Apply impulse to the object's torque. Force is scaled by object's mass.
  495. public abstract void ApplyTorqueImpulse(BulletBody obj, Vector3 imp);
  496. // Apply impulse at the point given. For is scaled by object's mass and effects both linear and angular forces.
  497. public abstract void ApplyImpulse(BulletBody obj, Vector3 imp, Vector3 pos);
  498. public abstract void ClearForces(BulletBody obj);
  499. public abstract void ClearAllForces(BulletBody obj);
  500. public abstract void UpdateInertiaTensor(BulletBody obj);
  501. public abstract Vector3 GetLinearVelocity(BulletBody obj);
  502. public abstract Vector3 GetAngularVelocity(BulletBody obj);
  503. public abstract void SetLinearVelocity(BulletBody obj, Vector3 val);
  504. public abstract void SetAngularVelocity(BulletBody obj, Vector3 angularVelocity);
  505. public abstract Vector3 GetVelocityInLocalPoint(BulletBody obj, Vector3 pos);
  506. public abstract void Translate(BulletBody obj, Vector3 trans);
  507. public abstract void UpdateDeactivation(BulletBody obj, float timeStep);
  508. public abstract bool WantsSleeping(BulletBody obj);
  509. public abstract void SetAngularFactor(BulletBody obj, float factor);
  510. public abstract void SetAngularFactorV(BulletBody obj, Vector3 factor);
  511. public abstract Vector3 GetAngularFactor(BulletBody obj);
  512. public abstract bool IsInWorld(BulletWorld world, BulletBody obj);
  513. public abstract void AddConstraintRef(BulletBody obj, BulletConstraint constrain);
  514. public abstract void RemoveConstraintRef(BulletBody obj, BulletConstraint constrain);
  515. public abstract BulletConstraint GetConstraintRef(BulletBody obj, int index);
  516. public abstract int GetNumConstraintRefs(BulletBody obj);
  517. public abstract bool SetCollisionGroupMask(BulletBody body, UInt32 filter, UInt32 mask);
  518. // =====================================================================================
  519. // btCollisionShape entries
  520. public abstract float GetAngularMotionDisc(BulletShape shape);
  521. public abstract float GetContactBreakingThreshold(BulletShape shape, float defaultFactor);
  522. public abstract bool IsPolyhedral(BulletShape shape);
  523. public abstract bool IsConvex2d(BulletShape shape);
  524. public abstract bool IsConvex(BulletShape shape);
  525. public abstract bool IsNonMoving(BulletShape shape);
  526. public abstract bool IsConcave(BulletShape shape);
  527. public abstract bool IsCompound(BulletShape shape);
  528. public abstract bool IsSoftBody(BulletShape shape);
  529. public abstract bool IsInfinite(BulletShape shape);
  530. public abstract void SetLocalScaling(BulletShape shape, Vector3 scale);
  531. public abstract Vector3 GetLocalScaling(BulletShape shape);
  532. public abstract Vector3 CalculateLocalInertia(BulletShape shape, float mass);
  533. public abstract int GetShapeType(BulletShape shape);
  534. public abstract void SetMargin(BulletShape shape, float val);
  535. public abstract float GetMargin(BulletShape shape);
  536. // =====================================================================================
  537. // Debugging
  538. public virtual void DumpRigidBody(BulletWorld sim, BulletBody collisionObject) { }
  539. public virtual void DumpCollisionShape(BulletWorld sim, BulletShape collisionShape) { }
  540. public virtual void DumpConstraint(BulletWorld sim, BulletConstraint constrain) { }
  541. public virtual void DumpActivationInfo(BulletWorld sim) { }
  542. public virtual void DumpAllInfo(BulletWorld sim) { }
  543. public virtual void DumpPhysicsStatistics(BulletWorld sim) { }
  544. public virtual void ResetBroadphasePool(BulletWorld sim) { }
  545. public virtual void ResetConstraintSolver(BulletWorld sim) { }
  546. };
  547. }