- add SixDofSpringJoint to native bullet (thanks to @chototsu) git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@8395 75d07b2b-3a1a-0410-a2c5-0572b91ccdca3.0
parent
f798988f0a
commit
5bfd3bd68c
@ -0,0 +1,103 @@ |
|||||||
|
/* |
||||||
|
* Copyright (c) 2009-2010 jMonkeyEngine |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
* Redistribution and use in source and binary forms, with or without |
||||||
|
* modification, are permitted provided that the following conditions are |
||||||
|
* met: |
||||||
|
* |
||||||
|
* * Redistributions of source code must retain the above copyright |
||||||
|
* notice, this list of conditions and the following disclaimer. |
||||||
|
* |
||||||
|
* * Redistributions in binary form must reproduce the above copyright |
||||||
|
* notice, this list of conditions and the following disclaimer in the |
||||||
|
* documentation and/or other materials provided with the distribution. |
||||||
|
* |
||||||
|
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors |
||||||
|
* may be used to endorse or promote products derived from this software |
||||||
|
* without specific prior written permission. |
||||||
|
* |
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
||||||
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
||||||
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
||||||
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
||||||
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
||||||
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
||||||
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
||||||
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
||||||
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
||||||
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||||
|
*/ |
||||||
|
package com.jme3.bullet.joints; |
||||||
|
|
||||||
|
import com.jme3.export.JmeExporter; |
||||||
|
import com.jme3.export.JmeImporter; |
||||||
|
import com.jme3.math.Matrix3f; |
||||||
|
import com.jme3.math.Vector3f; |
||||||
|
import com.jme3.bullet.joints.motors.RotationalLimitMotor; |
||||||
|
import com.jme3.bullet.joints.motors.TranslationalLimitMotor; |
||||||
|
import com.jme3.bullet.objects.PhysicsRigidBody; |
||||||
|
import com.jme3.export.InputCapsule; |
||||||
|
import com.jme3.export.OutputCapsule; |
||||||
|
import java.io.IOException; |
||||||
|
import java.util.Iterator; |
||||||
|
import java.util.LinkedList; |
||||||
|
import java.util.logging.Level; |
||||||
|
import java.util.logging.Logger; |
||||||
|
|
||||||
|
/** |
||||||
|
* <i>From bullet manual:</i><br> |
||||||
|
* This generic constraint can emulate a variety of standard constraints, |
||||||
|
* by configuring each of the 6 degrees of freedom (dof). |
||||||
|
* The first 3 dof axis are linear axis, which represent translation of rigidbodies, |
||||||
|
* and the latter 3 dof axis represent the angular motion. Each axis can be either locked, |
||||||
|
* free or limited. On construction of a new btGeneric6DofConstraint, all axis are locked. |
||||||
|
* Afterwards the axis can be reconfigured. Note that several combinations that |
||||||
|
* include free and/or limited angular degrees of freedom are undefined. |
||||||
|
* @author normenhansen |
||||||
|
*/ |
||||||
|
public class SixDofSpringJoint extends SixDofJoint { |
||||||
|
|
||||||
|
final boolean springEnabled[] = new boolean[6]; |
||||||
|
final float equilibriumPoint[] = new float[6]; |
||||||
|
final float springStiffness[] = new float[6]; |
||||||
|
final float springDamping[] = new float[6]; // between 0 and 1 (1 == no damping)
|
||||||
|
|
||||||
|
public SixDofSpringJoint() { |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @param pivotA local translation of the joint connection point in node A |
||||||
|
* @param pivotB local translation of the joint connection point in node B |
||||||
|
*/ |
||||||
|
public SixDofSpringJoint(PhysicsRigidBody nodeA, PhysicsRigidBody nodeB, Vector3f pivotA, Vector3f pivotB, Matrix3f rotA, Matrix3f rotB, boolean useLinearReferenceFrameA) { |
||||||
|
super(nodeA, nodeB, pivotA, pivotB, rotA, rotB, useLinearReferenceFrameA); |
||||||
|
} |
||||||
|
public void enableSpring(int index, boolean onOff) { |
||||||
|
enableSpring(objectId, index, onOff); |
||||||
|
} |
||||||
|
native void enableSpring(long objctId, int index, boolean onOff); |
||||||
|
|
||||||
|
public void setStiffness(int index, float stiffness) { |
||||||
|
setStiffness(objectId, index, stiffness); |
||||||
|
} |
||||||
|
native void setStiffness(long objctId, int index, float stiffness); |
||||||
|
|
||||||
|
public void setDamping(int index, float damping) { |
||||||
|
setDamping(objectId, index, damping); |
||||||
|
|
||||||
|
} |
||||||
|
native void setDamping(long objctId, int index, float damping); |
||||||
|
public void setEquilibriumPoint() { // set the current constraint position/orientation as an equilibrium point for all DOF
|
||||||
|
setEquilibriumPoint(objectId); |
||||||
|
} |
||||||
|
native void setEquilibriumPoint(long objctId); |
||||||
|
public void setEquilibriumPoint(int index){ // set the current constraint position/orientation as an equilibrium point for given DOF
|
||||||
|
setEquilibriumPoint(objectId, index); |
||||||
|
} |
||||||
|
native void setEquilibriumPoint(long objctId, int index); |
||||||
|
@Override |
||||||
|
native long createJoint(long objectIdA, long objectIdB, Vector3f pivotA, Matrix3f rotA, Vector3f pivotB, Matrix3f rotB, boolean useLinearReferenceFrameA); |
||||||
|
|
||||||
|
} |
@ -0,0 +1,103 @@ |
|||||||
|
|
||||||
|
/**
|
||||||
|
* Author: Normen Hansen |
||||||
|
*/ |
||||||
|
#include "com_jme3_bullet_joints_SixDofSpringJoint.h" |
||||||
|
#include "jmeBulletUtil.h" |
||||||
|
|
||||||
|
#ifdef __cplusplus |
||||||
|
extern "C" { |
||||||
|
#endif |
||||||
|
|
||||||
|
/*
|
||||||
|
* Class: com_jme3_bullet_joints_SixDofSpringJoint |
||||||
|
* Method: enableString |
||||||
|
* Signature: (JIZ)V |
||||||
|
*/ |
||||||
|
JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_SixDofSpringJoint_enableSpring |
||||||
|
(JNIEnv *env, jobject object, jlong jointId, jint index, jboolean onOff) { |
||||||
|
btGeneric6DofSpringConstraint* joint = (btGeneric6DofSpringConstraint*) jointId; |
||||||
|
joint -> enableSpring(index, onOff); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Class: com_jme3_bullet_joints_SixDofSpringJoint |
||||||
|
* Method: setStiffness |
||||||
|
* Signature: (JIF)V |
||||||
|
*/ |
||||||
|
JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_SixDofSpringJoint_setStiffness |
||||||
|
(JNIEnv *env, jobject object, jlong jointId, jint index, jfloat stiffness) { |
||||||
|
btGeneric6DofSpringConstraint* joint = (btGeneric6DofSpringConstraint*) jointId; |
||||||
|
joint -> setStiffness(index, stiffness); |
||||||
|
} |
||||||
|
|
||||||
|
/*
|
||||||
|
* Class: com_jme3_bullet_joints_SixDofSpringJoint |
||||||
|
* Method: setDamping |
||||||
|
* Signature: (JIF)V |
||||||
|
*/ |
||||||
|
JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_SixDofSpringJoint_setDamping |
||||||
|
(JNIEnv *env, jobject object, jlong jointId, jint index, jfloat damping) { |
||||||
|
btGeneric6DofSpringConstraint* joint = (btGeneric6DofSpringConstraint*) jointId; |
||||||
|
joint -> setDamping(index, damping); |
||||||
|
} |
||||||
|
|
||||||
|
/*
|
||||||
|
* Class: com_jme3_bullet_joints_SixDofSpringJoint |
||||||
|
* Method: setEquilibriumPoint |
||||||
|
* Signature: (JIF)V |
||||||
|
*/ |
||||||
|
JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_SixDofSpringJoint_setEquilibriumPoint__J |
||||||
|
(JNIEnv *env, jobject object, jlong jointId) { |
||||||
|
btGeneric6DofSpringConstraint* joint = (btGeneric6DofSpringConstraint*) jointId; |
||||||
|
joint -> setEquilibriumPoint(); |
||||||
|
} |
||||||
|
|
||||||
|
/*
|
||||||
|
* Class: com_jme3_bullet_joints_SixDofSpringJoint |
||||||
|
* Method: setEquilibriumPoint |
||||||
|
* Signature: (JI)V |
||||||
|
*/ |
||||||
|
JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_SixDofSpringJoint_setEquilibriumPoint__JI |
||||||
|
(JNIEnv *env, jobject object, jlong jointId, jint index) { |
||||||
|
btGeneric6DofSpringConstraint* joint = (btGeneric6DofSpringConstraint*) jointId; |
||||||
|
joint -> setEquilibriumPoint(index); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Class: com_jme3_bullet_joints_SixDofSpringJoint |
||||||
|
* Method: createJoint |
||||||
|
* Signature: (JJLcom/jme3/math/Vector3f;Lcom/jme3/math/Matrix3f;Lcom/jme3/math/Vector3f;Lcom/jme3/math/Matrix3f;Z)J |
||||||
|
*/ |
||||||
|
JNIEXPORT jlong JNICALL Java_com_jme3_bullet_joints_SixDofSpringJoint_createJoint |
||||||
|
(JNIEnv * env, jobject object, jlong bodyIdA, jlong bodyIdB, jobject pivotA, jobject rotA, jobject pivotB, jobject rotB, jboolean useLinearReferenceFrameA) { |
||||||
|
jmeClasses::initJavaClasses(env); |
||||||
|
btRigidBody* bodyA = (btRigidBody*) bodyIdA; |
||||||
|
btRigidBody* bodyB = (btRigidBody*) bodyIdB; |
||||||
|
btMatrix3x3* mtx1 = &btMatrix3x3(); |
||||||
|
btMatrix3x3* mtx2 = &btMatrix3x3(); |
||||||
|
/* btTransform* transA = &btTransform(*mtx1);
|
||||||
|
jmeBulletUtil::convert(env, pivotA, &transA->getOrigin()); |
||||||
|
jmeBulletUtil::convert(env, rotA, &transA->getBasis()); |
||||||
|
btTransform* transB = &btTransform(*mtx2); |
||||||
|
jmeBulletUtil::convert(env, pivotB, &transB->getOrigin()); |
||||||
|
jmeBulletUtil::convert(env, rotB, &transB->getBasis()); |
||||||
|
*/ |
||||||
|
btTransform transA; |
||||||
|
jmeBulletUtil::convert(env, pivotA, &transA.getOrigin()); |
||||||
|
jmeBulletUtil::convert(env, rotA, &transA.getBasis()); |
||||||
|
btTransform transB; |
||||||
|
jmeBulletUtil::convert(env, pivotB, &transB.getOrigin()); |
||||||
|
jmeBulletUtil::convert(env, rotB, &transB.getBasis()); |
||||||
|
|
||||||
|
btGeneric6DofSpringConstraint* joint = new btGeneric6DofSpringConstraint(*bodyA, *bodyB, transA, transB, useLinearReferenceFrameA); |
||||||
|
return (long)joint; |
||||||
|
} |
||||||
|
|
||||||
|
#ifdef __cplusplus |
||||||
|
} |
||||||
|
#endif |
@ -0,0 +1,61 @@ |
|||||||
|
/* DO NOT EDIT THIS FILE - it is machine generated */ |
||||||
|
#include <jni.h> |
||||||
|
/* Header for class com_jme3_bullet_joints_SixDofSpringJoint */ |
||||||
|
|
||||||
|
#ifndef _Included_com_jme3_bullet_joints_SixDofSpringJoint |
||||||
|
#define _Included_com_jme3_bullet_joints_SixDofSpringJoint |
||||||
|
#ifdef __cplusplus |
||||||
|
extern "C" { |
||||||
|
#endif |
||||||
|
/*
|
||||||
|
* Class: com_jme3_bullet_joints_SixDofSpringJoint |
||||||
|
* Method: enableSpring |
||||||
|
* Signature: (JIZ)V |
||||||
|
*/ |
||||||
|
JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_SixDofSpringJoint_enableSpring |
||||||
|
(JNIEnv *, jobject, jlong, jint, jboolean); |
||||||
|
|
||||||
|
/*
|
||||||
|
* Class: com_jme3_bullet_joints_SixDofSpringJoint |
||||||
|
* Method: setStiffness |
||||||
|
* Signature: (JIF)V |
||||||
|
*/ |
||||||
|
JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_SixDofSpringJoint_setStiffness |
||||||
|
(JNIEnv *, jobject, jlong, jint, jfloat); |
||||||
|
|
||||||
|
/*
|
||||||
|
* Class: com_jme3_bullet_joints_SixDofSpringJoint |
||||||
|
* Method: setDamping |
||||||
|
* Signature: (JIF)V |
||||||
|
*/ |
||||||
|
JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_SixDofSpringJoint_setDamping |
||||||
|
(JNIEnv *, jobject, jlong, jint, jfloat); |
||||||
|
|
||||||
|
/*
|
||||||
|
* Class: com_jme3_bullet_joints_SixDofSpringJoint |
||||||
|
* Method: setEquilibriumPoint |
||||||
|
* Signature: (J)V |
||||||
|
*/ |
||||||
|
JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_SixDofSpringJoint_setEquilibriumPoint__J |
||||||
|
(JNIEnv *, jobject, jlong); |
||||||
|
|
||||||
|
/*
|
||||||
|
* Class: com_jme3_bullet_joints_SixDofSpringJoint |
||||||
|
* Method: setEquilibriumPoint |
||||||
|
* Signature: (JI)V |
||||||
|
*/ |
||||||
|
JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_SixDofSpringJoint_setEquilibriumPoint__JI |
||||||
|
(JNIEnv *, jobject, jlong, jint); |
||||||
|
|
||||||
|
/*
|
||||||
|
* Class: com_jme3_bullet_joints_SixDofSpringJoint |
||||||
|
* Method: createJoint |
||||||
|
* Signature: (JJLcom/jme3/math/Vector3f;Lcom/jme3/math/Matrix3f;Lcom/jme3/math/Vector3f;Lcom/jme3/math/Matrix3f;Z)J |
||||||
|
*/ |
||||||
|
JNIEXPORT jlong JNICALL Java_com_jme3_bullet_joints_SixDofSpringJoint_createJoint |
||||||
|
(JNIEnv *, jobject, jlong, jlong, jobject, jobject, jobject, jobject, jboolean); |
||||||
|
|
||||||
|
#ifdef __cplusplus |
||||||
|
} |
||||||
|
#endif |
||||||
|
#endif |
@ -0,0 +1,11 @@ |
|||||||
|
#ifndef _Included_jmeUserPointer |
||||||
|
#define _Included_jmeUserPointer |
||||||
|
#include <jni.h> |
||||||
|
class jmeUserPointer { |
||||||
|
public: |
||||||
|
jobject javaCollisionObject; |
||||||
|
jint group; |
||||||
|
jint groups; |
||||||
|
jmePhysicsSpace *space; |
||||||
|
}; |
||||||
|
#endif |
Loading…
Reference in new issue