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 #include "com_jme3_bullet_joints_HingeJoint.h" 37 #include "jmeBulletUtil.h" 38 39 #ifdef __cplusplus 40 extern "C" { 41 #endif 42 43 /* 44 * Class: com_jme3_bullet_joints_HingeJoint 45 * Method: enableMotor 46 * Signature: (JZFF)V 47 */ Java_com_jme3_bullet_joints_HingeJoint_enableMotor(JNIEnv * env,jobject object,jlong jointId,jboolean enable,jfloat targetVelocity,jfloat maxMotorImpulse)48 JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_HingeJoint_enableMotor 49 (JNIEnv * env, jobject object, jlong jointId, jboolean enable, jfloat targetVelocity, jfloat maxMotorImpulse) { 50 btHingeConstraint* joint = reinterpret_cast<btHingeConstraint*>(jointId); 51 if (joint == NULL) { 52 jclass newExc = env->FindClass("java/lang/NullPointerException"); 53 env->ThrowNew(newExc, "The native object does not exist."); 54 return; 55 } 56 joint->enableAngularMotor(enable, targetVelocity, maxMotorImpulse); 57 } 58 59 /* 60 * Class: com_jme3_bullet_joints_HingeJoint 61 * Method: getEnableAngularMotor 62 * Signature: (J)Z 63 */ Java_com_jme3_bullet_joints_HingeJoint_getEnableAngularMotor(JNIEnv * env,jobject object,jlong jointId)64 JNIEXPORT jboolean JNICALL Java_com_jme3_bullet_joints_HingeJoint_getEnableAngularMotor 65 (JNIEnv * env, jobject object, jlong jointId) { 66 btHingeConstraint* joint = reinterpret_cast<btHingeConstraint*>(jointId); 67 if (joint == NULL) { 68 jclass newExc = env->FindClass("java/lang/NullPointerException"); 69 env->ThrowNew(newExc, "The native object does not exist."); 70 return false; 71 } 72 return joint->getEnableAngularMotor(); 73 } 74 75 /* 76 * Class: com_jme3_bullet_joints_HingeJoint 77 * Method: getMotorTargetVelocity 78 * Signature: (J)F 79 */ Java_com_jme3_bullet_joints_HingeJoint_getMotorTargetVelocity(JNIEnv * env,jobject object,jlong jointId)80 JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_joints_HingeJoint_getMotorTargetVelocity 81 (JNIEnv * env, jobject object, jlong jointId) { 82 btHingeConstraint* joint = reinterpret_cast<btHingeConstraint*>(jointId); 83 if (joint == NULL) { 84 jclass newExc = env->FindClass("java/lang/NullPointerException"); 85 env->ThrowNew(newExc, "The native object does not exist."); 86 return 0; 87 } 88 return joint->getMotorTargetVelosity(); 89 } 90 91 /* 92 * Class: com_jme3_bullet_joints_HingeJoint 93 * Method: getMaxMotorImpulse 94 * Signature: (J)F 95 */ Java_com_jme3_bullet_joints_HingeJoint_getMaxMotorImpulse(JNIEnv * env,jobject object,jlong jointId)96 JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_joints_HingeJoint_getMaxMotorImpulse 97 (JNIEnv * env, jobject object, jlong jointId) { 98 btHingeConstraint* joint = reinterpret_cast<btHingeConstraint*>(jointId); 99 if (joint == NULL) { 100 jclass newExc = env->FindClass("java/lang/NullPointerException"); 101 env->ThrowNew(newExc, "The native object does not exist."); 102 return 0; 103 } 104 return joint->getMaxMotorImpulse(); 105 } 106 107 /* 108 * Class: com_jme3_bullet_joints_HingeJoint 109 * Method: setLimit 110 * Signature: (JFF)V 111 */ Java_com_jme3_bullet_joints_HingeJoint_setLimit__JFF(JNIEnv * env,jobject object,jlong jointId,jfloat low,jfloat high)112 JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_HingeJoint_setLimit__JFF 113 (JNIEnv * env, jobject object, jlong jointId, jfloat low, jfloat high) { 114 btHingeConstraint* joint = reinterpret_cast<btHingeConstraint*>(jointId); 115 if (joint == NULL) { 116 jclass newExc = env->FindClass("java/lang/NullPointerException"); 117 env->ThrowNew(newExc, "The native object does not exist."); 118 return; 119 } 120 return joint->setLimit(low, high); 121 } 122 123 /* 124 * Class: com_jme3_bullet_joints_HingeJoint 125 * Method: setLimit 126 * Signature: (JFFFFF)V 127 */ Java_com_jme3_bullet_joints_HingeJoint_setLimit__JFFFFF(JNIEnv * env,jobject object,jlong jointId,jfloat low,jfloat high,jfloat softness,jfloat biasFactor,jfloat relaxationFactor)128 JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_HingeJoint_setLimit__JFFFFF 129 (JNIEnv * env, jobject object, jlong jointId, jfloat low, jfloat high, jfloat softness, jfloat biasFactor, jfloat relaxationFactor) { 130 btHingeConstraint* joint = reinterpret_cast<btHingeConstraint*>(jointId); 131 if (joint == NULL) { 132 jclass newExc = env->FindClass("java/lang/NullPointerException"); 133 env->ThrowNew(newExc, "The native object does not exist."); 134 return; 135 } 136 return joint->setLimit(low, high, softness, biasFactor, relaxationFactor); 137 } 138 139 /* 140 * Class: com_jme3_bullet_joints_HingeJoint 141 * Method: getUpperLimit 142 * Signature: (J)F 143 */ Java_com_jme3_bullet_joints_HingeJoint_getUpperLimit(JNIEnv * env,jobject object,jlong jointId)144 JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_joints_HingeJoint_getUpperLimit 145 (JNIEnv * env, jobject object, jlong jointId) { 146 btHingeConstraint* joint = reinterpret_cast<btHingeConstraint*>(jointId); 147 if (joint == NULL) { 148 jclass newExc = env->FindClass("java/lang/NullPointerException"); 149 env->ThrowNew(newExc, "The native object does not exist."); 150 return 0; 151 } 152 return joint->getUpperLimit(); 153 } 154 155 /* 156 * Class: com_jme3_bullet_joints_HingeJoint 157 * Method: getLowerLimit 158 * Signature: (J)F 159 */ Java_com_jme3_bullet_joints_HingeJoint_getLowerLimit(JNIEnv * env,jobject object,jlong jointId)160 JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_joints_HingeJoint_getLowerLimit 161 (JNIEnv * env, jobject object, jlong jointId) { 162 btHingeConstraint* joint = reinterpret_cast<btHingeConstraint*>(jointId); 163 if (joint == NULL) { 164 jclass newExc = env->FindClass("java/lang/NullPointerException"); 165 env->ThrowNew(newExc, "The native object does not exist."); 166 return 0; 167 } 168 return joint->getLowerLimit(); 169 } 170 171 /* 172 * Class: com_jme3_bullet_joints_HingeJoint 173 * Method: setAngularOnly 174 * Signature: (JZ)V 175 */ Java_com_jme3_bullet_joints_HingeJoint_setAngularOnly(JNIEnv * env,jobject object,jlong jointId,jboolean angular)176 JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_HingeJoint_setAngularOnly 177 (JNIEnv * env, jobject object, jlong jointId, jboolean angular) { 178 btHingeConstraint* joint = reinterpret_cast<btHingeConstraint*>(jointId); 179 if (joint == NULL) { 180 jclass newExc = env->FindClass("java/lang/NullPointerException"); 181 env->ThrowNew(newExc, "The native object does not exist."); 182 return; 183 } 184 joint->setAngularOnly(angular); 185 } 186 187 /* 188 * Class: com_jme3_bullet_joints_HingeJoint 189 * Method: getHingeAngle 190 * Signature: (J)F 191 */ Java_com_jme3_bullet_joints_HingeJoint_getHingeAngle(JNIEnv * env,jobject object,jlong jointId)192 JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_joints_HingeJoint_getHingeAngle 193 (JNIEnv * env, jobject object, jlong jointId) { 194 btHingeConstraint* joint = reinterpret_cast<btHingeConstraint*>(jointId); 195 if (joint == NULL) { 196 jclass newExc = env->FindClass("java/lang/NullPointerException"); 197 env->ThrowNew(newExc, "The native object does not exist."); 198 return 0; 199 } 200 return joint->getHingeAngle(); 201 } 202 203 /* 204 * Class: com_jme3_bullet_joints_HingeJoint 205 * Method: createJoint 206 * Signature: (JJLcom/jme3/math/Vector3f;Lcom/jme3/math/Vector3f;Lcom/jme3/math/Vector3f;Lcom/jme3/math/Vector3f;)J 207 */ Java_com_jme3_bullet_joints_HingeJoint_createJoint(JNIEnv * env,jobject object,jlong bodyIdA,jlong bodyIdB,jobject pivotA,jobject axisA,jobject pivotB,jobject axisB)208 JNIEXPORT jlong JNICALL Java_com_jme3_bullet_joints_HingeJoint_createJoint 209 (JNIEnv * env, jobject object, jlong bodyIdA, jlong bodyIdB, jobject pivotA, jobject axisA, jobject pivotB, jobject axisB) { 210 jmeClasses::initJavaClasses(env); 211 btRigidBody* bodyA = reinterpret_cast<btRigidBody*>(bodyIdA); 212 btRigidBody* bodyB = reinterpret_cast<btRigidBody*>(bodyIdB); 213 btVector3 vec1 = btVector3(); 214 btVector3 vec2 = btVector3(); 215 btVector3 vec3 = btVector3(); 216 btVector3 vec4 = btVector3(); 217 jmeBulletUtil::convert(env, pivotA, &vec1); 218 jmeBulletUtil::convert(env, pivotB, &vec2); 219 jmeBulletUtil::convert(env, axisA, &vec3); 220 jmeBulletUtil::convert(env, axisB, &vec4); 221 btHingeConstraint* joint = new btHingeConstraint(*bodyA, *bodyB, vec1, vec2, vec3, vec4); 222 return reinterpret_cast<jlong>(joint); 223 } 224 #ifdef __cplusplus 225 } 226 #endif 227