2
0

com_jme3_bullet_objects_PhysicsRigidBody.cpp 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849
  1. /*
  2. * Copyright (c) 2009-2010 jMonkeyEngine
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are
  7. * met:
  8. *
  9. * * Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. *
  12. * * Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. *
  16. * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
  17. * may be used to endorse or promote products derived from this software
  18. * without specific prior written permission.
  19. *
  20. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  22. * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  23. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  24. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  25. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  26. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  27. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  28. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  29. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  30. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. */
  32. /**
  33. * Author: Normen Hansen
  34. */
  35. #include "com_jme3_bullet_objects_PhysicsRigidBody.h"
  36. #include "jmeBulletUtil.h"
  37. #include "jmeMotionState.h"
  38. #ifdef __cplusplus
  39. extern "C" {
  40. #endif
  41. /*
  42. * Class: com_jme3_bullet_objects_PhysicsRigidBody
  43. * Method: createRigidBody
  44. * Signature: (FJJ)J
  45. */
  46. JNIEXPORT jlong JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_createRigidBody
  47. (JNIEnv *env, jobject object, jfloat mass, jlong motionstatId, jlong shapeId) {
  48. jmeClasses::initJavaClasses(env);
  49. btMotionState* motionState = reinterpret_cast<btMotionState*>(motionstatId);
  50. btCollisionShape* shape = reinterpret_cast<btCollisionShape*>(shapeId);
  51. btVector3 localInertia = btVector3();
  52. shape->calculateLocalInertia(mass, localInertia);
  53. btRigidBody* body = new btRigidBody(mass, motionState, shape, localInertia);
  54. body->setUserPointer(NULL);
  55. return reinterpret_cast<jlong>(body);
  56. }
  57. /*
  58. * Class: com_jme3_bullet_objects_PhysicsRigidBody
  59. * Method: isInWorld
  60. * Signature: (J)Z
  61. */
  62. JNIEXPORT jboolean JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_isInWorld
  63. (JNIEnv *env, jobject object, jlong bodyId) {
  64. btRigidBody* body = reinterpret_cast<btRigidBody*>(bodyId);
  65. if (body == NULL) {
  66. jclass newExc = env->FindClass("java/lang/NullPointerException");
  67. env->ThrowNew(newExc, "The native object does not exist.");
  68. return false;
  69. }
  70. return body->isInWorld();
  71. }
  72. /*
  73. * Class: com_jme3_bullet_objects_PhysicsRigidBody
  74. * Method: setPhysicsLocation
  75. * Signature: (JLcom/jme3/math/Vector3f;)V
  76. */
  77. JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_setPhysicsLocation
  78. (JNIEnv *env, jobject object, jlong bodyId, jobject value) {
  79. btRigidBody* body = reinterpret_cast<btRigidBody*>(bodyId);
  80. if (body == NULL) {
  81. jclass newExc = env->FindClass("java/lang/NullPointerException");
  82. env->ThrowNew(newExc, "The native object does not exist.");
  83. return;
  84. }
  85. // if (body->isStaticOrKinematicObject() || !body->isInWorld())
  86. ((jmeMotionState*) body->getMotionState())->setKinematicLocation(env, value);
  87. body->setCenterOfMassTransform(((jmeMotionState*) body->getMotionState())->worldTransform);
  88. // else{
  89. // btMatrix3x3* mtx = &btMatrix3x3();
  90. // btTransform* trans = &btTransform(*mtx);
  91. // trans->setBasis(body->getCenterOfMassTransform().getBasis());
  92. // jmeBulletUtil::convert(env, value, &trans->getOrigin());
  93. // body->setCenterOfMassTransform(*trans);
  94. // }
  95. }
  96. /*
  97. * Class: com_jme3_bullet_objects_PhysicsRigidBody
  98. * Method: setPhysicsRotation
  99. * Signature: (JLcom/jme3/math/Matrix3f;)V
  100. */
  101. JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_setPhysicsRotation__JLcom_jme3_math_Matrix3f_2
  102. (JNIEnv *env, jobject object, jlong bodyId, jobject value) {
  103. btRigidBody* body = reinterpret_cast<btRigidBody*>(bodyId);
  104. if (body == NULL) {
  105. jclass newExc = env->FindClass("java/lang/NullPointerException");
  106. env->ThrowNew(newExc, "The native object does not exist.");
  107. return;
  108. }
  109. // if (body->isStaticOrKinematicObject() || !body->isInWorld())
  110. ((jmeMotionState*) body->getMotionState())->setKinematicRotation(env, value);
  111. body->setCenterOfMassTransform(((jmeMotionState*) body->getMotionState())->worldTransform);
  112. // else{
  113. // btMatrix3x3* mtx = &btMatrix3x3();
  114. // btTransform* trans = &btTransform(*mtx);
  115. // trans->setOrigin(body->getCenterOfMassTransform().getOrigin());
  116. // jmeBulletUtil::convert(env, value, &trans->getBasis());
  117. // body->setCenterOfMassTransform(*trans);
  118. // }
  119. }
  120. /*
  121. * Class: com_jme3_bullet_objects_PhysicsRigidBody
  122. * Method: setPhysicsRotation
  123. * Signature: (JLcom/jme3/math/Quaternion;)V
  124. */
  125. JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_setPhysicsRotation__JLcom_jme3_math_Quaternion_2
  126. (JNIEnv *env, jobject object, jlong bodyId, jobject value) {
  127. btRigidBody* body = reinterpret_cast<btRigidBody*>(bodyId);
  128. if (body == NULL) {
  129. jclass newExc = env->FindClass("java/lang/NullPointerException");
  130. env->ThrowNew(newExc, "The native object does not exist.");
  131. return;
  132. }
  133. // if (body->isStaticOrKinematicObject() || !body->isInWorld())
  134. ((jmeMotionState*) body->getMotionState())->setKinematicRotationQuat(env, value);
  135. body->setCenterOfMassTransform(((jmeMotionState*) body->getMotionState())->worldTransform);
  136. // else{
  137. // btMatrix3x3* mtx = &btMatrix3x3();
  138. // btTransform* trans = &btTransform(*mtx);
  139. // trans->setOrigin(body->getCenterOfMassTransform().getOrigin());
  140. // jmeBulletUtil::convertQuat(env, value, &trans->getBasis());
  141. // body->setCenterOfMassTransform(*trans);
  142. // }
  143. }
  144. /*
  145. * Class: com_jme3_bullet_objects_PhysicsRigidBody
  146. * Method: getPhysicsLocation
  147. * Signature: (JLcom/jme3/math/Vector3f;)V
  148. */
  149. JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_getPhysicsLocation
  150. (JNIEnv *env, jobject object, jlong bodyId, jobject value) {
  151. btRigidBody* body = reinterpret_cast<btRigidBody*>(bodyId);
  152. if (body == NULL) {
  153. jclass newExc = env->FindClass("java/lang/NullPointerException");
  154. env->ThrowNew(newExc, "The native object does not exist.");
  155. return;
  156. }
  157. jmeBulletUtil::convert(env, &body->getWorldTransform().getOrigin(), value);
  158. }
  159. /*
  160. * Class: com_jme3_bullet_objects_PhysicsRigidBody
  161. * Method: getPhysicsRotation
  162. * Signature: (JLcom/jme3/math/Quaternion;)V
  163. */
  164. JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_getPhysicsRotation
  165. (JNIEnv *env, jobject object, jlong bodyId, jobject value) {
  166. btRigidBody* body = reinterpret_cast<btRigidBody*>(bodyId);
  167. if (body == NULL) {
  168. jclass newExc = env->FindClass("java/lang/NullPointerException");
  169. env->ThrowNew(newExc, "The native object does not exist.");
  170. return;
  171. }
  172. jmeBulletUtil::convertQuat(env, &body->getWorldTransform().getBasis(), value);
  173. }
  174. /*
  175. * Class: com_jme3_bullet_objects_PhysicsRigidBody
  176. * Method: getPhysicsRotationMatrix
  177. * Signature: (JLcom/jme3/math/Matrix3f;)V
  178. */
  179. JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_getPhysicsRotationMatrix
  180. (JNIEnv *env, jobject object, jlong bodyId, jobject value) {
  181. btRigidBody* body = reinterpret_cast<btRigidBody*>(bodyId);
  182. if (body == NULL) {
  183. jclass newExc = env->FindClass("java/lang/NullPointerException");
  184. env->ThrowNew(newExc, "The native object does not exist.");
  185. return;
  186. }
  187. jmeBulletUtil::convert(env, &body->getWorldTransform().getBasis(), value);
  188. }
  189. /*
  190. * Class: com_jme3_bullet_objects_PhysicsRigidBody
  191. * Method: setKinematic
  192. * Signature: (JZ)V
  193. */
  194. JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_setKinematic
  195. (JNIEnv *env, jobject object, jlong bodyId, jboolean value) {
  196. btRigidBody* body = reinterpret_cast<btRigidBody*>(bodyId);
  197. if (body == NULL) {
  198. jclass newExc = env->FindClass("java/lang/NullPointerException");
  199. env->ThrowNew(newExc, "The native object does not exist.");
  200. return;
  201. }
  202. if (value) {
  203. body->setCollisionFlags(body->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
  204. body->setActivationState(DISABLE_DEACTIVATION);
  205. } else {
  206. body->setCollisionFlags(body->getCollisionFlags() & ~btCollisionObject::CF_KINEMATIC_OBJECT);
  207. body->setActivationState(ACTIVE_TAG);
  208. }
  209. }
  210. /*
  211. * Class: com_jme3_bullet_objects_PhysicsRigidBody
  212. * Method: setCcdSweptSphereRadius
  213. * Signature: (JF)V
  214. */
  215. JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_setCcdSweptSphereRadius
  216. (JNIEnv *env, jobject object, jlong bodyId, jfloat value) {
  217. btRigidBody* body = reinterpret_cast<btRigidBody*>(bodyId);
  218. if (body == NULL) {
  219. jclass newExc = env->FindClass("java/lang/NullPointerException");
  220. env->ThrowNew(newExc, "The native object does not exist.");
  221. return;
  222. }
  223. body->setCcdSweptSphereRadius(value);
  224. }
  225. /*
  226. * Class: com_jme3_bullet_objects_PhysicsRigidBody
  227. * Method: setCcdMotionThreshold
  228. * Signature: (JF)V
  229. */
  230. JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_setCcdMotionThreshold
  231. (JNIEnv *env, jobject object, jlong bodyId, jfloat value) {
  232. btRigidBody* body = reinterpret_cast<btRigidBody*>(bodyId);
  233. if (body == NULL) {
  234. jclass newExc = env->FindClass("java/lang/NullPointerException");
  235. env->ThrowNew(newExc, "The native object does not exist.");
  236. return;
  237. }
  238. body->setCcdMotionThreshold(value);
  239. }
  240. /*
  241. * Class: com_jme3_bullet_objects_PhysicsRigidBody
  242. * Method: getCcdSweptSphereRadius
  243. * Signature: (J)F
  244. */
  245. JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_getCcdSweptSphereRadius
  246. (JNIEnv *env, jobject object, jlong bodyId) {
  247. btRigidBody* body = reinterpret_cast<btRigidBody*>(bodyId);
  248. if (body == NULL) {
  249. jclass newExc = env->FindClass("java/lang/NullPointerException");
  250. env->ThrowNew(newExc, "The native object does not exist.");
  251. return 0;
  252. }
  253. return body->getCcdSweptSphereRadius();
  254. }
  255. /*
  256. * Class: com_jme3_bullet_objects_PhysicsRigidBody
  257. * Method: getCcdMotionThreshold
  258. * Signature: (J)F
  259. */
  260. JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_getCcdMotionThreshold
  261. (JNIEnv *env, jobject object, jlong bodyId) {
  262. btRigidBody* body = reinterpret_cast<btRigidBody*>(bodyId);
  263. if (body == NULL) {
  264. jclass newExc = env->FindClass("java/lang/NullPointerException");
  265. env->ThrowNew(newExc, "The native object does not exist.");
  266. return 0;
  267. }
  268. return body->getCcdMotionThreshold();
  269. }
  270. /*
  271. * Class: com_jme3_bullet_objects_PhysicsRigidBody
  272. * Method: getCcdSquareMotionThreshold
  273. * Signature: (J)F
  274. */
  275. JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_getCcdSquareMotionThreshold
  276. (JNIEnv *env, jobject object, jlong bodyId) {
  277. btRigidBody* body = reinterpret_cast<btRigidBody*>(bodyId);
  278. if (body == NULL) {
  279. jclass newExc = env->FindClass("java/lang/NullPointerException");
  280. env->ThrowNew(newExc, "The native object does not exist.");
  281. return 0;
  282. }
  283. return body->getCcdSquareMotionThreshold();
  284. }
  285. /*
  286. * Class: com_jme3_bullet_objects_PhysicsRigidBody
  287. * Method: setStatic
  288. * Signature: (JZ)V
  289. */
  290. JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_setStatic
  291. (JNIEnv *env, jobject object, jlong bodyId, jboolean value) {
  292. btRigidBody* body = reinterpret_cast<btRigidBody*>(bodyId);
  293. if (body == NULL) {
  294. jclass newExc = env->FindClass("java/lang/NullPointerException");
  295. env->ThrowNew(newExc, "The native object does not exist.");
  296. return;
  297. }
  298. if (value) {
  299. body->setCollisionFlags(body->getCollisionFlags() | btCollisionObject::CF_STATIC_OBJECT);
  300. } else {
  301. body->setCollisionFlags(body->getCollisionFlags() & ~btCollisionObject::CF_STATIC_OBJECT);
  302. }
  303. }
  304. /*
  305. * Class: com_jme3_bullet_objects_PhysicsRigidBody
  306. * Method: updateMassProps
  307. * Signature: (JJF)J
  308. */
  309. JNIEXPORT jlong JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_updateMassProps
  310. (JNIEnv *env, jobject object, jlong bodyId, jlong shapeId, jfloat mass) {
  311. btRigidBody* body = reinterpret_cast<btRigidBody*>(bodyId);
  312. if (body == NULL) {
  313. jclass newExc = env->FindClass("java/lang/NullPointerException");
  314. env->ThrowNew(newExc, "The native object does not exist.");
  315. return 0;
  316. }
  317. btCollisionShape* shape = reinterpret_cast<btCollisionShape*>(shapeId);
  318. btVector3 localInertia = btVector3();
  319. shape->calculateLocalInertia(mass, localInertia);
  320. body->setMassProps(mass, localInertia);
  321. return reinterpret_cast<jlong>(body);
  322. }
  323. /*
  324. * Class: com_jme3_bullet_objects_PhysicsRigidBody
  325. * Method: getGravity
  326. * Signature: (JLcom/jme3/math/Vector3f;)V
  327. */
  328. JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_getGravity
  329. (JNIEnv *env, jobject object, jlong bodyId, jobject value) {
  330. btRigidBody* body = reinterpret_cast<btRigidBody*>(bodyId);
  331. if (body == NULL) {
  332. jclass newExc = env->FindClass("java/lang/NullPointerException");
  333. env->ThrowNew(newExc, "The native object does not exist.");
  334. return;
  335. }
  336. jmeBulletUtil::convert(env, &body->getGravity(), value);
  337. }
  338. /*
  339. * Class: com_jme3_bullet_objects_PhysicsRigidBody
  340. * Method: setGravity
  341. * Signature: (JLcom/jme3/math/Vector3f;)V
  342. */
  343. JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_setGravity
  344. (JNIEnv *env, jobject object, jlong bodyId, jobject value) {
  345. btRigidBody* body = reinterpret_cast<btRigidBody*>(bodyId);
  346. if (body == NULL) {
  347. jclass newExc = env->FindClass("java/lang/NullPointerException");
  348. env->ThrowNew(newExc, "The native object does not exist.");
  349. return;
  350. }
  351. btVector3 vec = btVector3();
  352. jmeBulletUtil::convert(env, value, &vec);
  353. body->setGravity(vec);
  354. }
  355. /*
  356. * Class: com_jme3_bullet_objects_PhysicsRigidBody
  357. * Method: getFriction
  358. * Signature: (J)F
  359. */
  360. JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_getFriction
  361. (JNIEnv *env, jobject object, jlong bodyId) {
  362. btRigidBody* body = reinterpret_cast<btRigidBody*>(bodyId);
  363. if (body == NULL) {
  364. jclass newExc = env->FindClass("java/lang/NullPointerException");
  365. env->ThrowNew(newExc, "The native object does not exist.");
  366. return 0;
  367. }
  368. return body->getFriction();
  369. }
  370. /*
  371. * Class: com_jme3_bullet_objects_PhysicsRigidBody
  372. * Method: setFriction
  373. * Signature: (JF)V
  374. */
  375. JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_setFriction
  376. (JNIEnv *env, jobject object, jlong bodyId, jfloat value) {
  377. btRigidBody* body = reinterpret_cast<btRigidBody*>(bodyId);
  378. if (body == NULL) {
  379. jclass newExc = env->FindClass("java/lang/NullPointerException");
  380. env->ThrowNew(newExc, "The native object does not exist.");
  381. return;
  382. }
  383. body->setFriction(value);
  384. }
  385. /*
  386. * Class: com_jme3_bullet_objects_PhysicsRigidBody
  387. * Method: setDamping
  388. * Signature: (JFF)V
  389. */
  390. JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_setDamping
  391. (JNIEnv *env, jobject object, jlong bodyId, jfloat value1, jfloat value2) {
  392. btRigidBody* body = reinterpret_cast<btRigidBody*>(bodyId);
  393. if (body == NULL) {
  394. jclass newExc = env->FindClass("java/lang/NullPointerException");
  395. env->ThrowNew(newExc, "The native object does not exist.");
  396. return;
  397. }
  398. body->setDamping(value1, value2);
  399. }
  400. /*
  401. * Class: com_jme3_bullet_objects_PhysicsRigidBody
  402. * Method: setAngularDamping
  403. * Signature: (JF)V
  404. */
  405. JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_setAngularDamping
  406. (JNIEnv *env, jobject object, jlong bodyId, jfloat value) {
  407. btRigidBody* body = reinterpret_cast<btRigidBody*>(bodyId);
  408. if (body == NULL) {
  409. jclass newExc = env->FindClass("java/lang/NullPointerException");
  410. env->ThrowNew(newExc, "The native object does not exist.");
  411. return;
  412. }
  413. body->setDamping(body->getAngularDamping(), value);
  414. }
  415. /*
  416. * Class: com_jme3_bullet_objects_PhysicsRigidBody
  417. * Method: getLinearDamping
  418. * Signature: (J)F
  419. */
  420. JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_getLinearDamping
  421. (JNIEnv *env, jobject object, jlong bodyId) {
  422. btRigidBody* body = reinterpret_cast<btRigidBody*>(bodyId);
  423. if (body == NULL) {
  424. jclass newExc = env->FindClass("java/lang/NullPointerException");
  425. env->ThrowNew(newExc, "The native object does not exist.");
  426. return 0;
  427. }
  428. return body->getLinearDamping();
  429. }
  430. /*
  431. * Class: com_jme3_bullet_objects_PhysicsRigidBody
  432. * Method: getAngularDamping
  433. * Signature: (J)F
  434. */
  435. JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_getAngularDamping
  436. (JNIEnv *env, jobject object, jlong bodyId) {
  437. btRigidBody* body = reinterpret_cast<btRigidBody*>(bodyId);
  438. if (body == NULL) {
  439. jclass newExc = env->FindClass("java/lang/NullPointerException");
  440. env->ThrowNew(newExc, "The native object does not exist.");
  441. return 0;
  442. }
  443. return body->getAngularDamping();
  444. }
  445. /*
  446. * Class: com_jme3_bullet_objects_PhysicsRigidBody
  447. * Method: getRestitution
  448. * Signature: (J)F
  449. */
  450. JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_getRestitution
  451. (JNIEnv *env, jobject object, jlong bodyId) {
  452. btRigidBody* body = reinterpret_cast<btRigidBody*>(bodyId);
  453. if (body == NULL) {
  454. jclass newExc = env->FindClass("java/lang/NullPointerException");
  455. env->ThrowNew(newExc, "The native object does not exist.");
  456. return 0;
  457. }
  458. return body->getRestitution();
  459. }
  460. /*
  461. * Class: com_jme3_bullet_objects_PhysicsRigidBody
  462. * Method: setRestitution
  463. * Signature: (JF)V
  464. */
  465. JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_setRestitution
  466. (JNIEnv *env, jobject object, jlong bodyId, jfloat value) {
  467. btRigidBody* body = reinterpret_cast<btRigidBody*>(bodyId);
  468. if (body == NULL) {
  469. jclass newExc = env->FindClass("java/lang/NullPointerException");
  470. env->ThrowNew(newExc, "The native object does not exist.");
  471. return;
  472. }
  473. body->setRestitution(value);
  474. }
  475. /*
  476. * Class: com_jme3_bullet_objects_PhysicsRigidBody
  477. * Method: getAngularVelocity
  478. * Signature: (JLcom/jme3/math/Vector3f;)V
  479. */
  480. JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_getAngularVelocity
  481. (JNIEnv *env, jobject object, jlong bodyId, jobject value) {
  482. btRigidBody* body = reinterpret_cast<btRigidBody*>(bodyId);
  483. if (body == NULL) {
  484. jclass newExc = env->FindClass("java/lang/NullPointerException");
  485. env->ThrowNew(newExc, "The native object does not exist.");
  486. return;
  487. }
  488. jmeBulletUtil::convert(env, &body->getAngularVelocity(), value);
  489. }
  490. /*
  491. * Class: com_jme3_bullet_objects_PhysicsRigidBody
  492. * Method: setAngularVelocity
  493. * Signature: (JLcom/jme3/math/Vector3f;)V
  494. */
  495. JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_setAngularVelocity
  496. (JNIEnv *env, jobject object, jlong bodyId, jobject value) {
  497. btRigidBody* body = reinterpret_cast<btRigidBody*>(bodyId);
  498. if (body == NULL) {
  499. jclass newExc = env->FindClass("java/lang/NullPointerException");
  500. env->ThrowNew(newExc, "The native object does not exist.");
  501. return;
  502. }
  503. btVector3 vec = btVector3();
  504. jmeBulletUtil::convert(env, value, &vec);
  505. body->setAngularVelocity(vec);
  506. }
  507. /*
  508. * Class: com_jme3_bullet_objects_PhysicsRigidBody
  509. * Method: getLinearVelocity
  510. * Signature: (JLcom/jme3/math/Vector3f;)V
  511. */
  512. JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_getLinearVelocity
  513. (JNIEnv *env, jobject object, jlong bodyId, jobject value) {
  514. btRigidBody* body = reinterpret_cast<btRigidBody*>(bodyId);
  515. if (body == NULL) {
  516. jclass newExc = env->FindClass("java/lang/NullPointerException");
  517. env->ThrowNew(newExc, "The native object does not exist.");
  518. return;
  519. }
  520. jmeBulletUtil::convert(env, &body->getLinearVelocity(), value);
  521. }
  522. /*
  523. * Class: com_jme3_bullet_objects_PhysicsRigidBody
  524. * Method: setLinearVelocity
  525. * Signature: (JLcom/jme3/math/Vector3f;)V
  526. */
  527. JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_setLinearVelocity
  528. (JNIEnv *env, jobject object, jlong bodyId, jobject value) {
  529. btRigidBody* body = reinterpret_cast<btRigidBody*>(bodyId);
  530. if (body == NULL) {
  531. jclass newExc = env->FindClass("java/lang/NullPointerException");
  532. env->ThrowNew(newExc, "The native object does not exist.");
  533. return;
  534. }
  535. btVector3 vec = btVector3();
  536. jmeBulletUtil::convert(env, value, &vec);
  537. body->setLinearVelocity(vec);
  538. }
  539. /*
  540. * Class: com_jme3_bullet_objects_PhysicsRigidBody
  541. * Method: applyForce
  542. * Signature: (JLcom/jme3/math/Vector3f;Lcom/jme3/math/Vector3f;)V
  543. */
  544. JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_applyForce
  545. (JNIEnv *env, jobject object, jlong bodyId, jobject force, jobject location) {
  546. btRigidBody* body = reinterpret_cast<btRigidBody*>(bodyId);
  547. if (body == NULL) {
  548. jclass newExc = env->FindClass("java/lang/NullPointerException");
  549. env->ThrowNew(newExc, "The native object does not exist.");
  550. return;
  551. }
  552. btVector3 vec1 = btVector3();
  553. btVector3 vec2 = btVector3();
  554. jmeBulletUtil::convert(env, force, &vec1);
  555. jmeBulletUtil::convert(env, location, &vec2);
  556. body->applyForce(vec1, vec2);
  557. }
  558. /*
  559. * Class: com_jme3_bullet_objects_PhysicsRigidBody
  560. * Method: applyCentralForce
  561. * Signature: (JLcom/jme3/math/Vector3f;)V
  562. */
  563. JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_applyCentralForce
  564. (JNIEnv *env, jobject object, jlong bodyId, jobject force) {
  565. btRigidBody* body = reinterpret_cast<btRigidBody*>(bodyId);
  566. if (body == NULL) {
  567. jclass newExc = env->FindClass("java/lang/NullPointerException");
  568. env->ThrowNew(newExc, "The native object does not exist.");
  569. return;
  570. }
  571. btVector3 vec1 = btVector3();
  572. jmeBulletUtil::convert(env, force, &vec1);
  573. body->applyCentralForce(vec1);
  574. }
  575. /*
  576. * Class: com_jme3_bullet_objects_PhysicsRigidBody
  577. * Method: applyTorque
  578. * Signature: (JLcom/jme3/math/Vector3f;)V
  579. */
  580. JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_applyTorque
  581. (JNIEnv *env, jobject object, jlong bodyId, jobject force) {
  582. btRigidBody* body = reinterpret_cast<btRigidBody*>(bodyId);
  583. if (body == NULL) {
  584. jclass newExc = env->FindClass("java/lang/NullPointerException");
  585. env->ThrowNew(newExc, "The native object does not exist.");
  586. return;
  587. }
  588. btVector3 vec1 = btVector3();
  589. jmeBulletUtil::convert(env, force, &vec1);
  590. body->applyTorque(vec1);
  591. }
  592. /*
  593. * Class: com_jme3_bullet_objects_PhysicsRigidBody
  594. * Method: applyImpulse
  595. * Signature: (JLcom/jme3/math/Vector3f;Lcom/jme3/math/Vector3f;)V
  596. */
  597. JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_applyImpulse
  598. (JNIEnv *env, jobject object, jlong bodyId, jobject force, jobject location) {
  599. btRigidBody* body = reinterpret_cast<btRigidBody*>(bodyId);
  600. if (body == NULL) {
  601. jclass newExc = env->FindClass("java/lang/NullPointerException");
  602. env->ThrowNew(newExc, "The native object does not exist.");
  603. return;
  604. }
  605. btVector3 vec1 = btVector3();
  606. btVector3 vec2 = btVector3();
  607. jmeBulletUtil::convert(env, force, &vec1);
  608. jmeBulletUtil::convert(env, location, &vec2);
  609. body->applyImpulse(vec1, vec2);
  610. }
  611. /*
  612. * Class: com_jme3_bullet_objects_PhysicsRigidBody
  613. * Method: applyTorqueImpulse
  614. * Signature: (JLcom/jme3/math/Vector3f;)V
  615. */
  616. JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_applyTorqueImpulse
  617. (JNIEnv *env, jobject object, jlong bodyId, jobject force) {
  618. btRigidBody* body = reinterpret_cast<btRigidBody*>(bodyId);
  619. if (body == NULL) {
  620. jclass newExc = env->FindClass("java/lang/NullPointerException");
  621. env->ThrowNew(newExc, "The native object does not exist.");
  622. return;
  623. }
  624. btVector3 vec1 = btVector3();
  625. jmeBulletUtil::convert(env, force, &vec1);
  626. body->applyTorqueImpulse(vec1);
  627. }
  628. /*
  629. * Class: com_jme3_bullet_objects_PhysicsRigidBody
  630. * Method: clearForces
  631. * Signature: (J)V
  632. */
  633. JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_clearForces
  634. (JNIEnv *env, jobject object, jlong bodyId) {
  635. btRigidBody* body = reinterpret_cast<btRigidBody*>(bodyId);
  636. if (body == NULL) {
  637. jclass newExc = env->FindClass("java/lang/NullPointerException");
  638. env->ThrowNew(newExc, "The native object does not exist.");
  639. return;
  640. }
  641. body->clearForces();
  642. }
  643. /*
  644. * Class: com_jme3_bullet_objects_PhysicsRigidBody
  645. * Method: setCollisionShape
  646. * Signature: (JJ)V
  647. */
  648. JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_setCollisionShape
  649. (JNIEnv *env, jobject object, jlong bodyId, jlong shapeId) {
  650. btRigidBody* body = reinterpret_cast<btRigidBody*>(bodyId);
  651. if (body == NULL) {
  652. jclass newExc = env->FindClass("java/lang/NullPointerException");
  653. env->ThrowNew(newExc, "The native object does not exist.");
  654. return;
  655. }
  656. btCollisionShape* shape = reinterpret_cast<btCollisionShape*>(shapeId);
  657. body->setCollisionShape(shape);
  658. }
  659. /*
  660. * Class: com_jme3_bullet_objects_PhysicsRigidBody
  661. * Method: activate
  662. * Signature: (J)V
  663. */
  664. JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_activate
  665. (JNIEnv *env, jobject object, jlong bodyId) {
  666. btRigidBody* body = reinterpret_cast<btRigidBody*>(bodyId);
  667. if (body == NULL) {
  668. jclass newExc = env->FindClass("java/lang/NullPointerException");
  669. env->ThrowNew(newExc, "The native object does not exist.");
  670. return;
  671. }
  672. body->activate(false);
  673. }
  674. /*
  675. * Class: com_jme3_bullet_objects_PhysicsRigidBody
  676. * Method: isActive
  677. * Signature: (J)Z
  678. */
  679. JNIEXPORT jboolean JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_isActive
  680. (JNIEnv *env, jobject object, jlong bodyId) {
  681. btRigidBody* body = reinterpret_cast<btRigidBody*>(bodyId);
  682. if (body == NULL) {
  683. jclass newExc = env->FindClass("java/lang/NullPointerException");
  684. env->ThrowNew(newExc, "The native object does not exist.");
  685. return false;
  686. }
  687. return body->isActive();
  688. }
  689. /*
  690. * Class: com_jme3_bullet_objects_PhysicsRigidBody
  691. * Method: setSleepingThresholds
  692. * Signature: (JFF)V
  693. */
  694. JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_setSleepingThresholds
  695. (JNIEnv *env, jobject object, jlong bodyId, jfloat linear, jfloat angular) {
  696. btRigidBody* body = reinterpret_cast<btRigidBody*>(bodyId);
  697. if (body == NULL) {
  698. jclass newExc = env->FindClass("java/lang/NullPointerException");
  699. env->ThrowNew(newExc, "The native object does not exist.");
  700. return;
  701. }
  702. body->setSleepingThresholds(linear, angular);
  703. }
  704. /*
  705. * Class: com_jme3_bullet_objects_PhysicsRigidBody
  706. * Method: setLinearSleepingThreshold
  707. * Signature: (JF)V
  708. */
  709. JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_setLinearSleepingThreshold
  710. (JNIEnv *env, jobject object, jlong bodyId, jfloat value) {
  711. btRigidBody* body = reinterpret_cast<btRigidBody*>(bodyId);
  712. if (body == NULL) {
  713. jclass newExc = env->FindClass("java/lang/NullPointerException");
  714. env->ThrowNew(newExc, "The native object does not exist.");
  715. return;
  716. }
  717. body->setSleepingThresholds(value, body->getLinearSleepingThreshold());
  718. }
  719. /*
  720. * Class: com_jme3_bullet_objects_PhysicsRigidBody
  721. * Method: setAngularSleepingThreshold
  722. * Signature: (JF)V
  723. */
  724. JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_setAngularSleepingThreshold
  725. (JNIEnv *env, jobject object, jlong bodyId, jfloat value) {
  726. btRigidBody* body = reinterpret_cast<btRigidBody*>(bodyId);
  727. if (body == NULL) {
  728. jclass newExc = env->FindClass("java/lang/NullPointerException");
  729. env->ThrowNew(newExc, "The native object does not exist.");
  730. return;
  731. }
  732. body->setSleepingThresholds(body->getAngularSleepingThreshold(), value);
  733. }
  734. /*
  735. * Class: com_jme3_bullet_objects_PhysicsRigidBody
  736. * Method: getLinearSleepingThreshold
  737. * Signature: (J)F
  738. */
  739. JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_getLinearSleepingThreshold
  740. (JNIEnv *env, jobject object, jlong bodyId) {
  741. btRigidBody* body = reinterpret_cast<btRigidBody*>(bodyId);
  742. if (body == NULL) {
  743. jclass newExc = env->FindClass("java/lang/NullPointerException");
  744. env->ThrowNew(newExc, "The native object does not exist.");
  745. return 0;
  746. }
  747. return body->getLinearSleepingThreshold();
  748. }
  749. /*
  750. * Class: com_jme3_bullet_objects_PhysicsRigidBody
  751. * Method: getAngularSleepingThreshold
  752. * Signature: (J)F
  753. */
  754. JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_getAngularSleepingThreshold
  755. (JNIEnv *env, jobject object, jlong bodyId) {
  756. btRigidBody* body = reinterpret_cast<btRigidBody*>(bodyId);
  757. if (body == NULL) {
  758. jclass newExc = env->FindClass("java/lang/NullPointerException");
  759. env->ThrowNew(newExc, "The native object does not exist.");
  760. return 0;
  761. }
  762. return body->getAngularSleepingThreshold();
  763. }
  764. /*
  765. * Class: com_jme3_bullet_objects_PhysicsRigidBody
  766. * Method: getAngularFactor
  767. * Signature: (J)F
  768. */
  769. JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_getAngularFactor
  770. (JNIEnv *env, jobject object, jlong bodyId) {
  771. btRigidBody* body = reinterpret_cast<btRigidBody*>(bodyId);
  772. if (body == NULL) {
  773. jclass newExc = env->FindClass("java/lang/NullPointerException");
  774. env->ThrowNew(newExc, "The native object does not exist.");
  775. return 0;
  776. }
  777. return body->getAngularFactor().getX();
  778. }
  779. /*
  780. * Class: com_jme3_bullet_objects_PhysicsRigidBody
  781. * Method: setAngularFactor
  782. * Signature: (JF)V
  783. */
  784. JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_setAngularFactor
  785. (JNIEnv *env, jobject object, jlong bodyId, jfloat value) {
  786. btRigidBody* body = reinterpret_cast<btRigidBody*>(bodyId);
  787. if (body == NULL) {
  788. jclass newExc = env->FindClass("java/lang/NullPointerException");
  789. env->ThrowNew(newExc, "The native object does not exist.");
  790. return;
  791. }
  792. btVector3 vec1 = btVector3();
  793. vec1.setX(value);
  794. vec1.setY(value);
  795. vec1.setZ(value);
  796. body->setAngularFactor(vec1);
  797. }
  798. #ifdef __cplusplus
  799. }
  800. #endif