com_jme3_bullet_objects_VehicleWheel.cpp 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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_VehicleWheel.h"
  36. #include "jmeBulletUtil.h"
  37. #ifdef __cplusplus
  38. extern "C" {
  39. #endif
  40. /*
  41. * Class: com_jme3_bullet_objects_VehicleWheel
  42. * Method: getWheelLocation
  43. * Signature: (JLcom/jme3/math/Vector3f;)V
  44. */
  45. JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_VehicleWheel_getWheelLocation
  46. (JNIEnv *env, jobject object, jlong vehicleId, jint wheelIndex, jobject out) {
  47. btRaycastVehicle* vehicle = reinterpret_cast<btRaycastVehicle*>(vehicleId);
  48. if (vehicle == NULL) {
  49. jclass newExc = env->FindClass("java/lang/NullPointerException");
  50. env->ThrowNew(newExc, "The native object does not exist.");
  51. return;
  52. }
  53. jmeBulletUtil::convert(env, &vehicle->getWheelInfo(wheelIndex).m_worldTransform.getOrigin(), out);
  54. }
  55. /*
  56. * Class: com_jme3_bullet_objects_VehicleWheel
  57. * Method: getWheelRotation
  58. * Signature: (JLcom/jme3/math/Matrix3f;)V
  59. */
  60. JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_VehicleWheel_getWheelRotation
  61. (JNIEnv *env, jobject object, jlong vehicleId, jint wheelIndex, jobject out) {
  62. btRaycastVehicle* vehicle = reinterpret_cast<btRaycastVehicle*>(vehicleId);
  63. if (vehicle == NULL) {
  64. jclass newExc = env->FindClass("java/lang/NullPointerException");
  65. env->ThrowNew(newExc, "The native object does not exist.");
  66. return;
  67. }
  68. jmeBulletUtil::convert(env, &vehicle->getWheelInfo(wheelIndex).m_worldTransform.getBasis(), out);
  69. }
  70. /*
  71. * Class: com_jme3_bullet_objects_VehicleWheel
  72. * Method: applyInfo
  73. * Signature: (JFFFFFFFFZF)V
  74. */
  75. JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_VehicleWheel_applyInfo
  76. (JNIEnv *env, jobject object, jlong vehicleId, jint wheelIndex, jfloat suspensionStiffness, jfloat wheelsDampingRelaxation, jfloat wheelsDampingCompression, jfloat frictionSlip, jfloat rollInfluence, jfloat maxSuspensionTravelCm, jfloat maxSuspensionForce, jfloat radius, jboolean frontWheel, jfloat restLength) {
  77. btRaycastVehicle* vehicle = reinterpret_cast<btRaycastVehicle*>(vehicleId);
  78. vehicle->getWheelInfo(wheelIndex).m_suspensionStiffness = suspensionStiffness;
  79. vehicle->getWheelInfo(wheelIndex).m_wheelsDampingRelaxation = wheelsDampingRelaxation;
  80. vehicle->getWheelInfo(wheelIndex).m_wheelsDampingCompression = wheelsDampingCompression;
  81. vehicle->getWheelInfo(wheelIndex).m_frictionSlip = frictionSlip;
  82. vehicle->getWheelInfo(wheelIndex).m_rollInfluence = rollInfluence;
  83. vehicle->getWheelInfo(wheelIndex).m_maxSuspensionTravelCm = maxSuspensionTravelCm;
  84. vehicle->getWheelInfo(wheelIndex).m_maxSuspensionForce = maxSuspensionForce;
  85. vehicle->getWheelInfo(wheelIndex).m_wheelsRadius = radius;
  86. vehicle->getWheelInfo(wheelIndex).m_bIsFrontWheel = frontWheel;
  87. vehicle->getWheelInfo(wheelIndex).m_suspensionRestLength1 = restLength;
  88. }
  89. /*
  90. * Class: com_jme3_bullet_objects_VehicleWheel
  91. * Method: getCollisionLocation
  92. * Signature: (JLcom/jme3/math/Vector3f;)V
  93. */
  94. JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_VehicleWheel_getCollisionLocation
  95. (JNIEnv *env, jobject object, jlong vehicleId, jint wheelIndex, jobject out) {
  96. btRaycastVehicle* vehicle = reinterpret_cast<btRaycastVehicle*>(vehicleId);
  97. if (vehicle == NULL) {
  98. jclass newExc = env->FindClass("java/lang/NullPointerException");
  99. env->ThrowNew(newExc, "The native object does not exist.");
  100. return;
  101. }
  102. jmeBulletUtil::convert(env, &vehicle->getWheelInfo(wheelIndex).m_raycastInfo.m_contactPointWS, out);
  103. }
  104. /*
  105. * Class: com_jme3_bullet_objects_VehicleWheel
  106. * Method: getCollisionNormal
  107. * Signature: (JLcom/jme3/math/Vector3f;)V
  108. */
  109. JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_VehicleWheel_getCollisionNormal
  110. (JNIEnv *env, jobject object, jlong vehicleId, jint wheelIndex, jobject out) {
  111. btRaycastVehicle* vehicle = reinterpret_cast<btRaycastVehicle*>(vehicleId);
  112. if (vehicle == NULL) {
  113. jclass newExc = env->FindClass("java/lang/NullPointerException");
  114. env->ThrowNew(newExc, "The native object does not exist.");
  115. return;
  116. }
  117. jmeBulletUtil::convert(env, &vehicle->getWheelInfo(wheelIndex).m_raycastInfo.m_contactNormalWS, out);
  118. }
  119. /*
  120. * Class: com_jme3_bullet_objects_VehicleWheel
  121. * Method: getSkidInfo
  122. * Signature: (J)F
  123. */
  124. JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_objects_VehicleWheel_getSkidInfo
  125. (JNIEnv *env, jobject object, jlong vehicleId, jint wheelIndex) {
  126. btRaycastVehicle* vehicle = reinterpret_cast<btRaycastVehicle*>(vehicleId);
  127. if (vehicle == NULL) {
  128. jclass newExc = env->FindClass("java/lang/NullPointerException");
  129. env->ThrowNew(newExc, "The native object does not exist.");
  130. return 0;
  131. }
  132. return vehicle->getWheelInfo(wheelIndex).m_skidInfo;
  133. }
  134. /*
  135. * Class: com_jme3_bullet_objects_VehicleWheel
  136. * Method: getDeltaRotation
  137. * Signature: (J)F
  138. */
  139. JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_objects_VehicleWheel_getDeltaRotation
  140. (JNIEnv *env, jobject object, jlong vehicleId, jint wheelIndex) {
  141. btRaycastVehicle* vehicle = reinterpret_cast<btRaycastVehicle*>(vehicleId);
  142. if (vehicle == NULL) {
  143. jclass newExc = env->FindClass("java/lang/NullPointerException");
  144. env->ThrowNew(newExc, "The native object does not exist.");
  145. return 0;
  146. }
  147. return vehicle->getWheelInfo(wheelIndex).m_deltaRotation;
  148. }
  149. #ifdef __cplusplus
  150. }
  151. #endif