BSAPIUnman.cs 91 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyrightD
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSimulator Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System;
  28. using System.Collections.Generic;
  29. using System.Reflection;
  30. using System.Runtime.InteropServices;
  31. using System.Security;
  32. using System.Text;
  33. using OpenSim.Framework;
  34. using OpenMetaverse;
  35. namespace OpenSim.Region.Physics.BulletSPlugin
  36. {
  37. public sealed class BSAPIUnman : BSAPITemplate
  38. {
  39. private sealed class BulletWorldUnman : BulletWorld
  40. {
  41. public IntPtr ptr;
  42. public BulletWorldUnman(uint id, BSScene physScene, IntPtr xx)
  43. : base(id, physScene)
  44. {
  45. ptr = xx;
  46. }
  47. }
  48. private sealed class BulletBodyUnman : BulletBody
  49. {
  50. public IntPtr ptr;
  51. public BulletBodyUnman(uint id, IntPtr xx)
  52. : base(id)
  53. {
  54. ptr = xx;
  55. }
  56. public override bool HasPhysicalBody
  57. {
  58. get { return ptr != IntPtr.Zero; }
  59. }
  60. public override void Clear()
  61. {
  62. ptr = IntPtr.Zero;
  63. }
  64. public override string AddrString
  65. {
  66. get { return ptr.ToString("X"); }
  67. }
  68. }
  69. private sealed class BulletShapeUnman : BulletShape
  70. {
  71. public IntPtr ptr;
  72. public BulletShapeUnman(IntPtr xx, BSPhysicsShapeType typ)
  73. : base()
  74. {
  75. ptr = xx;
  76. shapeType = typ;
  77. }
  78. public override bool HasPhysicalShape
  79. {
  80. get { return ptr != IntPtr.Zero; }
  81. }
  82. public override void Clear()
  83. {
  84. ptr = IntPtr.Zero;
  85. }
  86. public override BulletShape Clone()
  87. {
  88. return new BulletShapeUnman(ptr, shapeType);
  89. }
  90. public override bool ReferenceSame(BulletShape other)
  91. {
  92. BulletShapeUnman otheru = other as BulletShapeUnman;
  93. return (otheru != null) && (this.ptr == otheru.ptr);
  94. }
  95. public override string AddrString
  96. {
  97. get { return ptr.ToString("X"); }
  98. }
  99. }
  100. private sealed class BulletConstraintUnman : BulletConstraint
  101. {
  102. public BulletConstraintUnman(IntPtr xx) : base()
  103. {
  104. ptr = xx;
  105. }
  106. public IntPtr ptr;
  107. public override void Clear()
  108. {
  109. ptr = IntPtr.Zero;
  110. }
  111. public override bool HasPhysicalConstraint { get { return ptr != IntPtr.Zero; } }
  112. // Used for log messages for a unique display of the memory/object allocated to this instance
  113. public override string AddrString
  114. {
  115. get { return ptr.ToString("X"); }
  116. }
  117. }
  118. // We pin the memory passed between the managed and unmanaged code.
  119. GCHandle m_paramsHandle;
  120. private GCHandle m_collisionArrayPinnedHandle;
  121. private GCHandle m_updateArrayPinnedHandle;
  122. // Handle to the callback used by the unmanaged code to call into the managed code.
  123. // Used for debug logging.
  124. // Need to store the handle in a persistant variable so it won't be freed.
  125. private BSAPICPP.DebugLogCallback m_DebugLogCallbackHandle;
  126. private BSScene PhysicsScene { get; set; }
  127. public override string BulletEngineName { get { return "BulletUnmanaged"; } }
  128. public override string BulletEngineVersion { get; protected set; }
  129. public BSAPIUnman(string paramName, BSScene physScene)
  130. {
  131. PhysicsScene = physScene;
  132. // Do something fancy with the paramName to get the right DLL implementation
  133. // like "Bullet-2.80-OpenCL-Intel" loading the version for Intel based OpenCL implementation, etc.
  134. if (Util.IsWindows())
  135. Util.LoadArchSpecificWindowsDll("BulletSim.dll");
  136. // If not Windows, loading is performed by the
  137. // Mono loader as specified in
  138. // "bin/Physics/OpenSim.Region.Physics.BulletSPlugin.dll.config".
  139. }
  140. // Initialization and simulation
  141. public override BulletWorld Initialize(Vector3 maxPosition, ConfigurationParameters parms,
  142. int maxCollisions, ref CollisionDesc[] collisionArray,
  143. int maxUpdates, ref EntityProperties[] updateArray
  144. )
  145. {
  146. // Pin down the memory that will be used to pass object collisions and updates back from unmanaged code
  147. m_paramsHandle = GCHandle.Alloc(parms, GCHandleType.Pinned);
  148. m_collisionArrayPinnedHandle = GCHandle.Alloc(collisionArray, GCHandleType.Pinned);
  149. m_updateArrayPinnedHandle = GCHandle.Alloc(updateArray, GCHandleType.Pinned);
  150. // If Debug logging level, enable logging from the unmanaged code
  151. m_DebugLogCallbackHandle = null;
  152. if (BSScene.m_log.IsDebugEnabled && PhysicsScene.PhysicsLogging.Enabled)
  153. {
  154. BSScene.m_log.DebugFormat("{0}: Initialize: Setting debug callback for unmanaged code", BSScene.LogHeader);
  155. if (PhysicsScene.PhysicsLogging.Enabled)
  156. // The handle is saved in a variable to make sure it doesn't get freed after this call
  157. m_DebugLogCallbackHandle = new BSAPICPP.DebugLogCallback(BulletLoggerPhysLog);
  158. else
  159. m_DebugLogCallbackHandle = new BSAPICPP.DebugLogCallback(BulletLogger);
  160. }
  161. // Get the version of the DLL
  162. // TODO: this doesn't work yet. Something wrong with marshaling the returned string.
  163. // BulletEngineVersion = BulletSimAPI.GetVersion2();
  164. BulletEngineVersion = "";
  165. // Call the unmanaged code with the buffers and other information
  166. return new BulletWorldUnman(0, PhysicsScene, BSAPICPP.Initialize2(maxPosition, m_paramsHandle.AddrOfPinnedObject(),
  167. maxCollisions, m_collisionArrayPinnedHandle.AddrOfPinnedObject(),
  168. maxUpdates, m_updateArrayPinnedHandle.AddrOfPinnedObject(),
  169. m_DebugLogCallbackHandle));
  170. }
  171. // Called directly from unmanaged code so don't do much
  172. private void BulletLogger(string msg)
  173. {
  174. BSScene.m_log.Debug("[BULLETS UNMANAGED]:" + msg);
  175. }
  176. // Called directly from unmanaged code so don't do much
  177. private void BulletLoggerPhysLog(string msg)
  178. {
  179. PhysicsScene.DetailLog("[BULLETS UNMANAGED]:" + msg);
  180. }
  181. public override int PhysicsStep(BulletWorld world, float timeStep, int maxSubSteps, float fixedTimeStep,
  182. out int updatedEntityCount, out int collidersCount)
  183. {
  184. BulletWorldUnman worldu = world as BulletWorldUnman;
  185. return BSAPICPP.PhysicsStep2(worldu.ptr, timeStep, maxSubSteps, fixedTimeStep, out updatedEntityCount, out collidersCount);
  186. }
  187. public override void Shutdown(BulletWorld world)
  188. {
  189. BulletWorldUnman worldu = world as BulletWorldUnman;
  190. BSAPICPP.Shutdown2(worldu.ptr);
  191. if (m_paramsHandle.IsAllocated)
  192. {
  193. m_paramsHandle.Free();
  194. }
  195. if (m_collisionArrayPinnedHandle.IsAllocated)
  196. {
  197. m_collisionArrayPinnedHandle.Free();
  198. }
  199. if (m_updateArrayPinnedHandle.IsAllocated)
  200. {
  201. m_updateArrayPinnedHandle.Free();
  202. }
  203. }
  204. public override bool PushUpdate(BulletBody obj)
  205. {
  206. BulletBodyUnman bodyu = obj as BulletBodyUnman;
  207. return BSAPICPP.PushUpdate2(bodyu.ptr);
  208. }
  209. public override bool UpdateParameter(BulletWorld world, uint localID, String parm, float value)
  210. {
  211. BulletWorldUnman worldu = world as BulletWorldUnman;
  212. return BSAPICPP.UpdateParameter2(worldu.ptr, localID, parm, value);
  213. }
  214. // =====================================================================================
  215. // Mesh, hull, shape and body creation helper routines
  216. public override BulletShape CreateMeshShape(BulletWorld world,
  217. int indicesCount, int[] indices,
  218. int verticesCount, float[] vertices)
  219. {
  220. BulletWorldUnman worldu = world as BulletWorldUnman;
  221. return new BulletShapeUnman(
  222. BSAPICPP.CreateMeshShape2(worldu.ptr, indicesCount, indices, verticesCount, vertices),
  223. BSPhysicsShapeType.SHAPE_MESH);
  224. }
  225. public override BulletShape CreateGImpactShape(BulletWorld world,
  226. int indicesCount, int[] indices,
  227. int verticesCount, float[] vertices)
  228. {
  229. BulletWorldUnman worldu = world as BulletWorldUnman;
  230. return new BulletShapeUnman(
  231. BSAPICPP.CreateGImpactShape2(worldu.ptr, indicesCount, indices, verticesCount, vertices),
  232. BSPhysicsShapeType.SHAPE_GIMPACT);
  233. }
  234. public override BulletShape CreateHullShape(BulletWorld world, int hullCount, float[] hulls)
  235. {
  236. BulletWorldUnman worldu = world as BulletWorldUnman;
  237. return new BulletShapeUnman(
  238. BSAPICPP.CreateHullShape2(worldu.ptr, hullCount, hulls),
  239. BSPhysicsShapeType.SHAPE_HULL);
  240. }
  241. public override BulletShape BuildHullShapeFromMesh(BulletWorld world, BulletShape meshShape, HACDParams parms)
  242. {
  243. BulletWorldUnman worldu = world as BulletWorldUnman;
  244. BulletShapeUnman shapeu = meshShape as BulletShapeUnman;
  245. return new BulletShapeUnman(
  246. BSAPICPP.BuildHullShapeFromMesh2(worldu.ptr, shapeu.ptr, parms),
  247. BSPhysicsShapeType.SHAPE_HULL);
  248. }
  249. public override BulletShape BuildConvexHullShapeFromMesh(BulletWorld world, BulletShape meshShape)
  250. {
  251. BulletWorldUnman worldu = world as BulletWorldUnman;
  252. BulletShapeUnman shapeu = meshShape as BulletShapeUnman;
  253. return new BulletShapeUnman(
  254. BSAPICPP.BuildConvexHullShapeFromMesh2(worldu.ptr, shapeu.ptr),
  255. BSPhysicsShapeType.SHAPE_CONVEXHULL);
  256. }
  257. public override BulletShape CreateConvexHullShape(BulletWorld world,
  258. int indicesCount, int[] indices,
  259. int verticesCount, float[] vertices)
  260. {
  261. BulletWorldUnman worldu = world as BulletWorldUnman;
  262. return new BulletShapeUnman(
  263. BSAPICPP.CreateConvexHullShape2(worldu.ptr, indicesCount, indices, verticesCount, vertices),
  264. BSPhysicsShapeType.SHAPE_CONVEXHULL);
  265. }
  266. public override BulletShape BuildNativeShape(BulletWorld world, ShapeData shapeData)
  267. {
  268. BulletWorldUnman worldu = world as BulletWorldUnman;
  269. return new BulletShapeUnman(BSAPICPP.BuildNativeShape2(worldu.ptr, shapeData), shapeData.Type);
  270. }
  271. public override bool IsNativeShape(BulletShape shape)
  272. {
  273. BulletShapeUnman shapeu = shape as BulletShapeUnman;
  274. if (shapeu != null && shapeu.HasPhysicalShape)
  275. return BSAPICPP.IsNativeShape2(shapeu.ptr);
  276. return false;
  277. }
  278. public override void SetShapeCollisionMargin(BulletShape shape, float margin)
  279. {
  280. BulletShapeUnman shapeu = shape as BulletShapeUnman;
  281. if (shapeu != null && shapeu.HasPhysicalShape)
  282. BSAPICPP.SetShapeCollisionMargin(shapeu.ptr, margin);
  283. }
  284. public override BulletShape BuildCapsuleShape(BulletWorld world, float radius, float height, Vector3 scale)
  285. {
  286. BulletWorldUnman worldu = world as BulletWorldUnman;
  287. return new BulletShapeUnman(
  288. BSAPICPP.BuildCapsuleShape2(worldu.ptr, radius, height, scale),
  289. BSPhysicsShapeType.SHAPE_CAPSULE);
  290. }
  291. public override BulletShape CreateCompoundShape(BulletWorld world, bool enableDynamicAabbTree)
  292. {
  293. BulletWorldUnman worldu = world as BulletWorldUnman;
  294. return new BulletShapeUnman(
  295. BSAPICPP.CreateCompoundShape2(worldu.ptr, enableDynamicAabbTree),
  296. BSPhysicsShapeType.SHAPE_COMPOUND);
  297. }
  298. public override int GetNumberOfCompoundChildren(BulletShape shape)
  299. {
  300. BulletShapeUnman shapeu = shape as BulletShapeUnman;
  301. if (shapeu != null && shapeu.HasPhysicalShape)
  302. return BSAPICPP.GetNumberOfCompoundChildren2(shapeu.ptr);
  303. return 0;
  304. }
  305. public override void AddChildShapeToCompoundShape(BulletShape shape, BulletShape addShape, Vector3 pos, Quaternion rot)
  306. {
  307. BulletShapeUnman shapeu = shape as BulletShapeUnman;
  308. BulletShapeUnman addShapeu = addShape as BulletShapeUnman;
  309. BSAPICPP.AddChildShapeToCompoundShape2(shapeu.ptr, addShapeu.ptr, pos, rot);
  310. }
  311. public override BulletShape GetChildShapeFromCompoundShapeIndex(BulletShape shape, int indx)
  312. {
  313. BulletShapeUnman shapeu = shape as BulletShapeUnman;
  314. return new BulletShapeUnman(BSAPICPP.GetChildShapeFromCompoundShapeIndex2(shapeu.ptr, indx), BSPhysicsShapeType.SHAPE_UNKNOWN);
  315. }
  316. public override BulletShape RemoveChildShapeFromCompoundShapeIndex(BulletShape shape, int indx)
  317. {
  318. BulletShapeUnman shapeu = shape as BulletShapeUnman;
  319. return new BulletShapeUnman(BSAPICPP.RemoveChildShapeFromCompoundShapeIndex2(shapeu.ptr, indx), BSPhysicsShapeType.SHAPE_UNKNOWN);
  320. }
  321. public override void RemoveChildShapeFromCompoundShape(BulletShape shape, BulletShape removeShape)
  322. {
  323. BulletShapeUnman shapeu = shape as BulletShapeUnman;
  324. BulletShapeUnman removeShapeu = removeShape as BulletShapeUnman;
  325. BSAPICPP.RemoveChildShapeFromCompoundShape2(shapeu.ptr, removeShapeu.ptr);
  326. }
  327. public override void UpdateChildTransform(BulletShape pShape, int childIndex, Vector3 pos, Quaternion rot, bool shouldRecalculateLocalAabb)
  328. {
  329. BulletShapeUnman shapeu = pShape as BulletShapeUnman;
  330. BSAPICPP.UpdateChildTransform2(shapeu.ptr, childIndex, pos, rot, shouldRecalculateLocalAabb);
  331. }
  332. public override void RecalculateCompoundShapeLocalAabb(BulletShape shape)
  333. {
  334. BulletShapeUnman shapeu = shape as BulletShapeUnman;
  335. BSAPICPP.RecalculateCompoundShapeLocalAabb2(shapeu.ptr);
  336. }
  337. public override BulletShape DuplicateCollisionShape(BulletWorld world, BulletShape srcShape, uint id)
  338. {
  339. BulletWorldUnman worldu = world as BulletWorldUnman;
  340. BulletShapeUnman srcShapeu = srcShape as BulletShapeUnman;
  341. return new BulletShapeUnman(BSAPICPP.DuplicateCollisionShape2(worldu.ptr, srcShapeu.ptr, id), srcShape.shapeType);
  342. }
  343. public override bool DeleteCollisionShape(BulletWorld world, BulletShape shape)
  344. {
  345. BulletWorldUnman worldu = world as BulletWorldUnman;
  346. BulletShapeUnman shapeu = shape as BulletShapeUnman;
  347. return BSAPICPP.DeleteCollisionShape2(worldu.ptr, shapeu.ptr);
  348. }
  349. public override CollisionObjectTypes GetBodyType(BulletBody obj)
  350. {
  351. BulletBodyUnman bodyu = obj as BulletBodyUnman;
  352. return (CollisionObjectTypes)BSAPICPP.GetBodyType2(bodyu.ptr);
  353. }
  354. public override BulletBody CreateBodyFromShape(BulletWorld world, BulletShape shape, uint id, Vector3 pos, Quaternion rot)
  355. {
  356. BulletWorldUnman worldu = world as BulletWorldUnman;
  357. BulletShapeUnman shapeu = shape as BulletShapeUnman;
  358. return new BulletBodyUnman(id, BSAPICPP.CreateBodyFromShape2(worldu.ptr, shapeu.ptr, id, pos, rot));
  359. }
  360. public override BulletBody CreateBodyWithDefaultMotionState(BulletShape shape, uint id, Vector3 pos, Quaternion rot)
  361. {
  362. BulletShapeUnman shapeu = shape as BulletShapeUnman;
  363. return new BulletBodyUnman(id, BSAPICPP.CreateBodyWithDefaultMotionState2(shapeu.ptr, id, pos, rot));
  364. }
  365. public override BulletBody CreateGhostFromShape(BulletWorld world, BulletShape shape, uint id, Vector3 pos, Quaternion rot)
  366. {
  367. BulletWorldUnman worldu = world as BulletWorldUnman;
  368. BulletShapeUnman shapeu = shape as BulletShapeUnman;
  369. return new BulletBodyUnman(id, BSAPICPP.CreateGhostFromShape2(worldu.ptr, shapeu.ptr, id, pos, rot));
  370. }
  371. public override void DestroyObject(BulletWorld world, BulletBody obj)
  372. {
  373. BulletWorldUnman worldu = world as BulletWorldUnman;
  374. BulletBodyUnman bodyu = obj as BulletBodyUnman;
  375. BSAPICPP.DestroyObject2(worldu.ptr, bodyu.ptr);
  376. }
  377. // =====================================================================================
  378. // Terrain creation and helper routines
  379. public override BulletShape CreateGroundPlaneShape(uint id, float height, float collisionMargin)
  380. {
  381. return new BulletShapeUnman(BSAPICPP.CreateGroundPlaneShape2(id, height, collisionMargin), BSPhysicsShapeType.SHAPE_GROUNDPLANE);
  382. }
  383. public override BulletShape CreateTerrainShape(uint id, Vector3 size, float minHeight, float maxHeight, float[] heightMap,
  384. float scaleFactor, float collisionMargin)
  385. {
  386. return new BulletShapeUnman(BSAPICPP.CreateTerrainShape2(id, size, minHeight, maxHeight, heightMap, scaleFactor, collisionMargin),
  387. BSPhysicsShapeType.SHAPE_TERRAIN);
  388. }
  389. // =====================================================================================
  390. // Constraint creation and helper routines
  391. public override BulletConstraint Create6DofConstraint(BulletWorld world, BulletBody obj1, BulletBody obj2,
  392. Vector3 frame1loc, Quaternion frame1rot,
  393. Vector3 frame2loc, Quaternion frame2rot,
  394. bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies)
  395. {
  396. BulletWorldUnman worldu = world as BulletWorldUnman;
  397. BulletBodyUnman bodyu1 = obj1 as BulletBodyUnman;
  398. BulletBodyUnman bodyu2 = obj2 as BulletBodyUnman;
  399. return new BulletConstraintUnman(BSAPICPP.Create6DofConstraint2(worldu.ptr, bodyu1.ptr, bodyu2.ptr, frame1loc, frame1rot,
  400. frame2loc, frame2rot, useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies));
  401. }
  402. public override BulletConstraint Create6DofConstraintToPoint(BulletWorld world, BulletBody obj1, BulletBody obj2,
  403. Vector3 joinPoint,
  404. bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies)
  405. {
  406. BulletWorldUnman worldu = world as BulletWorldUnman;
  407. BulletBodyUnman bodyu1 = obj1 as BulletBodyUnman;
  408. BulletBodyUnman bodyu2 = obj2 as BulletBodyUnman;
  409. return new BulletConstraintUnman(BSAPICPP.Create6DofConstraintToPoint2(worldu.ptr, bodyu1.ptr, bodyu2.ptr,
  410. joinPoint, useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies));
  411. }
  412. public override BulletConstraint Create6DofConstraintFixed(BulletWorld world, BulletBody obj1,
  413. Vector3 frameInBloc, Quaternion frameInBrot,
  414. bool useLinearReferenceFrameB, bool disableCollisionsBetweenLinkedBodies)
  415. {
  416. BulletWorldUnman worldu = world as BulletWorldUnman;
  417. BulletBodyUnman bodyu1 = obj1 as BulletBodyUnman;
  418. return new BulletConstraintUnman(BSAPICPP.Create6DofConstraintFixed2(worldu.ptr, bodyu1.ptr,
  419. frameInBloc, frameInBrot, useLinearReferenceFrameB, disableCollisionsBetweenLinkedBodies));
  420. }
  421. public override BulletConstraint Create6DofSpringConstraint(BulletWorld world, BulletBody obj1, BulletBody obj2,
  422. Vector3 frame1loc, Quaternion frame1rot,
  423. Vector3 frame2loc, Quaternion frame2rot,
  424. bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies)
  425. {
  426. BulletWorldUnman worldu = world as BulletWorldUnman;
  427. BulletBodyUnman bodyu1 = obj1 as BulletBodyUnman;
  428. BulletBodyUnman bodyu2 = obj2 as BulletBodyUnman;
  429. return new BulletConstraintUnman(BSAPICPP.Create6DofSpringConstraint2(worldu.ptr, bodyu1.ptr, bodyu2.ptr, frame1loc, frame1rot,
  430. frame2loc, frame2rot, useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies));
  431. }
  432. public override BulletConstraint CreateHingeConstraint(BulletWorld world, BulletBody obj1, BulletBody obj2,
  433. Vector3 pivotinA, Vector3 pivotinB,
  434. Vector3 axisInA, Vector3 axisInB,
  435. bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies)
  436. {
  437. BulletWorldUnman worldu = world as BulletWorldUnman;
  438. BulletBodyUnman bodyu1 = obj1 as BulletBodyUnman;
  439. BulletBodyUnman bodyu2 = obj2 as BulletBodyUnman;
  440. return new BulletConstraintUnman(BSAPICPP.CreateHingeConstraint2(worldu.ptr, bodyu1.ptr, bodyu2.ptr,
  441. pivotinA, pivotinB, axisInA, axisInB, useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies));
  442. }
  443. public override BulletConstraint CreateSliderConstraint(BulletWorld world, BulletBody obj1, BulletBody obj2,
  444. Vector3 frame1loc, Quaternion frame1rot,
  445. Vector3 frame2loc, Quaternion frame2rot,
  446. bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies)
  447. {
  448. BulletWorldUnman worldu = world as BulletWorldUnman;
  449. BulletBodyUnman bodyu1 = obj1 as BulletBodyUnman;
  450. BulletBodyUnman bodyu2 = obj2 as BulletBodyUnman;
  451. return new BulletConstraintUnman(BSAPICPP.CreateSliderConstraint2(worldu.ptr, bodyu1.ptr, bodyu2.ptr, frame1loc, frame1rot,
  452. frame2loc, frame2rot, useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies));
  453. }
  454. public override BulletConstraint CreateConeTwistConstraint(BulletWorld world, BulletBody obj1, BulletBody obj2,
  455. Vector3 frame1loc, Quaternion frame1rot,
  456. Vector3 frame2loc, Quaternion frame2rot,
  457. bool disableCollisionsBetweenLinkedBodies)
  458. {
  459. BulletWorldUnman worldu = world as BulletWorldUnman;
  460. BulletBodyUnman bodyu1 = obj1 as BulletBodyUnman;
  461. BulletBodyUnman bodyu2 = obj2 as BulletBodyUnman;
  462. return new BulletConstraintUnman(BSAPICPP.CreateConeTwistConstraint2(worldu.ptr, bodyu1.ptr, bodyu2.ptr, frame1loc, frame1rot,
  463. frame2loc, frame2rot, disableCollisionsBetweenLinkedBodies));
  464. }
  465. public override BulletConstraint CreateGearConstraint(BulletWorld world, BulletBody obj1, BulletBody obj2,
  466. Vector3 axisInA, Vector3 axisInB,
  467. float ratio, bool disableCollisionsBetweenLinkedBodies)
  468. {
  469. BulletWorldUnman worldu = world as BulletWorldUnman;
  470. BulletBodyUnman bodyu1 = obj1 as BulletBodyUnman;
  471. BulletBodyUnman bodyu2 = obj2 as BulletBodyUnman;
  472. return new BulletConstraintUnman(BSAPICPP.CreateGearConstraint2(worldu.ptr, bodyu1.ptr, bodyu2.ptr, axisInA, axisInB,
  473. ratio, disableCollisionsBetweenLinkedBodies));
  474. }
  475. public override BulletConstraint CreatePoint2PointConstraint(BulletWorld world, BulletBody obj1, BulletBody obj2,
  476. Vector3 pivotInA, Vector3 pivotInB,
  477. bool disableCollisionsBetweenLinkedBodies)
  478. {
  479. BulletWorldUnman worldu = world as BulletWorldUnman;
  480. BulletBodyUnman bodyu1 = obj1 as BulletBodyUnman;
  481. BulletBodyUnman bodyu2 = obj2 as BulletBodyUnman;
  482. return new BulletConstraintUnman(BSAPICPP.CreatePoint2PointConstraint2(worldu.ptr, bodyu1.ptr, bodyu2.ptr, pivotInA, pivotInB,
  483. disableCollisionsBetweenLinkedBodies));
  484. }
  485. public override void SetConstraintEnable(BulletConstraint constrain, float numericTrueFalse)
  486. {
  487. BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
  488. BSAPICPP.SetConstraintEnable2(constrainu.ptr, numericTrueFalse);
  489. }
  490. public override void SetConstraintNumSolverIterations(BulletConstraint constrain, float iterations)
  491. {
  492. BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
  493. BSAPICPP.SetConstraintNumSolverIterations2(constrainu.ptr, iterations);
  494. }
  495. public override bool SetFrames(BulletConstraint constrain,
  496. Vector3 frameA, Quaternion frameArot, Vector3 frameB, Quaternion frameBrot)
  497. {
  498. BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
  499. return BSAPICPP.SetFrames2(constrainu.ptr, frameA, frameArot, frameB, frameBrot);
  500. }
  501. public override bool SetLinearLimits(BulletConstraint constrain, Vector3 low, Vector3 hi)
  502. {
  503. BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
  504. return BSAPICPP.SetLinearLimits2(constrainu.ptr, low, hi);
  505. }
  506. public override bool SetAngularLimits(BulletConstraint constrain, Vector3 low, Vector3 hi)
  507. {
  508. BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
  509. return BSAPICPP.SetAngularLimits2(constrainu.ptr, low, hi);
  510. }
  511. public override bool UseFrameOffset(BulletConstraint constrain, float enable)
  512. {
  513. BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
  514. return BSAPICPP.UseFrameOffset2(constrainu.ptr, enable);
  515. }
  516. public override bool TranslationalLimitMotor(BulletConstraint constrain, float enable, float targetVel, float maxMotorForce)
  517. {
  518. BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
  519. return BSAPICPP.TranslationalLimitMotor2(constrainu.ptr, enable, targetVel, maxMotorForce);
  520. }
  521. public override bool SetBreakingImpulseThreshold(BulletConstraint constrain, float threshold)
  522. {
  523. BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
  524. return BSAPICPP.SetBreakingImpulseThreshold2(constrainu.ptr, threshold);
  525. }
  526. public override bool HingeSetLimits(BulletConstraint constrain, float low, float high, float softness, float bias, float relaxation)
  527. {
  528. BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
  529. return BSAPICPP.HingeSetLimits2(constrainu.ptr, low, high, softness, bias, relaxation);
  530. }
  531. public override bool SpringEnable(BulletConstraint constrain, int index, float numericTrueFalse)
  532. {
  533. BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
  534. return BSAPICPP.ConstraintSpringEnable2(constrainu.ptr, index, numericTrueFalse);
  535. }
  536. public override bool SpringSetEquilibriumPoint(BulletConstraint constrain, int index, float equilibriumPoint)
  537. {
  538. BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
  539. return BSAPICPP.ConstraintSpringSetEquilibriumPoint2(constrainu.ptr, index, equilibriumPoint);
  540. }
  541. public override bool SpringSetStiffness(BulletConstraint constrain, int index, float stiffnesss)
  542. {
  543. BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
  544. return BSAPICPP.ConstraintSpringSetStiffness2(constrainu.ptr, index, stiffnesss);
  545. }
  546. public override bool SpringSetDamping(BulletConstraint constrain, int index, float damping)
  547. {
  548. BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
  549. return BSAPICPP.ConstraintSpringSetDamping2(constrainu.ptr, index, damping);
  550. }
  551. public override bool SliderSetLimits(BulletConstraint constrain, int lowerUpper, int linAng, float val)
  552. {
  553. BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
  554. return BSAPICPP.SliderSetLimits2(constrainu.ptr, lowerUpper, linAng, val);
  555. }
  556. public override bool SliderSet(BulletConstraint constrain, int softRestDamp, int dirLimOrtho, int linAng, float val)
  557. {
  558. BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
  559. return BSAPICPP.SliderSet2(constrainu.ptr, softRestDamp, dirLimOrtho, linAng, val);
  560. }
  561. public override bool SliderMotorEnable(BulletConstraint constrain, int linAng, float numericTrueFalse)
  562. {
  563. BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
  564. return BSAPICPP.SliderMotorEnable2(constrainu.ptr, linAng, numericTrueFalse);
  565. }
  566. public override bool SliderMotor(BulletConstraint constrain, int forceVel, int linAng, float val)
  567. {
  568. BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
  569. return BSAPICPP.SliderMotor2(constrainu.ptr, forceVel, linAng, val);
  570. }
  571. public override bool CalculateTransforms(BulletConstraint constrain)
  572. {
  573. BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
  574. return BSAPICPP.CalculateTransforms2(constrainu.ptr);
  575. }
  576. public override bool SetConstraintParam(BulletConstraint constrain, ConstraintParams paramIndex, float value, ConstraintParamAxis axis)
  577. {
  578. BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
  579. return BSAPICPP.SetConstraintParam2(constrainu.ptr, paramIndex, value, axis);
  580. }
  581. public override bool DestroyConstraint(BulletWorld world, BulletConstraint constrain)
  582. {
  583. BulletWorldUnman worldu = world as BulletWorldUnman;
  584. BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
  585. return BSAPICPP.DestroyConstraint2(worldu.ptr, constrainu.ptr);
  586. }
  587. // =====================================================================================
  588. // btCollisionWorld entries
  589. public override void UpdateSingleAabb(BulletWorld world, BulletBody obj)
  590. {
  591. BulletWorldUnman worldu = world as BulletWorldUnman;
  592. BulletBodyUnman bodyu = obj as BulletBodyUnman;
  593. BSAPICPP.UpdateSingleAabb2(worldu.ptr, bodyu.ptr);
  594. }
  595. public override void UpdateAabbs(BulletWorld world)
  596. {
  597. BulletWorldUnman worldu = world as BulletWorldUnman;
  598. BSAPICPP.UpdateAabbs2(worldu.ptr);
  599. }
  600. public override bool GetForceUpdateAllAabbs(BulletWorld world)
  601. {
  602. BulletWorldUnman worldu = world as BulletWorldUnman;
  603. return BSAPICPP.GetForceUpdateAllAabbs2(worldu.ptr);
  604. }
  605. public override void SetForceUpdateAllAabbs(BulletWorld world, bool force)
  606. {
  607. BulletWorldUnman worldu = world as BulletWorldUnman;
  608. BSAPICPP.SetForceUpdateAllAabbs2(worldu.ptr, force);
  609. }
  610. // =====================================================================================
  611. // btDynamicsWorld entries
  612. public override bool AddObjectToWorld(BulletWorld world, BulletBody obj)
  613. {
  614. BulletWorldUnman worldu = world as BulletWorldUnman;
  615. BulletBodyUnman bodyu = obj as BulletBodyUnman;
  616. // Bullet resets several variables when an object is added to the world.
  617. // Gravity is reset to world default depending on the static/dynamic
  618. // type. Of course, the collision flags in the broadphase proxy are initialized to default.
  619. Vector3 origGrav = BSAPICPP.GetGravity2(bodyu.ptr);
  620. bool ret = BSAPICPP.AddObjectToWorld2(worldu.ptr, bodyu.ptr);
  621. if (ret)
  622. {
  623. BSAPICPP.SetGravity2(bodyu.ptr, origGrav);
  624. obj.ApplyCollisionMask(world.physicsScene);
  625. }
  626. return ret;
  627. }
  628. public override bool RemoveObjectFromWorld(BulletWorld world, BulletBody obj)
  629. {
  630. BulletWorldUnman worldu = world as BulletWorldUnman;
  631. BulletBodyUnman bodyu = obj as BulletBodyUnman;
  632. return BSAPICPP.RemoveObjectFromWorld2(worldu.ptr, bodyu.ptr);
  633. }
  634. public override bool ClearCollisionProxyCache(BulletWorld world, BulletBody obj)
  635. {
  636. BulletWorldUnman worldu = world as BulletWorldUnman;
  637. BulletBodyUnman bodyu = obj as BulletBodyUnman;
  638. return BSAPICPP.ClearCollisionProxyCache2(worldu.ptr, bodyu.ptr);
  639. }
  640. public override bool AddConstraintToWorld(BulletWorld world, BulletConstraint constrain, bool disableCollisionsBetweenLinkedObjects)
  641. {
  642. BulletWorldUnman worldu = world as BulletWorldUnman;
  643. BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
  644. return BSAPICPP.AddConstraintToWorld2(worldu.ptr, constrainu.ptr, disableCollisionsBetweenLinkedObjects);
  645. }
  646. public override bool RemoveConstraintFromWorld(BulletWorld world, BulletConstraint constrain)
  647. {
  648. BulletWorldUnman worldu = world as BulletWorldUnman;
  649. BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
  650. return BSAPICPP.RemoveConstraintFromWorld2(worldu.ptr, constrainu.ptr);
  651. }
  652. // =====================================================================================
  653. // btCollisionObject entries
  654. public override Vector3 GetAnisotripicFriction(BulletConstraint constrain)
  655. {
  656. BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
  657. return BSAPICPP.GetAnisotripicFriction2(constrainu.ptr);
  658. }
  659. public override Vector3 SetAnisotripicFriction(BulletConstraint constrain, Vector3 frict)
  660. {
  661. BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
  662. return BSAPICPP.SetAnisotripicFriction2(constrainu.ptr, frict);
  663. }
  664. public override bool HasAnisotripicFriction(BulletConstraint constrain)
  665. {
  666. BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
  667. return BSAPICPP.HasAnisotripicFriction2(constrainu.ptr);
  668. }
  669. public override void SetContactProcessingThreshold(BulletBody obj, float val)
  670. {
  671. BulletBodyUnman bodyu = obj as BulletBodyUnman;
  672. BSAPICPP.SetContactProcessingThreshold2(bodyu.ptr, val);
  673. }
  674. public override float GetContactProcessingThreshold(BulletBody obj)
  675. {
  676. BulletBodyUnman bodyu = obj as BulletBodyUnman;
  677. return BSAPICPP.GetContactProcessingThreshold2(bodyu.ptr);
  678. }
  679. public override bool IsStaticObject(BulletBody obj)
  680. {
  681. BulletBodyUnman bodyu = obj as BulletBodyUnman;
  682. return BSAPICPP.IsStaticObject2(bodyu.ptr);
  683. }
  684. public override bool IsKinematicObject(BulletBody obj)
  685. {
  686. BulletBodyUnman bodyu = obj as BulletBodyUnman;
  687. return BSAPICPP.IsKinematicObject2(bodyu.ptr);
  688. }
  689. public override bool IsStaticOrKinematicObject(BulletBody obj)
  690. {
  691. BulletBodyUnman bodyu = obj as BulletBodyUnman;
  692. return BSAPICPP.IsStaticOrKinematicObject2(bodyu.ptr);
  693. }
  694. public override bool HasContactResponse(BulletBody obj)
  695. {
  696. BulletBodyUnman bodyu = obj as BulletBodyUnman;
  697. return BSAPICPP.HasContactResponse2(bodyu.ptr);
  698. }
  699. public override void SetCollisionShape(BulletWorld world, BulletBody obj, BulletShape shape)
  700. {
  701. BulletWorldUnman worldu = world as BulletWorldUnman;
  702. BulletBodyUnman bodyu = obj as BulletBodyUnman;
  703. BulletShapeUnman shapeu = shape as BulletShapeUnman;
  704. if (worldu != null && bodyu != null)
  705. {
  706. // Special case to allow the caller to zero out the reference to any physical shape
  707. if (shapeu != null)
  708. BSAPICPP.SetCollisionShape2(worldu.ptr, bodyu.ptr, shapeu.ptr);
  709. else
  710. BSAPICPP.SetCollisionShape2(worldu.ptr, bodyu.ptr, IntPtr.Zero);
  711. }
  712. }
  713. public override BulletShape GetCollisionShape(BulletBody obj)
  714. {
  715. BulletBodyUnman bodyu = obj as BulletBodyUnman;
  716. return new BulletShapeUnman(BSAPICPP.GetCollisionShape2(bodyu.ptr), BSPhysicsShapeType.SHAPE_UNKNOWN);
  717. }
  718. public override int GetActivationState(BulletBody obj)
  719. {
  720. BulletBodyUnman bodyu = obj as BulletBodyUnman;
  721. return BSAPICPP.GetActivationState2(bodyu.ptr);
  722. }
  723. public override void SetActivationState(BulletBody obj, int state)
  724. {
  725. BulletBodyUnman bodyu = obj as BulletBodyUnman;
  726. BSAPICPP.SetActivationState2(bodyu.ptr, state);
  727. }
  728. public override void SetDeactivationTime(BulletBody obj, float dtime)
  729. {
  730. BulletBodyUnman bodyu = obj as BulletBodyUnman;
  731. BSAPICPP.SetDeactivationTime2(bodyu.ptr, dtime);
  732. }
  733. public override float GetDeactivationTime(BulletBody obj)
  734. {
  735. BulletBodyUnman bodyu = obj as BulletBodyUnman;
  736. return BSAPICPP.GetDeactivationTime2(bodyu.ptr);
  737. }
  738. public override void ForceActivationState(BulletBody obj, ActivationState state)
  739. {
  740. BulletBodyUnman bodyu = obj as BulletBodyUnman;
  741. BSAPICPP.ForceActivationState2(bodyu.ptr, state);
  742. }
  743. public override void Activate(BulletBody obj, bool forceActivation)
  744. {
  745. BulletBodyUnman bodyu = obj as BulletBodyUnman;
  746. BSAPICPP.Activate2(bodyu.ptr, forceActivation);
  747. }
  748. public override bool IsActive(BulletBody obj)
  749. {
  750. BulletBodyUnman bodyu = obj as BulletBodyUnman;
  751. return BSAPICPP.IsActive2(bodyu.ptr);
  752. }
  753. public override void SetRestitution(BulletBody obj, float val)
  754. {
  755. BulletBodyUnman bodyu = obj as BulletBodyUnman;
  756. BSAPICPP.SetRestitution2(bodyu.ptr, val);
  757. }
  758. public override float GetRestitution(BulletBody obj)
  759. {
  760. BulletBodyUnman bodyu = obj as BulletBodyUnman;
  761. return BSAPICPP.GetRestitution2(bodyu.ptr);
  762. }
  763. public override void SetFriction(BulletBody obj, float val)
  764. {
  765. BulletBodyUnman bodyu = obj as BulletBodyUnman;
  766. BSAPICPP.SetFriction2(bodyu.ptr, val);
  767. }
  768. public override float GetFriction(BulletBody obj)
  769. {
  770. BulletBodyUnman bodyu = obj as BulletBodyUnman;
  771. return BSAPICPP.GetFriction2(bodyu.ptr);
  772. }
  773. public override Vector3 GetPosition(BulletBody obj)
  774. {
  775. BulletBodyUnman bodyu = obj as BulletBodyUnman;
  776. return BSAPICPP.GetPosition2(bodyu.ptr);
  777. }
  778. public override Quaternion GetOrientation(BulletBody obj)
  779. {
  780. BulletBodyUnman bodyu = obj as BulletBodyUnman;
  781. return BSAPICPP.GetOrientation2(bodyu.ptr);
  782. }
  783. public override void SetTranslation(BulletBody obj, Vector3 position, Quaternion rotation)
  784. {
  785. BulletBodyUnman bodyu = obj as BulletBodyUnman;
  786. BSAPICPP.SetTranslation2(bodyu.ptr, position, rotation);
  787. }
  788. /*
  789. public override IntPtr GetBroadphaseHandle(BulletBody obj)
  790. {
  791. BulletBodyUnman bodyu = obj as BulletBodyUnman;
  792. return BSAPICPP.GetBroadphaseHandle2(bodyu.ptr);
  793. }
  794. public override void SetBroadphaseHandle(BulletBody obj, IntPtr handle)
  795. {
  796. BulletBodyUnman bodyu = obj as BulletBodyUnman;
  797. BSAPICPP.SetUserPointer2(bodyu.ptr, handle);
  798. }
  799. */
  800. public override void SetInterpolationLinearVelocity(BulletBody obj, Vector3 vel)
  801. {
  802. BulletBodyUnman bodyu = obj as BulletBodyUnman;
  803. BSAPICPP.SetInterpolationLinearVelocity2(bodyu.ptr, vel);
  804. }
  805. public override void SetInterpolationAngularVelocity(BulletBody obj, Vector3 vel)
  806. {
  807. BulletBodyUnman bodyu = obj as BulletBodyUnman;
  808. BSAPICPP.SetInterpolationAngularVelocity2(bodyu.ptr, vel);
  809. }
  810. public override void SetInterpolationVelocity(BulletBody obj, Vector3 linearVel, Vector3 angularVel)
  811. {
  812. BulletBodyUnman bodyu = obj as BulletBodyUnman;
  813. BSAPICPP.SetInterpolationVelocity2(bodyu.ptr, linearVel, angularVel);
  814. }
  815. public override float GetHitFraction(BulletBody obj)
  816. {
  817. BulletBodyUnman bodyu = obj as BulletBodyUnman;
  818. return BSAPICPP.GetHitFraction2(bodyu.ptr);
  819. }
  820. public override void SetHitFraction(BulletBody obj, float val)
  821. {
  822. BulletBodyUnman bodyu = obj as BulletBodyUnman;
  823. BSAPICPP.SetHitFraction2(bodyu.ptr, val);
  824. }
  825. public override CollisionFlags GetCollisionFlags(BulletBody obj)
  826. {
  827. BulletBodyUnman bodyu = obj as BulletBodyUnman;
  828. return BSAPICPP.GetCollisionFlags2(bodyu.ptr);
  829. }
  830. public override CollisionFlags SetCollisionFlags(BulletBody obj, CollisionFlags flags)
  831. {
  832. BulletBodyUnman bodyu = obj as BulletBodyUnman;
  833. return BSAPICPP.SetCollisionFlags2(bodyu.ptr, flags);
  834. }
  835. public override CollisionFlags AddToCollisionFlags(BulletBody obj, CollisionFlags flags)
  836. {
  837. BulletBodyUnman bodyu = obj as BulletBodyUnman;
  838. return BSAPICPP.AddToCollisionFlags2(bodyu.ptr, flags);
  839. }
  840. public override CollisionFlags RemoveFromCollisionFlags(BulletBody obj, CollisionFlags flags)
  841. {
  842. BulletBodyUnman bodyu = obj as BulletBodyUnman;
  843. return BSAPICPP.RemoveFromCollisionFlags2(bodyu.ptr, flags);
  844. }
  845. public override float GetCcdMotionThreshold(BulletBody obj)
  846. {
  847. BulletBodyUnman bodyu = obj as BulletBodyUnman;
  848. return BSAPICPP.GetCcdMotionThreshold2(bodyu.ptr);
  849. }
  850. public override void SetCcdMotionThreshold(BulletBody obj, float val)
  851. {
  852. BulletBodyUnman bodyu = obj as BulletBodyUnman;
  853. BSAPICPP.SetCcdMotionThreshold2(bodyu.ptr, val);
  854. }
  855. public override float GetCcdSweptSphereRadius(BulletBody obj)
  856. {
  857. BulletBodyUnman bodyu = obj as BulletBodyUnman;
  858. return BSAPICPP.GetCcdSweptSphereRadius2(bodyu.ptr);
  859. }
  860. public override void SetCcdSweptSphereRadius(BulletBody obj, float val)
  861. {
  862. BulletBodyUnman bodyu = obj as BulletBodyUnman;
  863. BSAPICPP.SetCcdSweptSphereRadius2(bodyu.ptr, val);
  864. }
  865. public override IntPtr GetUserPointer(BulletBody obj)
  866. {
  867. BulletBodyUnman bodyu = obj as BulletBodyUnman;
  868. return BSAPICPP.GetUserPointer2(bodyu.ptr);
  869. }
  870. public override void SetUserPointer(BulletBody obj, IntPtr val)
  871. {
  872. BulletBodyUnman bodyu = obj as BulletBodyUnman;
  873. BSAPICPP.SetUserPointer2(bodyu.ptr, val);
  874. }
  875. // =====================================================================================
  876. // btRigidBody entries
  877. public override void ApplyGravity(BulletBody obj)
  878. {
  879. BulletBodyUnman bodyu = obj as BulletBodyUnman;
  880. BSAPICPP.ApplyGravity2(bodyu.ptr);
  881. }
  882. public override void SetGravity(BulletBody obj, Vector3 val)
  883. {
  884. BulletBodyUnman bodyu = obj as BulletBodyUnman;
  885. BSAPICPP.SetGravity2(bodyu.ptr, val);
  886. }
  887. public override Vector3 GetGravity(BulletBody obj)
  888. {
  889. BulletBodyUnman bodyu = obj as BulletBodyUnman;
  890. return BSAPICPP.GetGravity2(bodyu.ptr);
  891. }
  892. public override void SetDamping(BulletBody obj, float lin_damping, float ang_damping)
  893. {
  894. BulletBodyUnman bodyu = obj as BulletBodyUnman;
  895. BSAPICPP.SetDamping2(bodyu.ptr, lin_damping, ang_damping);
  896. }
  897. public override void SetLinearDamping(BulletBody obj, float lin_damping)
  898. {
  899. BulletBodyUnman bodyu = obj as BulletBodyUnman;
  900. BSAPICPP.SetLinearDamping2(bodyu.ptr, lin_damping);
  901. }
  902. public override void SetAngularDamping(BulletBody obj, float ang_damping)
  903. {
  904. BulletBodyUnman bodyu = obj as BulletBodyUnman;
  905. BSAPICPP.SetAngularDamping2(bodyu.ptr, ang_damping);
  906. }
  907. public override float GetLinearDamping(BulletBody obj)
  908. {
  909. BulletBodyUnman bodyu = obj as BulletBodyUnman;
  910. return BSAPICPP.GetLinearDamping2(bodyu.ptr);
  911. }
  912. public override float GetAngularDamping(BulletBody obj)
  913. {
  914. BulletBodyUnman bodyu = obj as BulletBodyUnman;
  915. return BSAPICPP.GetAngularDamping2(bodyu.ptr);
  916. }
  917. public override float GetLinearSleepingThreshold(BulletBody obj)
  918. {
  919. BulletBodyUnman bodyu = obj as BulletBodyUnman;
  920. return BSAPICPP.GetLinearSleepingThreshold2(bodyu.ptr);
  921. }
  922. public override void ApplyDamping(BulletBody obj, float timeStep)
  923. {
  924. BulletBodyUnman bodyu = obj as BulletBodyUnman;
  925. BSAPICPP.ApplyDamping2(bodyu.ptr, timeStep);
  926. }
  927. public override void SetMassProps(BulletBody obj, float mass, Vector3 inertia)
  928. {
  929. BulletBodyUnman bodyu = obj as BulletBodyUnman;
  930. BSAPICPP.SetMassProps2(bodyu.ptr, mass, inertia);
  931. }
  932. public override Vector3 GetLinearFactor(BulletBody obj)
  933. {
  934. BulletBodyUnman bodyu = obj as BulletBodyUnman;
  935. return BSAPICPP.GetLinearFactor2(bodyu.ptr);
  936. }
  937. public override void SetLinearFactor(BulletBody obj, Vector3 factor)
  938. {
  939. BulletBodyUnman bodyu = obj as BulletBodyUnman;
  940. BSAPICPP.SetLinearFactor2(bodyu.ptr, factor);
  941. }
  942. public override void SetCenterOfMassByPosRot(BulletBody obj, Vector3 pos, Quaternion rot)
  943. {
  944. BulletBodyUnman bodyu = obj as BulletBodyUnman;
  945. BSAPICPP.SetCenterOfMassByPosRot2(bodyu.ptr, pos, rot);
  946. }
  947. // Add a force to the object as if its mass is one.
  948. // Deep down in Bullet: m_totalForce += force*m_linearFactor;
  949. public override void ApplyCentralForce(BulletBody obj, Vector3 force)
  950. {
  951. BulletBodyUnman bodyu = obj as BulletBodyUnman;
  952. BSAPICPP.ApplyCentralForce2(bodyu.ptr, force);
  953. }
  954. // Set the force being applied to the object as if its mass is one.
  955. public override void SetObjectForce(BulletBody obj, Vector3 force)
  956. {
  957. BulletBodyUnman bodyu = obj as BulletBodyUnman;
  958. BSAPICPP.SetObjectForce2(bodyu.ptr, force);
  959. }
  960. public override Vector3 GetTotalForce(BulletBody obj)
  961. {
  962. BulletBodyUnman bodyu = obj as BulletBodyUnman;
  963. return BSAPICPP.GetTotalForce2(bodyu.ptr);
  964. }
  965. public override Vector3 GetTotalTorque(BulletBody obj)
  966. {
  967. BulletBodyUnman bodyu = obj as BulletBodyUnman;
  968. return BSAPICPP.GetTotalTorque2(bodyu.ptr);
  969. }
  970. public override Vector3 GetInvInertiaDiagLocal(BulletBody obj)
  971. {
  972. BulletBodyUnman bodyu = obj as BulletBodyUnman;
  973. return BSAPICPP.GetInvInertiaDiagLocal2(bodyu.ptr);
  974. }
  975. public override void SetInvInertiaDiagLocal(BulletBody obj, Vector3 inert)
  976. {
  977. BulletBodyUnman bodyu = obj as BulletBodyUnman;
  978. BSAPICPP.SetInvInertiaDiagLocal2(bodyu.ptr, inert);
  979. }
  980. public override void SetSleepingThresholds(BulletBody obj, float lin_threshold, float ang_threshold)
  981. {
  982. BulletBodyUnman bodyu = obj as BulletBodyUnman;
  983. BSAPICPP.SetSleepingThresholds2(bodyu.ptr, lin_threshold, ang_threshold);
  984. }
  985. // Deep down in Bullet: m_totalTorque += torque*m_angularFactor;
  986. public override void ApplyTorque(BulletBody obj, Vector3 torque)
  987. {
  988. BulletBodyUnman bodyu = obj as BulletBodyUnman;
  989. BSAPICPP.ApplyTorque2(bodyu.ptr, torque);
  990. }
  991. // Apply force at the given point. Will add torque to the object.
  992. // Deep down in Bullet: applyCentralForce(force);
  993. // applyTorque(rel_pos.cross(force*m_linearFactor));
  994. public override void ApplyForce(BulletBody obj, Vector3 force, Vector3 pos)
  995. {
  996. BulletBodyUnman bodyu = obj as BulletBodyUnman;
  997. BSAPICPP.ApplyForce2(bodyu.ptr, force, pos);
  998. }
  999. // Apply impulse to the object. Same as "ApplycentralForce" but force scaled by object's mass.
  1000. // Deep down in Bullet: m_linearVelocity += impulse *m_linearFactor * m_inverseMass;
  1001. public override void ApplyCentralImpulse(BulletBody obj, Vector3 imp)
  1002. {
  1003. BulletBodyUnman bodyu = obj as BulletBodyUnman;
  1004. BSAPICPP.ApplyCentralImpulse2(bodyu.ptr, imp);
  1005. }
  1006. // Apply impulse to the object's torque. Force is scaled by object's mass.
  1007. // Deep down in Bullet: m_angularVelocity += m_invInertiaTensorWorld * torque * m_angularFactor;
  1008. public override void ApplyTorqueImpulse(BulletBody obj, Vector3 imp)
  1009. {
  1010. BulletBodyUnman bodyu = obj as BulletBodyUnman;
  1011. BSAPICPP.ApplyTorqueImpulse2(bodyu.ptr, imp);
  1012. }
  1013. // Apply impulse at the point given. For is scaled by object's mass and effects both linear and angular forces.
  1014. // Deep down in Bullet: applyCentralImpulse(impulse);
  1015. // applyTorqueImpulse(rel_pos.cross(impulse*m_linearFactor));
  1016. public override void ApplyImpulse(BulletBody obj, Vector3 imp, Vector3 pos)
  1017. {
  1018. BulletBodyUnman bodyu = obj as BulletBodyUnman;
  1019. BSAPICPP.ApplyImpulse2(bodyu.ptr, imp, pos);
  1020. }
  1021. public override void ClearForces(BulletBody obj)
  1022. {
  1023. BulletBodyUnman bodyu = obj as BulletBodyUnman;
  1024. BSAPICPP.ClearForces2(bodyu.ptr);
  1025. }
  1026. public override void ClearAllForces(BulletBody obj)
  1027. {
  1028. BulletBodyUnman bodyu = obj as BulletBodyUnman;
  1029. BSAPICPP.ClearAllForces2(bodyu.ptr);
  1030. }
  1031. public override void UpdateInertiaTensor(BulletBody obj)
  1032. {
  1033. BulletBodyUnman bodyu = obj as BulletBodyUnman;
  1034. BSAPICPP.UpdateInertiaTensor2(bodyu.ptr);
  1035. }
  1036. public override Vector3 GetLinearVelocity(BulletBody obj)
  1037. {
  1038. BulletBodyUnman bodyu = obj as BulletBodyUnman;
  1039. return BSAPICPP.GetLinearVelocity2(bodyu.ptr);
  1040. }
  1041. public override Vector3 GetAngularVelocity(BulletBody obj)
  1042. {
  1043. BulletBodyUnman bodyu = obj as BulletBodyUnman;
  1044. return BSAPICPP.GetAngularVelocity2(bodyu.ptr);
  1045. }
  1046. public override void SetLinearVelocity(BulletBody obj, Vector3 vel)
  1047. {
  1048. BulletBodyUnman bodyu = obj as BulletBodyUnman;
  1049. BSAPICPP.SetLinearVelocity2(bodyu.ptr, vel);
  1050. }
  1051. public override void SetAngularVelocity(BulletBody obj, Vector3 angularVelocity)
  1052. {
  1053. BulletBodyUnman bodyu = obj as BulletBodyUnman;
  1054. BSAPICPP.SetAngularVelocity2(bodyu.ptr, angularVelocity);
  1055. }
  1056. public override Vector3 GetVelocityInLocalPoint(BulletBody obj, Vector3 pos)
  1057. {
  1058. BulletBodyUnman bodyu = obj as BulletBodyUnman;
  1059. return BSAPICPP.GetVelocityInLocalPoint2(bodyu.ptr, pos);
  1060. }
  1061. public override void Translate(BulletBody obj, Vector3 trans)
  1062. {
  1063. BulletBodyUnman bodyu = obj as BulletBodyUnman;
  1064. BSAPICPP.Translate2(bodyu.ptr, trans);
  1065. }
  1066. public override void UpdateDeactivation(BulletBody obj, float timeStep)
  1067. {
  1068. BulletBodyUnman bodyu = obj as BulletBodyUnman;
  1069. BSAPICPP.UpdateDeactivation2(bodyu.ptr, timeStep);
  1070. }
  1071. public override bool WantsSleeping(BulletBody obj)
  1072. {
  1073. BulletBodyUnman bodyu = obj as BulletBodyUnman;
  1074. return BSAPICPP.WantsSleeping2(bodyu.ptr);
  1075. }
  1076. public override void SetAngularFactor(BulletBody obj, float factor)
  1077. {
  1078. BulletBodyUnman bodyu = obj as BulletBodyUnman;
  1079. BSAPICPP.SetAngularFactor2(bodyu.ptr, factor);
  1080. }
  1081. public override void SetAngularFactorV(BulletBody obj, Vector3 factor)
  1082. {
  1083. BulletBodyUnman bodyu = obj as BulletBodyUnman;
  1084. BSAPICPP.SetAngularFactorV2(bodyu.ptr, factor);
  1085. }
  1086. public override Vector3 GetAngularFactor(BulletBody obj)
  1087. {
  1088. BulletBodyUnman bodyu = obj as BulletBodyUnman;
  1089. return BSAPICPP.GetAngularFactor2(bodyu.ptr);
  1090. }
  1091. public override bool IsInWorld(BulletWorld world, BulletBody obj)
  1092. {
  1093. BulletBodyUnman bodyu = obj as BulletBodyUnman;
  1094. return BSAPICPP.IsInWorld2(bodyu.ptr);
  1095. }
  1096. public override void AddConstraintRef(BulletBody obj, BulletConstraint constrain)
  1097. {
  1098. BulletBodyUnman bodyu = obj as BulletBodyUnman;
  1099. BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
  1100. BSAPICPP.AddConstraintRef2(bodyu.ptr, constrainu.ptr);
  1101. }
  1102. public override void RemoveConstraintRef(BulletBody obj, BulletConstraint constrain)
  1103. {
  1104. BulletBodyUnman bodyu = obj as BulletBodyUnman;
  1105. BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
  1106. BSAPICPP.RemoveConstraintRef2(bodyu.ptr, constrainu.ptr);
  1107. }
  1108. public override BulletConstraint GetConstraintRef(BulletBody obj, int index)
  1109. {
  1110. BulletBodyUnman bodyu = obj as BulletBodyUnman;
  1111. return new BulletConstraintUnman(BSAPICPP.GetConstraintRef2(bodyu.ptr, index));
  1112. }
  1113. public override int GetNumConstraintRefs(BulletBody obj)
  1114. {
  1115. BulletBodyUnman bodyu = obj as BulletBodyUnman;
  1116. return BSAPICPP.GetNumConstraintRefs2(bodyu.ptr);
  1117. }
  1118. public override bool SetCollisionGroupMask(BulletBody body, uint filter, uint mask)
  1119. {
  1120. BulletBodyUnman bodyu = body as BulletBodyUnman;
  1121. return BSAPICPP.SetCollisionGroupMask2(bodyu.ptr, filter, mask);
  1122. }
  1123. // =====================================================================================
  1124. // btCollisionShape entries
  1125. public override float GetAngularMotionDisc(BulletShape shape)
  1126. {
  1127. BulletShapeUnman shapeu = shape as BulletShapeUnman;
  1128. return BSAPICPP.GetAngularMotionDisc2(shapeu.ptr);
  1129. }
  1130. public override float GetContactBreakingThreshold(BulletShape shape, float defaultFactor)
  1131. {
  1132. BulletShapeUnman shapeu = shape as BulletShapeUnman;
  1133. return BSAPICPP.GetContactBreakingThreshold2(shapeu.ptr, defaultFactor);
  1134. }
  1135. public override bool IsPolyhedral(BulletShape shape)
  1136. {
  1137. BulletShapeUnman shapeu = shape as BulletShapeUnman;
  1138. return BSAPICPP.IsPolyhedral2(shapeu.ptr);
  1139. }
  1140. public override bool IsConvex2d(BulletShape shape)
  1141. {
  1142. BulletShapeUnman shapeu = shape as BulletShapeUnman;
  1143. return BSAPICPP.IsConvex2d2(shapeu.ptr);
  1144. }
  1145. public override bool IsConvex(BulletShape shape)
  1146. {
  1147. BulletShapeUnman shapeu = shape as BulletShapeUnman;
  1148. return BSAPICPP.IsConvex2(shapeu.ptr);
  1149. }
  1150. public override bool IsNonMoving(BulletShape shape)
  1151. {
  1152. BulletShapeUnman shapeu = shape as BulletShapeUnman;
  1153. return BSAPICPP.IsNonMoving2(shapeu.ptr);
  1154. }
  1155. public override bool IsConcave(BulletShape shape)
  1156. {
  1157. BulletShapeUnman shapeu = shape as BulletShapeUnman;
  1158. return BSAPICPP.IsConcave2(shapeu.ptr);
  1159. }
  1160. public override bool IsCompound(BulletShape shape)
  1161. {
  1162. BulletShapeUnman shapeu = shape as BulletShapeUnman;
  1163. return BSAPICPP.IsCompound2(shapeu.ptr);
  1164. }
  1165. public override bool IsSoftBody(BulletShape shape)
  1166. {
  1167. BulletShapeUnman shapeu = shape as BulletShapeUnman;
  1168. return BSAPICPP.IsSoftBody2(shapeu.ptr);
  1169. }
  1170. public override bool IsInfinite(BulletShape shape)
  1171. {
  1172. BulletShapeUnman shapeu = shape as BulletShapeUnman;
  1173. return BSAPICPP.IsInfinite2(shapeu.ptr);
  1174. }
  1175. public override void SetLocalScaling(BulletShape shape, Vector3 scale)
  1176. {
  1177. BulletShapeUnman shapeu = shape as BulletShapeUnman;
  1178. BSAPICPP.SetLocalScaling2(shapeu.ptr, scale);
  1179. }
  1180. public override Vector3 GetLocalScaling(BulletShape shape)
  1181. {
  1182. BulletShapeUnman shapeu = shape as BulletShapeUnman;
  1183. return BSAPICPP.GetLocalScaling2(shapeu.ptr);
  1184. }
  1185. public override Vector3 CalculateLocalInertia(BulletShape shape, float mass)
  1186. {
  1187. BulletShapeUnman shapeu = shape as BulletShapeUnman;
  1188. return BSAPICPP.CalculateLocalInertia2(shapeu.ptr, mass);
  1189. }
  1190. public override int GetShapeType(BulletShape shape)
  1191. {
  1192. BulletShapeUnman shapeu = shape as BulletShapeUnman;
  1193. return BSAPICPP.GetShapeType2(shapeu.ptr);
  1194. }
  1195. public override void SetMargin(BulletShape shape, float val)
  1196. {
  1197. BulletShapeUnman shapeu = shape as BulletShapeUnman;
  1198. BSAPICPP.SetMargin2(shapeu.ptr, val);
  1199. }
  1200. public override float GetMargin(BulletShape shape)
  1201. {
  1202. BulletShapeUnman shapeu = shape as BulletShapeUnman;
  1203. return BSAPICPP.GetMargin2(shapeu.ptr);
  1204. }
  1205. // =====================================================================================
  1206. // Debugging
  1207. public override void DumpRigidBody(BulletWorld world, BulletBody collisionObject)
  1208. {
  1209. BulletWorldUnman worldu = world as BulletWorldUnman;
  1210. BulletBodyUnman bodyu = collisionObject as BulletBodyUnman;
  1211. BSAPICPP.DumpRigidBody2(worldu.ptr, bodyu.ptr);
  1212. }
  1213. public override void DumpCollisionShape(BulletWorld world, BulletShape collisionShape)
  1214. {
  1215. BulletWorldUnman worldu = world as BulletWorldUnman;
  1216. BulletShapeUnman shapeu = collisionShape as BulletShapeUnman;
  1217. BSAPICPP.DumpCollisionShape2(worldu.ptr, shapeu.ptr);
  1218. }
  1219. public override void DumpConstraint(BulletWorld world, BulletConstraint constrain)
  1220. {
  1221. BulletWorldUnman worldu = world as BulletWorldUnman;
  1222. BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
  1223. BSAPICPP.DumpConstraint2(worldu.ptr, constrainu.ptr);
  1224. }
  1225. public override void DumpActivationInfo(BulletWorld world)
  1226. {
  1227. BulletWorldUnman worldu = world as BulletWorldUnman;
  1228. BSAPICPP.DumpActivationInfo2(worldu.ptr);
  1229. }
  1230. public override void DumpAllInfo(BulletWorld world)
  1231. {
  1232. BulletWorldUnman worldu = world as BulletWorldUnman;
  1233. BSAPICPP.DumpAllInfo2(worldu.ptr);
  1234. }
  1235. public override void DumpPhysicsStatistics(BulletWorld world)
  1236. {
  1237. BulletWorldUnman worldu = world as BulletWorldUnman;
  1238. BSAPICPP.DumpPhysicsStatistics2(worldu.ptr);
  1239. }
  1240. public override void ResetBroadphasePool(BulletWorld world)
  1241. {
  1242. BulletWorldUnman worldu = world as BulletWorldUnman;
  1243. BSAPICPP.ResetBroadphasePool(worldu.ptr);
  1244. }
  1245. public override void ResetConstraintSolver(BulletWorld world)
  1246. {
  1247. BulletWorldUnman worldu = world as BulletWorldUnman;
  1248. BSAPICPP.ResetConstraintSolver(worldu.ptr);
  1249. }
  1250. // =====================================================================================
  1251. // =====================================================================================
  1252. // =====================================================================================
  1253. // =====================================================================================
  1254. // =====================================================================================
  1255. // The actual interface to the unmanaged code
  1256. static class BSAPICPP
  1257. {
  1258. // ===============================================================================
  1259. // Link back to the managed code for outputting log messages
  1260. [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
  1261. public delegate void DebugLogCallback([MarshalAs(UnmanagedType.LPStr)]string msg);
  1262. // ===============================================================================
  1263. // Initialization and simulation
  1264. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1265. public static extern IntPtr Initialize2(Vector3 maxPosition, IntPtr parms,
  1266. int maxCollisions, IntPtr collisionArray,
  1267. int maxUpdates, IntPtr updateArray,
  1268. DebugLogCallback logRoutine);
  1269. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1270. public static extern int PhysicsStep2(IntPtr world, float timeStep, int maxSubSteps, float fixedTimeStep,
  1271. out int updatedEntityCount, out int collidersCount);
  1272. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1273. public static extern void Shutdown2(IntPtr sim);
  1274. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1275. public static extern bool PushUpdate2(IntPtr obj);
  1276. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1277. public static extern bool UpdateParameter2(IntPtr world, uint localID, String parm, float value);
  1278. // =====================================================================================
  1279. // Mesh, hull, shape and body creation helper routines
  1280. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1281. public static extern IntPtr CreateMeshShape2(IntPtr world,
  1282. int indicesCount, [MarshalAs(UnmanagedType.LPArray)] int[] indices,
  1283. int verticesCount, [MarshalAs(UnmanagedType.LPArray)] float[] vertices );
  1284. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1285. public static extern IntPtr CreateGImpactShape2(IntPtr world,
  1286. int indicesCount, [MarshalAs(UnmanagedType.LPArray)] int[] indices,
  1287. int verticesCount, [MarshalAs(UnmanagedType.LPArray)] float[] vertices );
  1288. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1289. public static extern IntPtr CreateHullShape2(IntPtr world,
  1290. int hullCount, [MarshalAs(UnmanagedType.LPArray)] float[] hulls);
  1291. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1292. public static extern IntPtr BuildHullShapeFromMesh2(IntPtr world, IntPtr meshShape, HACDParams parms);
  1293. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1294. public static extern IntPtr BuildConvexHullShapeFromMesh2(IntPtr world, IntPtr meshShape);
  1295. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1296. public static extern IntPtr CreateConvexHullShape2(IntPtr world,
  1297. int indicesCount, [MarshalAs(UnmanagedType.LPArray)] int[] indices,
  1298. int verticesCount, [MarshalAs(UnmanagedType.LPArray)] float[] vertices );
  1299. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1300. public static extern IntPtr BuildNativeShape2(IntPtr world, ShapeData shapeData);
  1301. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1302. public static extern bool IsNativeShape2(IntPtr shape);
  1303. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1304. public static extern void SetShapeCollisionMargin(IntPtr shape, float margin);
  1305. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1306. public static extern IntPtr BuildCapsuleShape2(IntPtr world, float radius, float height, Vector3 scale);
  1307. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1308. public static extern IntPtr CreateCompoundShape2(IntPtr sim, bool enableDynamicAabbTree);
  1309. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1310. public static extern int GetNumberOfCompoundChildren2(IntPtr cShape);
  1311. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1312. public static extern void AddChildShapeToCompoundShape2(IntPtr cShape, IntPtr addShape, Vector3 pos, Quaternion rot);
  1313. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1314. public static extern IntPtr GetChildShapeFromCompoundShapeIndex2(IntPtr cShape, int indx);
  1315. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1316. public static extern IntPtr RemoveChildShapeFromCompoundShapeIndex2(IntPtr cShape, int indx);
  1317. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1318. public static extern void RemoveChildShapeFromCompoundShape2(IntPtr cShape, IntPtr removeShape);
  1319. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1320. public static extern void UpdateChildTransform2(IntPtr pShape, int childIndex, Vector3 pos, Quaternion rot, bool shouldRecalculateLocalAabb);
  1321. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1322. public static extern void RecalculateCompoundShapeLocalAabb2(IntPtr cShape);
  1323. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1324. public static extern IntPtr DuplicateCollisionShape2(IntPtr sim, IntPtr srcShape, uint id);
  1325. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1326. public static extern bool DeleteCollisionShape2(IntPtr world, IntPtr shape);
  1327. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1328. public static extern int GetBodyType2(IntPtr obj);
  1329. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1330. public static extern IntPtr CreateBodyFromShape2(IntPtr sim, IntPtr shape, uint id, Vector3 pos, Quaternion rot);
  1331. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1332. public static extern IntPtr CreateBodyWithDefaultMotionState2(IntPtr shape, uint id, Vector3 pos, Quaternion rot);
  1333. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1334. public static extern IntPtr CreateGhostFromShape2(IntPtr sim, IntPtr shape, uint id, Vector3 pos, Quaternion rot);
  1335. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1336. public static extern void DestroyObject2(IntPtr sim, IntPtr obj);
  1337. // =====================================================================================
  1338. // Terrain creation and helper routines
  1339. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1340. public static extern IntPtr CreateGroundPlaneShape2(uint id, float height, float collisionMargin);
  1341. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1342. public static extern IntPtr CreateTerrainShape2(uint id, Vector3 size, float minHeight, float maxHeight,
  1343. [MarshalAs(UnmanagedType.LPArray)] float[] heightMap,
  1344. float scaleFactor, float collisionMargin);
  1345. // =====================================================================================
  1346. // Constraint creation and helper routines
  1347. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1348. public static extern IntPtr Create6DofConstraint2(IntPtr world, IntPtr obj1, IntPtr obj2,
  1349. Vector3 frame1loc, Quaternion frame1rot,
  1350. Vector3 frame2loc, Quaternion frame2rot,
  1351. bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies);
  1352. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1353. public static extern IntPtr Create6DofConstraintToPoint2(IntPtr world, IntPtr obj1, IntPtr obj2,
  1354. Vector3 joinPoint,
  1355. bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies);
  1356. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1357. public static extern IntPtr Create6DofConstraintFixed2(IntPtr world, IntPtr obj1,
  1358. Vector3 frameInBloc, Quaternion frameInBrot,
  1359. bool useLinearReferenceFrameB, bool disableCollisionsBetweenLinkedBodies);
  1360. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1361. public static extern IntPtr Create6DofSpringConstraint2(IntPtr world, IntPtr obj1, IntPtr obj2,
  1362. Vector3 frame1loc, Quaternion frame1rot,
  1363. Vector3 frame2loc, Quaternion frame2rot,
  1364. bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies);
  1365. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1366. public static extern IntPtr CreateHingeConstraint2(IntPtr world, IntPtr obj1, IntPtr obj2,
  1367. Vector3 pivotinA, Vector3 pivotinB,
  1368. Vector3 axisInA, Vector3 axisInB,
  1369. bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies);
  1370. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1371. public static extern IntPtr CreateSliderConstraint2(IntPtr world, IntPtr obj1, IntPtr obj2,
  1372. Vector3 frameInAloc, Quaternion frameInArot,
  1373. Vector3 frameInBloc, Quaternion frameInBrot,
  1374. bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies);
  1375. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1376. public static extern IntPtr CreateConeTwistConstraint2(IntPtr world, IntPtr obj1, IntPtr obj2,
  1377. Vector3 frameInAloc, Quaternion frameInArot,
  1378. Vector3 frameInBloc, Quaternion frameInBrot,
  1379. bool disableCollisionsBetweenLinkedBodies);
  1380. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1381. public static extern IntPtr CreateGearConstraint2(IntPtr world, IntPtr obj1, IntPtr obj2,
  1382. Vector3 axisInA, Vector3 axisInB,
  1383. float ratio, bool disableCollisionsBetweenLinkedBodies);
  1384. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1385. public static extern IntPtr CreatePoint2PointConstraint2(IntPtr world, IntPtr obj1, IntPtr obj2,
  1386. Vector3 pivotInA, Vector3 pivotInB,
  1387. bool disableCollisionsBetweenLinkedBodies);
  1388. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1389. public static extern void SetConstraintEnable2(IntPtr constrain, float numericTrueFalse);
  1390. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1391. public static extern void SetConstraintNumSolverIterations2(IntPtr constrain, float iterations);
  1392. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1393. public static extern bool SetFrames2(IntPtr constrain,
  1394. Vector3 frameA, Quaternion frameArot, Vector3 frameB, Quaternion frameBrot);
  1395. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1396. public static extern bool SetLinearLimits2(IntPtr constrain, Vector3 low, Vector3 hi);
  1397. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1398. public static extern bool SetAngularLimits2(IntPtr constrain, Vector3 low, Vector3 hi);
  1399. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1400. public static extern bool UseFrameOffset2(IntPtr constrain, float enable);
  1401. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1402. public static extern bool TranslationalLimitMotor2(IntPtr constrain, float enable, float targetVel, float maxMotorForce);
  1403. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1404. public static extern bool SetBreakingImpulseThreshold2(IntPtr constrain, float threshold);
  1405. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1406. public static extern bool HingeSetLimits2(IntPtr constrain, float low, float high, float softness, float bias, float relaxation);
  1407. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1408. public static extern bool ConstraintSpringEnable2(IntPtr constrain, int index, float numericTrueFalse);
  1409. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1410. public static extern bool ConstraintSpringSetEquilibriumPoint2(IntPtr constrain, int index, float equilibriumPoint);
  1411. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1412. public static extern bool ConstraintSpringSetStiffness2(IntPtr constrain, int index, float stiffness);
  1413. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1414. public static extern bool ConstraintSpringSetDamping2(IntPtr constrain, int index, float damping);
  1415. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1416. public static extern bool SliderSetLimits2(IntPtr constrain, int lowerUpper, int linAng, float val);
  1417. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1418. public static extern bool SliderSet2(IntPtr constrain, int softRestDamp, int dirLimOrtho, int linAng, float val);
  1419. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1420. public static extern bool SliderMotorEnable2(IntPtr constrain, int linAng, float numericTrueFalse);
  1421. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1422. public static extern bool SliderMotor2(IntPtr constrain, int forceVel, int linAng, float val);
  1423. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1424. public static extern bool CalculateTransforms2(IntPtr constrain);
  1425. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1426. public static extern bool SetConstraintParam2(IntPtr constrain, ConstraintParams paramIndex, float value, ConstraintParamAxis axis);
  1427. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1428. public static extern bool DestroyConstraint2(IntPtr world, IntPtr constrain);
  1429. // =====================================================================================
  1430. // btCollisionWorld entries
  1431. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1432. public static extern void UpdateSingleAabb2(IntPtr world, IntPtr obj);
  1433. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1434. public static extern void UpdateAabbs2(IntPtr world);
  1435. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1436. public static extern bool GetForceUpdateAllAabbs2(IntPtr world);
  1437. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1438. public static extern void SetForceUpdateAllAabbs2(IntPtr world, bool force);
  1439. // =====================================================================================
  1440. // btDynamicsWorld entries
  1441. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1442. public static extern bool AddObjectToWorld2(IntPtr world, IntPtr obj);
  1443. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1444. public static extern bool RemoveObjectFromWorld2(IntPtr world, IntPtr obj);
  1445. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1446. public static extern bool ClearCollisionProxyCache2(IntPtr world, IntPtr obj);
  1447. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1448. public static extern bool AddConstraintToWorld2(IntPtr world, IntPtr constrain, bool disableCollisionsBetweenLinkedObjects);
  1449. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1450. public static extern bool RemoveConstraintFromWorld2(IntPtr world, IntPtr constrain);
  1451. // =====================================================================================
  1452. // btCollisionObject entries
  1453. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1454. public static extern Vector3 GetAnisotripicFriction2(IntPtr constrain);
  1455. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1456. public static extern Vector3 SetAnisotripicFriction2(IntPtr constrain, Vector3 frict);
  1457. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1458. public static extern bool HasAnisotripicFriction2(IntPtr constrain);
  1459. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1460. public static extern void SetContactProcessingThreshold2(IntPtr obj, float val);
  1461. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1462. public static extern float GetContactProcessingThreshold2(IntPtr obj);
  1463. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1464. public static extern bool IsStaticObject2(IntPtr obj);
  1465. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1466. public static extern bool IsKinematicObject2(IntPtr obj);
  1467. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1468. public static extern bool IsStaticOrKinematicObject2(IntPtr obj);
  1469. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1470. public static extern bool HasContactResponse2(IntPtr obj);
  1471. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1472. public static extern void SetCollisionShape2(IntPtr sim, IntPtr obj, IntPtr shape);
  1473. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1474. public static extern IntPtr GetCollisionShape2(IntPtr obj);
  1475. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1476. public static extern int GetActivationState2(IntPtr obj);
  1477. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1478. public static extern void SetActivationState2(IntPtr obj, int state);
  1479. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1480. public static extern void SetDeactivationTime2(IntPtr obj, float dtime);
  1481. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1482. public static extern float GetDeactivationTime2(IntPtr obj);
  1483. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1484. public static extern void ForceActivationState2(IntPtr obj, ActivationState state);
  1485. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1486. public static extern void Activate2(IntPtr obj, bool forceActivation);
  1487. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1488. public static extern bool IsActive2(IntPtr obj);
  1489. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1490. public static extern void SetRestitution2(IntPtr obj, float val);
  1491. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1492. public static extern float GetRestitution2(IntPtr obj);
  1493. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1494. public static extern void SetFriction2(IntPtr obj, float val);
  1495. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1496. public static extern float GetFriction2(IntPtr obj);
  1497. /* Haven't defined the type 'Transform'
  1498. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1499. public static extern Transform GetWorldTransform2(IntPtr obj);
  1500. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1501. public static extern void setWorldTransform2(IntPtr obj, Transform trans);
  1502. */
  1503. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1504. public static extern Vector3 GetPosition2(IntPtr obj);
  1505. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1506. public static extern Quaternion GetOrientation2(IntPtr obj);
  1507. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1508. public static extern void SetTranslation2(IntPtr obj, Vector3 position, Quaternion rotation);
  1509. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1510. public static extern IntPtr GetBroadphaseHandle2(IntPtr obj);
  1511. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1512. public static extern void SetBroadphaseHandle2(IntPtr obj, IntPtr handle);
  1513. /*
  1514. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1515. public static extern Transform GetInterpolationWorldTransform2(IntPtr obj);
  1516. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1517. public static extern void SetInterpolationWorldTransform2(IntPtr obj, Transform trans);
  1518. */
  1519. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1520. public static extern void SetInterpolationLinearVelocity2(IntPtr obj, Vector3 vel);
  1521. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1522. public static extern void SetInterpolationAngularVelocity2(IntPtr obj, Vector3 vel);
  1523. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1524. public static extern void SetInterpolationVelocity2(IntPtr obj, Vector3 linearVel, Vector3 angularVel);
  1525. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1526. public static extern float GetHitFraction2(IntPtr obj);
  1527. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1528. public static extern void SetHitFraction2(IntPtr obj, float val);
  1529. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1530. public static extern CollisionFlags GetCollisionFlags2(IntPtr obj);
  1531. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1532. public static extern CollisionFlags SetCollisionFlags2(IntPtr obj, CollisionFlags flags);
  1533. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1534. public static extern CollisionFlags AddToCollisionFlags2(IntPtr obj, CollisionFlags flags);
  1535. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1536. public static extern CollisionFlags RemoveFromCollisionFlags2(IntPtr obj, CollisionFlags flags);
  1537. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1538. public static extern float GetCcdMotionThreshold2(IntPtr obj);
  1539. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1540. public static extern void SetCcdMotionThreshold2(IntPtr obj, float val);
  1541. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1542. public static extern float GetCcdSweptSphereRadius2(IntPtr obj);
  1543. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1544. public static extern void SetCcdSweptSphereRadius2(IntPtr obj, float val);
  1545. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1546. public static extern IntPtr GetUserPointer2(IntPtr obj);
  1547. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1548. public static extern void SetUserPointer2(IntPtr obj, IntPtr val);
  1549. // =====================================================================================
  1550. // btRigidBody entries
  1551. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1552. public static extern void ApplyGravity2(IntPtr obj);
  1553. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1554. public static extern void SetGravity2(IntPtr obj, Vector3 val);
  1555. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1556. public static extern Vector3 GetGravity2(IntPtr obj);
  1557. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1558. public static extern void SetDamping2(IntPtr obj, float lin_damping, float ang_damping);
  1559. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1560. public static extern void SetLinearDamping2(IntPtr obj, float lin_damping);
  1561. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1562. public static extern void SetAngularDamping2(IntPtr obj, float ang_damping);
  1563. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1564. public static extern float GetLinearDamping2(IntPtr obj);
  1565. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1566. public static extern float GetAngularDamping2(IntPtr obj);
  1567. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1568. public static extern float GetLinearSleepingThreshold2(IntPtr obj);
  1569. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1570. public static extern float GetAngularSleepingThreshold2(IntPtr obj);
  1571. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1572. public static extern void ApplyDamping2(IntPtr obj, float timeStep);
  1573. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1574. public static extern void SetMassProps2(IntPtr obj, float mass, Vector3 inertia);
  1575. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1576. public static extern Vector3 GetLinearFactor2(IntPtr obj);
  1577. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1578. public static extern void SetLinearFactor2(IntPtr obj, Vector3 factor);
  1579. /*
  1580. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1581. public static extern void SetCenterOfMassTransform2(IntPtr obj, Transform trans);
  1582. */
  1583. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1584. public static extern void SetCenterOfMassByPosRot2(IntPtr obj, Vector3 pos, Quaternion rot);
  1585. // Add a force to the object as if its mass is one.
  1586. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1587. public static extern void ApplyCentralForce2(IntPtr obj, Vector3 force);
  1588. // Set the force being applied to the object as if its mass is one.
  1589. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1590. public static extern void SetObjectForce2(IntPtr obj, Vector3 force);
  1591. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1592. public static extern Vector3 GetTotalForce2(IntPtr obj);
  1593. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1594. public static extern Vector3 GetTotalTorque2(IntPtr obj);
  1595. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1596. public static extern Vector3 GetInvInertiaDiagLocal2(IntPtr obj);
  1597. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1598. public static extern void SetInvInertiaDiagLocal2(IntPtr obj, Vector3 inert);
  1599. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1600. public static extern void SetSleepingThresholds2(IntPtr obj, float lin_threshold, float ang_threshold);
  1601. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1602. public static extern void ApplyTorque2(IntPtr obj, Vector3 torque);
  1603. // Apply force at the given point. Will add torque to the object.
  1604. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1605. public static extern void ApplyForce2(IntPtr obj, Vector3 force, Vector3 pos);
  1606. // Apply impulse to the object. Same as "ApplycentralForce" but force scaled by object's mass.
  1607. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1608. public static extern void ApplyCentralImpulse2(IntPtr obj, Vector3 imp);
  1609. // Apply impulse to the object's torque. Force is scaled by object's mass.
  1610. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1611. public static extern void ApplyTorqueImpulse2(IntPtr obj, Vector3 imp);
  1612. // Apply impulse at the point given. For is scaled by object's mass and effects both linear and angular forces.
  1613. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1614. public static extern void ApplyImpulse2(IntPtr obj, Vector3 imp, Vector3 pos);
  1615. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1616. public static extern void ClearForces2(IntPtr obj);
  1617. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1618. public static extern void ClearAllForces2(IntPtr obj);
  1619. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1620. public static extern void UpdateInertiaTensor2(IntPtr obj);
  1621. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1622. public static extern Vector3 GetCenterOfMassPosition2(IntPtr obj);
  1623. /*
  1624. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1625. public static extern Transform GetCenterOfMassTransform2(IntPtr obj);
  1626. */
  1627. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1628. public static extern Vector3 GetLinearVelocity2(IntPtr obj);
  1629. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1630. public static extern Vector3 GetAngularVelocity2(IntPtr obj);
  1631. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1632. public static extern void SetLinearVelocity2(IntPtr obj, Vector3 val);
  1633. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1634. public static extern void SetAngularVelocity2(IntPtr obj, Vector3 angularVelocity);
  1635. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1636. public static extern Vector3 GetVelocityInLocalPoint2(IntPtr obj, Vector3 pos);
  1637. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1638. public static extern void Translate2(IntPtr obj, Vector3 trans);
  1639. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1640. public static extern void UpdateDeactivation2(IntPtr obj, float timeStep);
  1641. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1642. public static extern bool WantsSleeping2(IntPtr obj);
  1643. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1644. public static extern void SetAngularFactor2(IntPtr obj, float factor);
  1645. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1646. public static extern void SetAngularFactorV2(IntPtr obj, Vector3 factor);
  1647. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1648. public static extern Vector3 GetAngularFactor2(IntPtr obj);
  1649. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1650. public static extern bool IsInWorld2(IntPtr obj);
  1651. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1652. public static extern void AddConstraintRef2(IntPtr obj, IntPtr constrain);
  1653. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1654. public static extern void RemoveConstraintRef2(IntPtr obj, IntPtr constrain);
  1655. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1656. public static extern IntPtr GetConstraintRef2(IntPtr obj, int index);
  1657. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1658. public static extern int GetNumConstraintRefs2(IntPtr obj);
  1659. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1660. public static extern bool SetCollisionGroupMask2(IntPtr body, uint filter, uint mask);
  1661. // =====================================================================================
  1662. // btCollisionShape entries
  1663. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1664. public static extern float GetAngularMotionDisc2(IntPtr shape);
  1665. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1666. public static extern float GetContactBreakingThreshold2(IntPtr shape, float defaultFactor);
  1667. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1668. public static extern bool IsPolyhedral2(IntPtr shape);
  1669. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1670. public static extern bool IsConvex2d2(IntPtr shape);
  1671. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1672. public static extern bool IsConvex2(IntPtr shape);
  1673. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1674. public static extern bool IsNonMoving2(IntPtr shape);
  1675. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1676. public static extern bool IsConcave2(IntPtr shape);
  1677. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1678. public static extern bool IsCompound2(IntPtr shape);
  1679. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1680. public static extern bool IsSoftBody2(IntPtr shape);
  1681. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1682. public static extern bool IsInfinite2(IntPtr shape);
  1683. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1684. public static extern void SetLocalScaling2(IntPtr shape, Vector3 scale);
  1685. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1686. public static extern Vector3 GetLocalScaling2(IntPtr shape);
  1687. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1688. public static extern Vector3 CalculateLocalInertia2(IntPtr shape, float mass);
  1689. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1690. public static extern int GetShapeType2(IntPtr shape);
  1691. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1692. public static extern void SetMargin2(IntPtr shape, float val);
  1693. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1694. public static extern float GetMargin2(IntPtr shape);
  1695. // =====================================================================================
  1696. // Debugging
  1697. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1698. public static extern void DumpRigidBody2(IntPtr sim, IntPtr collisionObject);
  1699. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1700. public static extern void DumpCollisionShape2(IntPtr sim, IntPtr collisionShape);
  1701. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1702. public static extern void DumpMapInfo2(IntPtr sim, IntPtr manInfo);
  1703. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1704. public static extern void DumpConstraint2(IntPtr sim, IntPtr constrain);
  1705. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1706. public static extern void DumpActivationInfo2(IntPtr sim);
  1707. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1708. public static extern void DumpAllInfo2(IntPtr sim);
  1709. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1710. public static extern void DumpPhysicsStatistics2(IntPtr sim);
  1711. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1712. public static extern void ResetBroadphasePool(IntPtr sim);
  1713. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  1714. public static extern void ResetConstraintSolver(IntPtr sim);
  1715. }
  1716. }
  1717. }