BSApiTemplate.cs 36 KB

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