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