com_jme3_bullet_objects_PhysicsGhostObject.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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 <BulletCollision/CollisionDispatch/btGhostObject.h>
  36. #include "com_jme3_bullet_objects_PhysicsGhostObject.h"
  37. #include "jmeBulletUtil.h"
  38. #ifdef __cplusplus
  39. extern "C" {
  40. #endif
  41. /*
  42. * Class: com_jme3_bullet_objects_PhysicsGhostObject
  43. * Method: createGhostObject
  44. * Signature: ()J
  45. */
  46. JNIEXPORT jlong JNICALL Java_com_jme3_bullet_objects_PhysicsGhostObject_createGhostObject
  47. (JNIEnv * env, jobject object) {
  48. jmeClasses::initJavaClasses(env);
  49. btPairCachingGhostObject* ghost = new btPairCachingGhostObject();
  50. return (long) ghost;
  51. }
  52. /*
  53. * Class: com_jme3_bullet_objects_PhysicsGhostObject
  54. * Method: setGhostFlags
  55. * Signature: (J)V
  56. */
  57. JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsGhostObject_setGhostFlags
  58. (JNIEnv *env, jobject object, jlong objectId) {
  59. btPairCachingGhostObject* ghost = (btPairCachingGhostObject*) objectId;
  60. if (ghost == NULL) {
  61. jclass newExc = env->FindClass("java/lang/NullPointerException");
  62. env->ThrowNew(newExc, "The native object does not exist.");
  63. return;
  64. }
  65. ghost->setCollisionFlags(ghost->getCollisionFlags() | btCollisionObject::CF_NO_CONTACT_RESPONSE);
  66. }
  67. /*
  68. * Class: com_jme3_bullet_objects_PhysicsGhostObject
  69. * Method: setPhysicsLocation
  70. * Signature: (JLcom/jme3/math/Vector3f;)V
  71. */
  72. JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsGhostObject_setPhysicsLocation
  73. (JNIEnv *env, jobject object, jlong objectId, jobject value) {
  74. btPairCachingGhostObject* ghost = (btPairCachingGhostObject*) objectId;
  75. if (ghost == NULL) {
  76. jclass newExc = env->FindClass("java/lang/NullPointerException");
  77. env->ThrowNew(newExc, "The native object does not exist.");
  78. return;
  79. }
  80. jmeBulletUtil::convert(env, value, &ghost->getWorldTransform().getOrigin());
  81. }
  82. /*
  83. * Class: com_jme3_bullet_objects_PhysicsGhostObject
  84. * Method: setPhysicsRotation
  85. * Signature: (JLcom/jme3/math/Matrix3f;)V
  86. */
  87. JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsGhostObject_setPhysicsRotation__JLcom_jme3_math_Matrix3f_2
  88. (JNIEnv *env, jobject object, jlong objectId, jobject value) {
  89. btPairCachingGhostObject* ghost = (btPairCachingGhostObject*) objectId;
  90. if (ghost == NULL) {
  91. jclass newExc = env->FindClass("java/lang/NullPointerException");
  92. env->ThrowNew(newExc, "The native object does not exist.");
  93. return;
  94. }
  95. jmeBulletUtil::convert(env, value, &ghost->getWorldTransform().getBasis());
  96. }
  97. /*
  98. * Class: com_jme3_bullet_objects_PhysicsGhostObject
  99. * Method: setPhysicsRotation
  100. * Signature: (JLcom/jme3/math/Quaternion;)V
  101. */
  102. JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsGhostObject_setPhysicsRotation__JLcom_jme3_math_Quaternion_2
  103. (JNIEnv *env, jobject object, jlong objectId, jobject value) {
  104. btPairCachingGhostObject* ghost = (btPairCachingGhostObject*) objectId;
  105. if (ghost == NULL) {
  106. jclass newExc = env->FindClass("java/lang/NullPointerException");
  107. env->ThrowNew(newExc, "The native object does not exist.");
  108. return;
  109. }
  110. jmeBulletUtil::convertQuat(env, value, &ghost->getWorldTransform().getBasis());
  111. }
  112. /*
  113. * Class: com_jme3_bullet_objects_PhysicsGhostObject
  114. * Method: getPhysicsLocation
  115. * Signature: (JLcom/jme3/math/Vector3f;)V
  116. */
  117. JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsGhostObject_getPhysicsLocation
  118. (JNIEnv *env, jobject object, jlong objectId, jobject value) {
  119. btPairCachingGhostObject* ghost = (btPairCachingGhostObject*) objectId;
  120. if (ghost == NULL) {
  121. jclass newExc = env->FindClass("java/lang/NullPointerException");
  122. env->ThrowNew(newExc, "The native object does not exist.");
  123. return;
  124. }
  125. jmeBulletUtil::convert(env, &ghost->getWorldTransform().getOrigin(), value);
  126. }
  127. /*
  128. * Class: com_jme3_bullet_objects_PhysicsGhostObject
  129. * Method: getPhysicsRotation
  130. * Signature: (JLcom/jme3/math/Quaternion;)V
  131. */
  132. JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsGhostObject_getPhysicsRotation
  133. (JNIEnv *env, jobject object, jlong objectId, jobject value) {
  134. btPairCachingGhostObject* ghost = (btPairCachingGhostObject*) objectId;
  135. if (ghost == NULL) {
  136. jclass newExc = env->FindClass("java/lang/NullPointerException");
  137. env->ThrowNew(newExc, "The native object does not exist.");
  138. return;
  139. }
  140. jmeBulletUtil::convertQuat(env, &ghost->getWorldTransform().getBasis(), value);
  141. }
  142. /*
  143. * Class: com_jme3_bullet_objects_PhysicsGhostObject
  144. * Method: getPhysicsRotationMatrix
  145. * Signature: (JLcom/jme3/math/Matrix3f;)V
  146. */
  147. JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsGhostObject_getPhysicsRotationMatrix
  148. (JNIEnv *env, jobject object, jlong objectId, jobject value) {
  149. btPairCachingGhostObject* ghost = (btPairCachingGhostObject*) objectId;
  150. if (ghost == NULL) {
  151. jclass newExc = env->FindClass("java/lang/NullPointerException");
  152. env->ThrowNew(newExc, "The native object does not exist.");
  153. return;
  154. }
  155. jmeBulletUtil::convert(env, &ghost->getWorldTransform().getBasis(), value);
  156. }
  157. /*
  158. * Class: com_jme3_bullet_objects_PhysicsGhostObject
  159. * Method: getOverlappingCount
  160. * Signature: (J)I
  161. */
  162. JNIEXPORT jint JNICALL Java_com_jme3_bullet_objects_PhysicsGhostObject_getOverlappingCount
  163. (JNIEnv *env, jobject object, jlong objectId) {
  164. btPairCachingGhostObject* ghost = (btPairCachingGhostObject*) objectId;
  165. if (ghost == NULL) {
  166. jclass newExc = env->FindClass("java/lang/NullPointerException");
  167. env->ThrowNew(newExc, "The native object does not exist.");
  168. return 0;
  169. }
  170. return ghost->getNumOverlappingObjects();
  171. }
  172. /*
  173. * Class: com_jme3_bullet_objects_PhysicsGhostObject
  174. * Method: setCcdSweptSphereRadius
  175. * Signature: (JF)V
  176. */
  177. JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsGhostObject_setCcdSweptSphereRadius
  178. (JNIEnv *env, jobject object, jlong objectId, jfloat value) {
  179. btPairCachingGhostObject* ghost = (btPairCachingGhostObject*) objectId;
  180. if (ghost == NULL) {
  181. jclass newExc = env->FindClass("java/lang/NullPointerException");
  182. env->ThrowNew(newExc, "The native object does not exist.");
  183. return;
  184. }
  185. ghost->setCcdSweptSphereRadius(value);
  186. }
  187. /*
  188. * Class: com_jme3_bullet_objects_PhysicsGhostObject
  189. * Method: setCcdMotionThreshold
  190. * Signature: (JF)V
  191. */
  192. JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsGhostObject_setCcdMotionThreshold
  193. (JNIEnv *env, jobject object, jlong objectId, jfloat value) {
  194. btPairCachingGhostObject* ghost = (btPairCachingGhostObject*) objectId;
  195. if (ghost == NULL) {
  196. jclass newExc = env->FindClass("java/lang/NullPointerException");
  197. env->ThrowNew(newExc, "The native object does not exist.");
  198. return;
  199. }
  200. ghost->setCcdMotionThreshold(value);
  201. }
  202. /*
  203. * Class: com_jme3_bullet_objects_PhysicsGhostObject
  204. * Method: getCcdSweptSphereRadius
  205. * Signature: (J)F
  206. */
  207. JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_objects_PhysicsGhostObject_getCcdSweptSphereRadius
  208. (JNIEnv *env, jobject object, jlong objectId) {
  209. btPairCachingGhostObject* ghost = (btPairCachingGhostObject*) objectId;
  210. if (ghost == NULL) {
  211. jclass newExc = env->FindClass("java/lang/NullPointerException");
  212. env->ThrowNew(newExc, "The native object does not exist.");
  213. return 0;
  214. }
  215. return ghost->getCcdSweptSphereRadius();
  216. }
  217. /*
  218. * Class: com_jme3_bullet_objects_PhysicsGhostObject
  219. * Method: getCcdMotionThreshold
  220. * Signature: (J)F
  221. */
  222. JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_objects_PhysicsGhostObject_getCcdMotionThreshold
  223. (JNIEnv *env, jobject object, jlong objectId) {
  224. btPairCachingGhostObject* ghost = (btPairCachingGhostObject*) objectId;
  225. if (ghost == NULL) {
  226. jclass newExc = env->FindClass("java/lang/NullPointerException");
  227. env->ThrowNew(newExc, "The native object does not exist.");
  228. return 0;
  229. }
  230. return ghost->getCcdMotionThreshold();
  231. }
  232. /*
  233. * Class: com_jme3_bullet_objects_PhysicsGhostObject
  234. * Method: getCcdSquareMotionThreshold
  235. * Signature: (J)F
  236. */
  237. JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_objects_PhysicsGhostObject_getCcdSquareMotionThreshold
  238. (JNIEnv *env, jobject object, jlong objectId) {
  239. btPairCachingGhostObject* ghost = (btPairCachingGhostObject*) objectId;
  240. if (ghost == NULL) {
  241. jclass newExc = env->FindClass("java/lang/NullPointerException");
  242. env->ThrowNew(newExc, "The native object does not exist.");
  243. return 0;
  244. }
  245. return ghost->getCcdSquareMotionThreshold();
  246. }
  247. #ifdef __cplusplus
  248. }
  249. #endif