159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta/* 259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * Copyright (c) 2009-2010 jMonkeyEngine 359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * All rights reserved. 459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * 559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * Redistribution and use in source and binary forms, with or without 659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * modification, are permitted provided that the following conditions are 759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * met: 859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * 959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * * Redistributions of source code must retain the above copyright 1059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * notice, this list of conditions and the following disclaimer. 1159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * 1259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * * Redistributions in binary form must reproduce the above copyright 1359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * notice, this list of conditions and the following disclaimer in the 1459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * documentation and/or other materials provided with the distribution. 1559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * 1659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * * Neither the name of 'jMonkeyEngine' nor the names of its contributors 1759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * may be used to endorse or promote products derived from this software 1859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * without specific prior written permission. 1959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * 2059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 2159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 2259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 2359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 2459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 2559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 2659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 2759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 2859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 2959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 3059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 3159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta */ 3259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 3359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta/** 3459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * Author: Normen Hansen 3559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta */ 3659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta#include "com_jme3_bullet_collision_shapes_CompoundCollisionShape.h" 3759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta#include "jmeBulletUtil.h" 3859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 3959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta#ifdef __cplusplus 4059b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaextern "C" { 4159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta#endif 4259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 4359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta/* 4459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * Class: com_jme3_bullet_collision_shapes_CompoundCollisionShape 4559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * Method: createShape 4659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * Signature: ()J 4759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta */ 4859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta JNIEXPORT jlong JNICALL Java_com_jme3_bullet_collision_shapes_CompoundCollisionShape_createShape 4959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta (JNIEnv *env, jobject object) { 5059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta jmeClasses::initJavaClasses(env); 5159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta btCompoundShape* shape = new btCompoundShape(); 5259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta return reinterpret_cast<jlong>(shape); 5359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 5459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 5559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta /* 5659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * Class: com_jme3_bullet_collision_shapes_CompoundCollisionShape 5759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * Method: addChildShape 5859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * Signature: (JJLcom/jme3/math/Vector3f;Lcom/jme3/math/Matrix3f;)J 5959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta */ 6059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta JNIEXPORT jlong JNICALL Java_com_jme3_bullet_collision_shapes_CompoundCollisionShape_addChildShape 6159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta (JNIEnv *env, jobject object, jlong compoundId, jlong childId, jobject childLocation, jobject childRotation) { 6259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta btCompoundShape* shape = reinterpret_cast<btCompoundShape*>(compoundId); 6359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta if (shape == NULL) { 6459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta jclass newExc = env->FindClass("java/lang/NullPointerException"); 6559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta env->ThrowNew(newExc, "The native object does not exist."); 6659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta return 0; 6759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 6859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta btCollisionShape* child = reinterpret_cast<btCollisionShape*>(childId); 6959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta if (shape == NULL) { 7059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta jclass newExc = env->FindClass("java/lang/NullPointerException"); 7159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta env->ThrowNew(newExc, "The native object does not exist."); 7259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta return 0; 7359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 7459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta btMatrix3x3 mtx = btMatrix3x3(); 7559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta btTransform trans = btTransform(mtx); 7659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta jmeBulletUtil::convert(env, childLocation, &trans.getOrigin()); 7759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta jmeBulletUtil::convert(env, childRotation, &trans.getBasis()); 7859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta shape->addChildShape(trans, child); 7959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta return 0; 8059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 8159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 8259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta /* 8359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * Class: com_jme3_bullet_collision_shapes_CompoundCollisionShape 8459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * Method: removeChildShape 8559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * Signature: (JJ)J 8659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta */ 8759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta JNIEXPORT jlong JNICALL Java_com_jme3_bullet_collision_shapes_CompoundCollisionShape_removeChildShape 8859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta (JNIEnv * env, jobject object, jlong compoundId, jlong childId) { 8959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta btCompoundShape* shape = reinterpret_cast<btCompoundShape*>(compoundId); 9059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta if (shape == NULL) { 9159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta jclass newExc = env->FindClass("java/lang/NullPointerException"); 9259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta env->ThrowNew(newExc, "The native object does not exist."); 9359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta return 0; 9459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 9559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta btCollisionShape* child = reinterpret_cast<btCollisionShape*>(childId); 9659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta if (shape == NULL) { 9759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta jclass newExc = env->FindClass("java/lang/NullPointerException"); 9859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta env->ThrowNew(newExc, "The native object does not exist."); 9959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta return 0; 10059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 10159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta shape->removeChildShape(child); 10259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta return 0; 10359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 10459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 10559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta#ifdef __cplusplus 10659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta} 10759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta#endif 108