Home | History | Annotate | Download | only in bullet-native
      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_Point2PointJoint.h"
     37 #include "jmeBulletUtil.h"
     38 
     39 #ifdef __cplusplus
     40 extern "C" {
     41 #endif
     42 
     43     /*
     44      * Class:     com_jme3_bullet_joints_Point2PointJoint
     45      * Method:    setDamping
     46      * Signature: (JF)V
     47      */
     48     JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_Point2PointJoint_setDamping
     49     (JNIEnv * env, jobject object, jlong jointId, jfloat damping) {
     50         btPoint2PointConstraint* joint = reinterpret_cast<btPoint2PointConstraint*>(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->m_setting.m_damping = damping;
     57     }
     58 
     59     /*
     60      * Class:     com_jme3_bullet_joints_Point2PointJoint
     61      * Method:    setImpulseClamp
     62      * Signature: (JF)V
     63      */
     64     JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_Point2PointJoint_setImpulseClamp
     65     (JNIEnv * env, jobject object, jlong jointId, jfloat clamp) {
     66         btPoint2PointConstraint* joint = reinterpret_cast<btPoint2PointConstraint*>(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;
     71         }
     72         joint->m_setting.m_impulseClamp = clamp;
     73     }
     74 
     75     /*
     76      * Class:     com_jme3_bullet_joints_Point2PointJoint
     77      * Method:    setTau
     78      * Signature: (JF)V
     79      */
     80     JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_Point2PointJoint_setTau
     81     (JNIEnv * env, jobject object, jlong jointId, jfloat tau) {
     82         btPoint2PointConstraint* joint = reinterpret_cast<btPoint2PointConstraint*>(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;
     87         }
     88         joint->m_setting.m_tau = tau;
     89     }
     90 
     91     /*
     92      * Class:     com_jme3_bullet_joints_Point2PointJoint
     93      * Method:    getDamping
     94      * Signature: (J)F
     95      */
     96     JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_joints_Point2PointJoint_getDamping
     97     (JNIEnv * env, jobject object, jlong jointId) {
     98         btPoint2PointConstraint* joint = reinterpret_cast<btPoint2PointConstraint*>(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->m_setting.m_damping;
    105     }
    106 
    107     /*
    108      * Class:     com_jme3_bullet_joints_Point2PointJoint
    109      * Method:    getImpulseClamp
    110      * Signature: (J)F
    111      */
    112     JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_joints_Point2PointJoint_getImpulseClamp
    113     (JNIEnv * env, jobject object, jlong jointId) {
    114         btPoint2PointConstraint* joint = reinterpret_cast<btPoint2PointConstraint*>(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 0;
    119         }
    120         return joint->m_setting.m_damping;
    121     }
    122 
    123     /*
    124      * Class:     com_jme3_bullet_joints_Point2PointJoint
    125      * Method:    getTau
    126      * Signature: (J)F
    127      */
    128     JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_joints_Point2PointJoint_getTau
    129     (JNIEnv * env, jobject object, jlong jointId) {
    130         btPoint2PointConstraint* joint = reinterpret_cast<btPoint2PointConstraint*>(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 0;
    135         }
    136         return joint->m_setting.m_damping;
    137     }
    138 
    139     /*
    140      * Class:     com_jme3_bullet_joints_Point2PointJoint
    141      * Method:    createJoint
    142      * Signature: (JJLcom/jme3/math/Vector3f;Lcom/jme3/math/Vector3f;)J
    143      */
    144     JNIEXPORT jlong JNICALL Java_com_jme3_bullet_joints_Point2PointJoint_createJoint
    145     (JNIEnv * env, jobject object, jlong bodyIdA, jlong bodyIdB, jobject pivotA, jobject pivotB) {
    146         jmeClasses::initJavaClasses(env);
    147         btRigidBody* bodyA = reinterpret_cast<btRigidBody*>(bodyIdA);
    148         btRigidBody* bodyB = reinterpret_cast<btRigidBody*>(bodyIdB);
    149         //TODO: matrix not needed?
    150         btMatrix3x3 mtx1 = btMatrix3x3();
    151         btMatrix3x3 mtx2 = btMatrix3x3();
    152         btTransform transA = btTransform(mtx1);
    153         jmeBulletUtil::convert(env, pivotA, &transA.getOrigin());
    154         btTransform transB = btTransform(mtx2);
    155         jmeBulletUtil::convert(env, pivotB, &transB.getOrigin());
    156         btHingeConstraint* joint = new btHingeConstraint(*bodyA, *bodyB, transA, transB);
    157         return reinterpret_cast<jlong>(joint);
    158     }
    159 
    160 #ifdef __cplusplus
    161 }
    162 #endif
    163