BSApiTemplate.cs 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763
  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.PhysicsModule.BulletS {
  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. // VHACD
  203. public float whichHACD; // zero if Bullet HACD, non-zero says VHACD
  204. // http://kmamou.blogspot.ca/2014/12/v-hacd-20-parameters-description.html
  205. public float vHACDresolution; // 100,000 max number of voxels generated during voxelization stage
  206. public float vHACDdepth; // 20 max number of clipping stages
  207. public float vHACDconcavity; // 0.0025 maximum concavity
  208. public float vHACDplaneDownsampling; // 4 granularity of search for best clipping plane
  209. public float vHACDconvexHullDownsampling; // 4 precision of hull gen process
  210. public float vHACDalpha; // 0.05 bias toward clipping along symmetry planes
  211. public float vHACDbeta; // 0.05 bias toward clipping along revolution axis
  212. public float vHACDgamma; // 0.00125 max concavity when merging
  213. public float vHACDpca; // 0 on/off normalizing mesh before decomp
  214. public float vHACDmode; // 0 0:voxel based, 1: tetrahedron based
  215. public float vHACDmaxNumVerticesPerCH; // 64 max triangles per convex hull
  216. public float vHACDminVolumePerCH; // 0.0001 sampling of generated convex hulls
  217. }
  218. // The states a bullet collision object can have
  219. public enum ActivationState : uint
  220. {
  221. ACTIVE_TAG = 1,
  222. ISLAND_SLEEPING,
  223. WANTS_DEACTIVATION,
  224. DISABLE_DEACTIVATION,
  225. DISABLE_SIMULATION,
  226. }
  227. public enum CollisionObjectTypes : int
  228. {
  229. CO_COLLISION_OBJECT = 1 << 0,
  230. CO_RIGID_BODY = 1 << 1,
  231. CO_GHOST_OBJECT = 1 << 2,
  232. CO_SOFT_BODY = 1 << 3,
  233. CO_HF_FLUID = 1 << 4,
  234. CO_USER_TYPE = 1 << 5,
  235. }
  236. // Values used by Bullet and BulletSim to control object properties.
  237. // Bullet's "CollisionFlags" has more to do with operations on the
  238. // object (if collisions happen, if gravity effects it, ...).
  239. public enum CollisionFlags : uint
  240. {
  241. CF_STATIC_OBJECT = 1 << 0,
  242. CF_KINEMATIC_OBJECT = 1 << 1,
  243. CF_NO_CONTACT_RESPONSE = 1 << 2,
  244. CF_CUSTOM_MATERIAL_CALLBACK = 1 << 3,
  245. CF_CHARACTER_OBJECT = 1 << 4,
  246. CF_DISABLE_VISUALIZE_OBJECT = 1 << 5,
  247. CF_DISABLE_SPU_COLLISION_PROCESS = 1 << 6,
  248. // Following used by BulletSim to control collisions and updates
  249. BS_SUBSCRIBE_COLLISION_EVENTS = 1 << 10, // return collision events from unmanaged to managed
  250. BS_FLOATS_ON_WATER = 1 << 11, // the object should float at water level
  251. BS_VEHICLE_COLLISIONS = 1 << 12, // return collisions for vehicle ground checking
  252. BS_RETURN_ROOT_COMPOUND_SHAPE = 1 << 13, // return the pos/rot of the root shape in a compound shape
  253. BS_NONE = 0,
  254. BS_ALL = 0x7FFF // collision flags are a signed short
  255. };
  256. // Values f collisions groups and masks
  257. public enum CollisionFilterGroups : uint
  258. {
  259. // Don't use the bit definitions!! Define the use in a
  260. // filter/mask definition below. This way collision interactions
  261. // are more easily found and debugged.
  262. BNoneGroup = 0,
  263. BDefaultGroup = 1 << 0, // 0001
  264. BStaticGroup = 1 << 1, // 0002
  265. BKinematicGroup = 1 << 2, // 0004
  266. BDebrisGroup = 1 << 3, // 0008
  267. BSensorTrigger = 1 << 4, // 0010
  268. BCharacterGroup = 1 << 5, // 0020
  269. BAllGroup = 0x0007FFF, // collision flags are a signed short
  270. // Filter groups defined by BulletSim
  271. BGroundPlaneGroup = 1 << 8, // 0400
  272. BTerrainGroup = 1 << 9, // 0800
  273. BRaycastGroup = 1 << 10, // 1000
  274. BSolidGroup = 1 << 11, // 2000
  275. // BLinksetGroup = xx // a linkset proper is either static or dynamic
  276. BLinksetChildGroup = 1 << 12, // 4000
  277. };
  278. // CFM controls the 'hardness' of the constraint. 0=fixed, 0..1=violatable. Default=0
  279. // ERP controls amount of correction per tick. Usable range=0.1..0.8. Default=0.2.
  280. public enum ConstraintParams : int
  281. {
  282. BT_CONSTRAINT_ERP = 1, // this one is not used in Bullet as of 20120730
  283. BT_CONSTRAINT_STOP_ERP,
  284. BT_CONSTRAINT_CFM,
  285. BT_CONSTRAINT_STOP_CFM,
  286. };
  287. public enum ConstraintParamAxis : int
  288. {
  289. AXIS_LINEAR_X = 0,
  290. AXIS_LINEAR_Y,
  291. AXIS_LINEAR_Z,
  292. AXIS_ANGULAR_X,
  293. AXIS_ANGULAR_Y,
  294. AXIS_ANGULAR_Z,
  295. AXIS_LINEAR_ALL = 20, // added by BulletSim so we don't have to do zillions of calls
  296. AXIS_ANGULAR_ALL,
  297. AXIS_ALL
  298. };
  299. public abstract class BSAPITemplate
  300. {
  301. // Returns the name of the underlying Bullet engine
  302. public abstract string BulletEngineName { get; }
  303. public abstract string BulletEngineVersion { get; protected set;}
  304. // Initialization and simulation
  305. public abstract BulletWorld Initialize(Vector3 maxPosition, ConfigurationParameters parms,
  306. int maxCollisions, ref CollisionDesc[] collisionArray,
  307. int maxUpdates, ref EntityProperties[] updateArray
  308. );
  309. public abstract int PhysicsStep(BulletWorld world, float timeStep, int maxSubSteps, float fixedTimeStep,
  310. out int updatedEntityCount, out int collidersCount);
  311. public abstract bool UpdateParameter(BulletWorld world, UInt32 localID, String parm, float value);
  312. public abstract void Shutdown(BulletWorld sim);
  313. public abstract bool PushUpdate(BulletBody obj);
  314. // =====================================================================================
  315. // Mesh, hull, shape and body creation helper routines
  316. public abstract BulletShape CreateMeshShape(BulletWorld world,
  317. int indicesCount, int[] indices,
  318. int verticesCount, float[] vertices );
  319. public abstract BulletShape CreateGImpactShape(BulletWorld world,
  320. int indicesCount, int[] indices,
  321. int verticesCount, float[] vertices );
  322. public abstract BulletShape CreateHullShape(BulletWorld world,
  323. int hullCount, float[] hulls);
  324. public abstract BulletShape BuildHullShapeFromMesh(BulletWorld world, BulletShape meshShape, HACDParams parms);
  325. public abstract BulletShape BuildConvexHullShapeFromMesh(BulletWorld world, BulletShape meshShape);
  326. public abstract BulletShape CreateConvexHullShape(BulletWorld world,
  327. int indicesCount, int[] indices,
  328. int verticesCount, float[] vertices );
  329. public abstract BulletShape BuildNativeShape(BulletWorld world, ShapeData shapeData);
  330. public abstract bool IsNativeShape(BulletShape shape);
  331. public abstract void SetShapeCollisionMargin(BulletShape shape, float margin);
  332. public abstract BulletShape BuildCapsuleShape(BulletWorld world, float radius, float height, Vector3 scale);
  333. public abstract BulletShape CreateCompoundShape(BulletWorld sim, bool enableDynamicAabbTree);
  334. public abstract int GetNumberOfCompoundChildren(BulletShape cShape);
  335. public abstract void AddChildShapeToCompoundShape(BulletShape cShape, BulletShape addShape, Vector3 pos, Quaternion rot);
  336. public abstract BulletShape GetChildShapeFromCompoundShapeIndex(BulletShape cShape, int indx);
  337. public abstract BulletShape RemoveChildShapeFromCompoundShapeIndex(BulletShape cShape, int indx);
  338. public abstract void RemoveChildShapeFromCompoundShape(BulletShape cShape, BulletShape removeShape);
  339. public abstract void UpdateChildTransform(BulletShape pShape, int childIndex, Vector3 pos, Quaternion rot, bool shouldRecalculateLocalAabb);
  340. public abstract void RecalculateCompoundShapeLocalAabb(BulletShape cShape);
  341. public abstract BulletShape DuplicateCollisionShape(BulletWorld sim, BulletShape srcShape, UInt32 id);
  342. public abstract bool DeleteCollisionShape(BulletWorld world, BulletShape shape);
  343. public abstract CollisionObjectTypes GetBodyType(BulletBody obj);
  344. public abstract BulletBody CreateBodyFromShape(BulletWorld sim, BulletShape shape, UInt32 id, Vector3 pos, Quaternion rot);
  345. public abstract BulletBody CreateBodyWithDefaultMotionState(BulletShape shape, UInt32 id, Vector3 pos, Quaternion rot);
  346. public abstract BulletBody CreateGhostFromShape(BulletWorld sim, BulletShape shape, UInt32 id, Vector3 pos, Quaternion rot);
  347. public abstract void DestroyObject(BulletWorld sim, BulletBody obj);
  348. // =====================================================================================
  349. public abstract BulletShape CreateGroundPlaneShape(UInt32 id, float height, float collisionMargin);
  350. public abstract BulletShape CreateTerrainShape(UInt32 id, Vector3 size, float minHeight, float maxHeight, float[] heightMap,
  351. float scaleFactor, float collisionMargin);
  352. // =====================================================================================
  353. // Constraint creation and helper routines
  354. public abstract BulletConstraint Create6DofConstraint(BulletWorld world, BulletBody obj1, BulletBody obj2,
  355. Vector3 frame1loc, Quaternion frame1rot,
  356. Vector3 frame2loc, Quaternion frame2rot,
  357. bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies);
  358. public abstract BulletConstraint Create6DofConstraintToPoint(BulletWorld world, BulletBody obj1, BulletBody obj2,
  359. Vector3 joinPoint,
  360. bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies);
  361. public abstract BulletConstraint Create6DofConstraintFixed(BulletWorld world, BulletBody obj1,
  362. Vector3 frameInBloc, Quaternion frameInBrot,
  363. bool useLinearReferenceFrameB, bool disableCollisionsBetweenLinkedBodies);
  364. public abstract BulletConstraint Create6DofSpringConstraint(BulletWorld world, BulletBody obj1, BulletBody obj2,
  365. Vector3 frame1loc, Quaternion frame1rot,
  366. Vector3 frame2loc, Quaternion frame2rot,
  367. bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies);
  368. public abstract BulletConstraint CreateHingeConstraint(BulletWorld world, BulletBody obj1, BulletBody obj2,
  369. Vector3 pivotinA, Vector3 pivotinB,
  370. Vector3 axisInA, Vector3 axisInB,
  371. bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies);
  372. public abstract BulletConstraint CreateSliderConstraint(BulletWorld world, BulletBody obj1, BulletBody obj2,
  373. Vector3 frameInAloc, Quaternion frameInArot,
  374. Vector3 frameInBloc, Quaternion frameInBrot,
  375. bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies);
  376. public abstract BulletConstraint CreateConeTwistConstraint(BulletWorld world, BulletBody obj1, BulletBody obj2,
  377. Vector3 frameInAloc, Quaternion frameInArot,
  378. Vector3 frameInBloc, Quaternion frameInBrot,
  379. bool disableCollisionsBetweenLinkedBodies);
  380. public abstract BulletConstraint CreateGearConstraint(BulletWorld world, BulletBody obj1, BulletBody obj2,
  381. Vector3 axisInA, Vector3 axisInB,
  382. float ratio, bool disableCollisionsBetweenLinkedBodies);
  383. public abstract BulletConstraint CreatePoint2PointConstraint(BulletWorld world, BulletBody obj1, BulletBody obj2,
  384. Vector3 pivotInA, Vector3 pivotInB,
  385. bool disableCollisionsBetweenLinkedBodies);
  386. public abstract void SetConstraintEnable(BulletConstraint constrain, float numericTrueFalse);
  387. public abstract void SetConstraintNumSolverIterations(BulletConstraint constrain, float iterations);
  388. public abstract bool SetFrames(BulletConstraint constrain,
  389. Vector3 frameA, Quaternion frameArot, Vector3 frameB, Quaternion frameBrot);
  390. public abstract bool SetLinearLimits(BulletConstraint constrain, Vector3 low, Vector3 hi);
  391. public abstract bool SetAngularLimits(BulletConstraint constrain, Vector3 low, Vector3 hi);
  392. public abstract bool UseFrameOffset(BulletConstraint constrain, float enable);
  393. public abstract bool TranslationalLimitMotor(BulletConstraint constrain, float enable, float targetVel, float maxMotorForce);
  394. public abstract bool SetBreakingImpulseThreshold(BulletConstraint constrain, float threshold);
  395. public const int HINGE_NOT_SPECIFIED = -1;
  396. public abstract bool HingeSetLimits(BulletConstraint constrain, float low, float high, float softness, float bias, float relaxation);
  397. public abstract bool SpringEnable(BulletConstraint constrain, int index, float numericTrueFalse);
  398. public const int SPRING_NOT_SPECIFIED = -1;
  399. public abstract bool SpringSetEquilibriumPoint(BulletConstraint constrain, int index, float equilibriumPoint);
  400. public abstract bool SpringSetStiffness(BulletConstraint constrain, int index, float stiffnesss);
  401. public abstract bool SpringSetDamping(BulletConstraint constrain, int index, float damping);
  402. public const int SLIDER_LOWER_LIMIT = 0;
  403. public const int SLIDER_UPPER_LIMIT = 1;
  404. public const int SLIDER_LINEAR = 2;
  405. public const int SLIDER_ANGULAR = 3;
  406. public abstract bool SliderSetLimits(BulletConstraint constrain, int lowerUpper, int linAng, float val);
  407. public const int SLIDER_SET_SOFTNESS = 4;
  408. public const int SLIDER_SET_RESTITUTION = 5;
  409. public const int SLIDER_SET_DAMPING = 6;
  410. public const int SLIDER_SET_DIRECTION = 7;
  411. public const int SLIDER_SET_LIMIT = 8;
  412. public const int SLIDER_SET_ORTHO = 9;
  413. public abstract bool SliderSet(BulletConstraint constrain, int softRestDamp, int dirLimOrtho, int linAng, float val);
  414. public abstract bool SliderMotorEnable(BulletConstraint constrain, int linAng, float numericTrueFalse);
  415. public const int SLIDER_MOTOR_VELOCITY = 10;
  416. public const int SLIDER_MAX_MOTOR_FORCE = 11;
  417. public abstract bool SliderMotor(BulletConstraint constrain, int forceVel, int linAng, float val);
  418. public abstract bool CalculateTransforms(BulletConstraint constrain);
  419. public abstract bool SetConstraintParam(BulletConstraint constrain, ConstraintParams paramIndex, float value, ConstraintParamAxis axis);
  420. public abstract bool DestroyConstraint(BulletWorld world, BulletConstraint constrain);
  421. // =====================================================================================
  422. // btCollisionWorld entries
  423. public abstract void UpdateSingleAabb(BulletWorld world, BulletBody obj);
  424. public abstract void UpdateAabbs(BulletWorld world);
  425. public abstract bool GetForceUpdateAllAabbs(BulletWorld world);
  426. public abstract void SetForceUpdateAllAabbs(BulletWorld world, bool force);
  427. // =====================================================================================
  428. // btDynamicsWorld entries
  429. // public abstract bool AddObjectToWorld(BulletWorld world, BulletBody obj, Vector3 pos, Quaternion rot);
  430. public abstract bool AddObjectToWorld(BulletWorld world, BulletBody obj);
  431. public abstract bool RemoveObjectFromWorld(BulletWorld world, BulletBody obj);
  432. public abstract bool ClearCollisionProxyCache(BulletWorld world, BulletBody obj);
  433. public abstract bool AddConstraintToWorld(BulletWorld world, BulletConstraint constrain, bool disableCollisionsBetweenLinkedObjects);
  434. public abstract bool RemoveConstraintFromWorld(BulletWorld world, BulletConstraint constrain);
  435. // =====================================================================================
  436. // btCollisionObject entries
  437. public abstract Vector3 GetAnisotripicFriction(BulletConstraint constrain);
  438. public abstract Vector3 SetAnisotripicFriction(BulletConstraint constrain, Vector3 frict);
  439. public abstract bool HasAnisotripicFriction(BulletConstraint constrain);
  440. public abstract void SetContactProcessingThreshold(BulletBody obj, float val);
  441. public abstract float GetContactProcessingThreshold(BulletBody obj);
  442. public abstract bool IsStaticObject(BulletBody obj);
  443. public abstract bool IsKinematicObject(BulletBody obj);
  444. public abstract bool IsStaticOrKinematicObject(BulletBody obj);
  445. public abstract bool HasContactResponse(BulletBody obj);
  446. public abstract void SetCollisionShape(BulletWorld sim, BulletBody obj, BulletShape shape);
  447. public abstract BulletShape GetCollisionShape(BulletBody obj);
  448. public abstract int GetActivationState(BulletBody obj);
  449. public abstract void SetActivationState(BulletBody obj, int state);
  450. public abstract void SetDeactivationTime(BulletBody obj, float dtime);
  451. public abstract float GetDeactivationTime(BulletBody obj);
  452. public abstract void ForceActivationState(BulletBody obj, ActivationState state);
  453. public abstract void Activate(BulletBody obj, bool forceActivation);
  454. public abstract bool IsActive(BulletBody obj);
  455. public abstract void SetRestitution(BulletBody obj, float val);
  456. public abstract float GetRestitution(BulletBody obj);
  457. public abstract void SetFriction(BulletBody obj, float val);
  458. public abstract float GetFriction(BulletBody obj);
  459. public abstract Vector3 GetPosition(BulletBody obj);
  460. public abstract Quaternion GetOrientation(BulletBody obj);
  461. public abstract void SetTranslation(BulletBody obj, Vector3 position, Quaternion rotation);
  462. // public abstract IntPtr GetBroadphaseHandle(BulletBody obj);
  463. // public abstract void SetBroadphaseHandle(BulletBody obj, IntPtr handle);
  464. public abstract void SetInterpolationLinearVelocity(BulletBody obj, Vector3 vel);
  465. public abstract void SetInterpolationAngularVelocity(BulletBody obj, Vector3 vel);
  466. public abstract void SetInterpolationVelocity(BulletBody obj, Vector3 linearVel, Vector3 angularVel);
  467. public abstract float GetHitFraction(BulletBody obj);
  468. public abstract void SetHitFraction(BulletBody obj, float val);
  469. public abstract CollisionFlags GetCollisionFlags(BulletBody obj);
  470. public abstract CollisionFlags SetCollisionFlags(BulletBody obj, CollisionFlags flags);
  471. public abstract CollisionFlags AddToCollisionFlags(BulletBody obj, CollisionFlags flags);
  472. public abstract CollisionFlags RemoveFromCollisionFlags(BulletBody obj, CollisionFlags flags);
  473. public abstract float GetCcdMotionThreshold(BulletBody obj);
  474. public abstract void SetCcdMotionThreshold(BulletBody obj, float val);
  475. public abstract float GetCcdSweptSphereRadius(BulletBody obj);
  476. public abstract void SetCcdSweptSphereRadius(BulletBody obj, float val);
  477. public abstract IntPtr GetUserPointer(BulletBody obj);
  478. public abstract void SetUserPointer(BulletBody obj, IntPtr val);
  479. // =====================================================================================
  480. // btRigidBody entries
  481. public abstract void ApplyGravity(BulletBody obj);
  482. public abstract void SetGravity(BulletBody obj, Vector3 val);
  483. public abstract Vector3 GetGravity(BulletBody obj);
  484. public abstract void SetDamping(BulletBody obj, float lin_damping, float ang_damping);
  485. public abstract void SetLinearDamping(BulletBody obj, float lin_damping);
  486. public abstract void SetAngularDamping(BulletBody obj, float ang_damping);
  487. public abstract float GetLinearDamping(BulletBody obj);
  488. public abstract float GetAngularDamping(BulletBody obj);
  489. public abstract float GetLinearSleepingThreshold(BulletBody obj);
  490. public abstract void ApplyDamping(BulletBody obj, float timeStep);
  491. public abstract void SetMassProps(BulletBody obj, float mass, Vector3 inertia);
  492. public abstract Vector3 GetLinearFactor(BulletBody obj);
  493. public abstract void SetLinearFactor(BulletBody obj, Vector3 factor);
  494. public abstract void SetCenterOfMassByPosRot(BulletBody obj, Vector3 pos, Quaternion rot);
  495. // Add a force to the object as if its mass is one.
  496. public abstract void ApplyCentralForce(BulletBody obj, Vector3 force);
  497. // Set the force being applied to the object as if its mass is one.
  498. public abstract void SetObjectForce(BulletBody obj, Vector3 force);
  499. public abstract Vector3 GetTotalForce(BulletBody obj);
  500. public abstract Vector3 GetTotalTorque(BulletBody obj);
  501. public abstract Vector3 GetInvInertiaDiagLocal(BulletBody obj);
  502. public abstract void SetInvInertiaDiagLocal(BulletBody obj, Vector3 inert);
  503. public abstract void SetSleepingThresholds(BulletBody obj, float lin_threshold, float ang_threshold);
  504. public abstract void ApplyTorque(BulletBody obj, Vector3 torque);
  505. // Apply force at the given point. Will add torque to the object.
  506. public abstract void ApplyForce(BulletBody obj, Vector3 force, Vector3 pos);
  507. // Apply impulse to the object. Same as "ApplycentralForce" but force scaled by object's mass.
  508. public abstract void ApplyCentralImpulse(BulletBody obj, Vector3 imp);
  509. // Apply impulse to the object's torque. Force is scaled by object's mass.
  510. public abstract void ApplyTorqueImpulse(BulletBody obj, Vector3 imp);
  511. // Apply impulse at the point given. For is scaled by object's mass and effects both linear and angular forces.
  512. public abstract void ApplyImpulse(BulletBody obj, Vector3 imp, Vector3 pos);
  513. public abstract void ClearForces(BulletBody obj);
  514. public abstract void ClearAllForces(BulletBody obj);
  515. public abstract void UpdateInertiaTensor(BulletBody obj);
  516. public abstract Vector3 GetLinearVelocity(BulletBody obj);
  517. public abstract Vector3 GetAngularVelocity(BulletBody obj);
  518. public abstract void SetLinearVelocity(BulletBody obj, Vector3 val);
  519. public abstract void SetAngularVelocity(BulletBody obj, Vector3 angularVelocity);
  520. public abstract Vector3 GetVelocityInLocalPoint(BulletBody obj, Vector3 pos);
  521. public abstract void Translate(BulletBody obj, Vector3 trans);
  522. public abstract void UpdateDeactivation(BulletBody obj, float timeStep);
  523. public abstract bool WantsSleeping(BulletBody obj);
  524. public abstract void SetAngularFactor(BulletBody obj, float factor);
  525. public abstract void SetAngularFactorV(BulletBody obj, Vector3 factor);
  526. public abstract Vector3 GetAngularFactor(BulletBody obj);
  527. public abstract bool IsInWorld(BulletWorld world, BulletBody obj);
  528. public abstract void AddConstraintRef(BulletBody obj, BulletConstraint constrain);
  529. public abstract void RemoveConstraintRef(BulletBody obj, BulletConstraint constrain);
  530. public abstract BulletConstraint GetConstraintRef(BulletBody obj, int index);
  531. public abstract int GetNumConstraintRefs(BulletBody obj);
  532. public abstract bool SetCollisionGroupMask(BulletBody body, UInt32 filter, UInt32 mask);
  533. // =====================================================================================
  534. // btCollisionShape entries
  535. public abstract float GetAngularMotionDisc(BulletShape shape);
  536. public abstract float GetContactBreakingThreshold(BulletShape shape, float defaultFactor);
  537. public abstract bool IsPolyhedral(BulletShape shape);
  538. public abstract bool IsConvex2d(BulletShape shape);
  539. public abstract bool IsConvex(BulletShape shape);
  540. public abstract bool IsNonMoving(BulletShape shape);
  541. public abstract bool IsConcave(BulletShape shape);
  542. public abstract bool IsCompound(BulletShape shape);
  543. public abstract bool IsSoftBody(BulletShape shape);
  544. public abstract bool IsInfinite(BulletShape shape);
  545. public abstract void SetLocalScaling(BulletShape shape, Vector3 scale);
  546. public abstract Vector3 GetLocalScaling(BulletShape shape);
  547. public abstract Vector3 CalculateLocalInertia(BulletShape shape, float mass);
  548. public abstract int GetShapeType(BulletShape shape);
  549. public abstract void SetMargin(BulletShape shape, float val);
  550. public abstract float GetMargin(BulletShape shape);
  551. // =====================================================================================
  552. // Debugging
  553. public virtual void DumpRigidBody(BulletWorld sim, BulletBody collisionObject) { }
  554. public virtual void DumpCollisionShape(BulletWorld sim, BulletShape collisionShape) { }
  555. public virtual void DumpConstraint(BulletWorld sim, BulletConstraint constrain) { }
  556. public virtual void DumpActivationInfo(BulletWorld sim) { }
  557. public virtual void DumpAllInfo(BulletWorld sim) { }
  558. public virtual void DumpPhysicsStatistics(BulletWorld sim) { }
  559. public virtual void ResetBroadphasePool(BulletWorld sim) { }
  560. public virtual void ResetConstraintSolver(BulletWorld sim) { }
  561. };
  562. }