Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@ POM_INCEPTION_YEAR=2009
# Bintray settings to override in $HOME/.gradle/gradle.properties or ENV or commandline
bintray_user=
bintray_api_key=

119 changes: 62 additions & 57 deletions jme3-bullet-native/src/native/cpp/com_jme3_bullet_PhysicsSpace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,21 @@ extern "C" {
* Signature: (FFFFFFI)J
*/
JNIEXPORT jlong JNICALL Java_com_jme3_bullet_PhysicsSpace_createPhysicsSpace
(JNIEnv * env, jobject object, jfloat minX, jfloat minY, jfloat minZ, jfloat maxX, jfloat maxY, jfloat maxZ, jint broadphase, jboolean threading) {
(JNIEnv * env, jobject object, jfloat minX, jfloat minY, jfloat minZ,
jfloat maxX, jfloat maxY, jfloat maxZ, jint broadphase,
jboolean threading) {
jmeClasses::initJavaClasses(env);

jmePhysicsSpace* space = new jmePhysicsSpace(env, object);
if (space == NULL) {
jclass newExc = env->FindClass("java/lang/NullPointerException");
env->ThrowNew(newExc, "The physics space has not been created.");
return 0;
}
space->createPhysicsSpace(minX, minY, minZ, maxX, maxY, maxZ, broadphase, threading);
return reinterpret_cast<jlong>(space);

space->createPhysicsSpace(minX, minY, minZ, maxX, maxY, maxZ,
broadphase, threading);
return reinterpret_cast<jlong> (space);
}

/*
Expand All @@ -64,8 +69,9 @@ extern "C" {
* Signature: (JFIF)V
*/
JNIEXPORT void JNICALL Java_com_jme3_bullet_PhysicsSpace_stepSimulation
(JNIEnv * env, jobject object, jlong spaceId, jfloat tpf, jint maxSteps, jfloat accuracy) {
jmePhysicsSpace* space = reinterpret_cast<jmePhysicsSpace*>(spaceId);
(JNIEnv * env, jobject object, jlong spaceId, jfloat tpf, jint maxSteps,
jfloat accuracy) {
jmePhysicsSpace* space = reinterpret_cast<jmePhysicsSpace*> (spaceId);
if (space == NULL) {
jclass newExc = env->FindClass("java/lang/NullPointerException");
env->ThrowNew(newExc, "The physics space does not exist.");
Expand All @@ -81,8 +87,8 @@ extern "C" {
*/
JNIEXPORT void JNICALL Java_com_jme3_bullet_PhysicsSpace_addCollisionObject
(JNIEnv * env, jobject object, jlong spaceId, jlong objectId) {
jmePhysicsSpace* space = reinterpret_cast<jmePhysicsSpace*>(spaceId);
btCollisionObject* collisionObject = reinterpret_cast<btCollisionObject*>(objectId);
jmePhysicsSpace* space = reinterpret_cast<jmePhysicsSpace*> (spaceId);
btCollisionObject* collisionObject = reinterpret_cast<btCollisionObject*> (objectId);
if (space == NULL) {
jclass newExc = env->FindClass("java/lang/NullPointerException");
env->ThrowNew(newExc, "The physics space does not exist.");
Expand All @@ -93,7 +99,7 @@ extern "C" {
env->ThrowNew(newExc, "The collision object does not exist.");
return;
}
jmeUserPointer *userPointer = (jmeUserPointer*)collisionObject->getUserPointer();
jmeUserPointer *userPointer = (jmeUserPointer*) collisionObject->getUserPointer();
userPointer -> space = space;

space->getDynamicsWorld()->addCollisionObject(collisionObject);
Expand All @@ -106,8 +112,8 @@ extern "C" {
*/
JNIEXPORT void JNICALL Java_com_jme3_bullet_PhysicsSpace_removeCollisionObject
(JNIEnv * env, jobject object, jlong spaceId, jlong objectId) {
jmePhysicsSpace* space = reinterpret_cast<jmePhysicsSpace*>(spaceId);
btCollisionObject* collisionObject = reinterpret_cast<btCollisionObject*>(objectId);
jmePhysicsSpace* space = reinterpret_cast<jmePhysicsSpace*> (spaceId);
btCollisionObject* collisionObject = reinterpret_cast<btCollisionObject*> (objectId);
if (space == NULL) {
jclass newExc = env->FindClass("java/lang/NullPointerException");
env->ThrowNew(newExc, "The physics space does not exist.");
Expand All @@ -119,7 +125,7 @@ extern "C" {
return;
}
space->getDynamicsWorld()->removeCollisionObject(collisionObject);
jmeUserPointer *userPointer = (jmeUserPointer*)collisionObject->getUserPointer();
jmeUserPointer *userPointer = (jmeUserPointer*) collisionObject->getUserPointer();
userPointer -> space = NULL;
}

Expand All @@ -130,8 +136,8 @@ extern "C" {
*/
JNIEXPORT void JNICALL Java_com_jme3_bullet_PhysicsSpace_addRigidBody
(JNIEnv * env, jobject object, jlong spaceId, jlong rigidBodyId) {
jmePhysicsSpace* space = reinterpret_cast<jmePhysicsSpace*>(spaceId);
btRigidBody* collisionObject = reinterpret_cast<btRigidBody*>(rigidBodyId);
jmePhysicsSpace* space = reinterpret_cast<jmePhysicsSpace*> (spaceId);
btRigidBody* collisionObject = reinterpret_cast<btRigidBody*> (rigidBodyId);
if (space == NULL) {
jclass newExc = env->FindClass("java/lang/NullPointerException");
env->ThrowNew(newExc, "The physics space does not exist.");
Expand All @@ -142,7 +148,7 @@ extern "C" {
env->ThrowNew(newExc, "The collision object does not exist.");
return;
}
jmeUserPointer *userPointer = (jmeUserPointer*)collisionObject->getUserPointer();
jmeUserPointer *userPointer = (jmeUserPointer*) collisionObject->getUserPointer();
userPointer -> space = space;
space->getDynamicsWorld()->addRigidBody(collisionObject);
}
Expand All @@ -154,8 +160,8 @@ extern "C" {
*/
JNIEXPORT void JNICALL Java_com_jme3_bullet_PhysicsSpace_removeRigidBody
(JNIEnv * env, jobject object, jlong spaceId, jlong rigidBodyId) {
jmePhysicsSpace* space = reinterpret_cast<jmePhysicsSpace*>(spaceId);
btRigidBody* collisionObject = reinterpret_cast<btRigidBody*>(rigidBodyId);
jmePhysicsSpace* space = reinterpret_cast<jmePhysicsSpace*> (spaceId);
btRigidBody* collisionObject = reinterpret_cast<btRigidBody*> (rigidBodyId);
if (space == NULL) {
jclass newExc = env->FindClass("java/lang/NullPointerException");
env->ThrowNew(newExc, "The physics space does not exist.");
Expand All @@ -166,7 +172,7 @@ extern "C" {
env->ThrowNew(newExc, "The collision object does not exist.");
return;
}
jmeUserPointer *userPointer = (jmeUserPointer*)collisionObject->getUserPointer();
jmeUserPointer *userPointer = (jmeUserPointer*) collisionObject->getUserPointer();
userPointer -> space = NULL;
space->getDynamicsWorld()->removeRigidBody(collisionObject);
}
Expand All @@ -178,8 +184,8 @@ extern "C" {
*/
JNIEXPORT void JNICALL Java_com_jme3_bullet_PhysicsSpace_addCharacterObject
(JNIEnv * env, jobject object, jlong spaceId, jlong objectId) {
jmePhysicsSpace* space = reinterpret_cast<jmePhysicsSpace*>(spaceId);
btCollisionObject* collisionObject = reinterpret_cast<btCollisionObject*>(objectId);
jmePhysicsSpace* space = reinterpret_cast<jmePhysicsSpace*> (spaceId);
btCollisionObject* collisionObject = reinterpret_cast<btCollisionObject*> (objectId);
if (space == NULL) {
jclass newExc = env->FindClass("java/lang/NullPointerException");
env->ThrowNew(newExc, "The physics space does not exist.");
Expand All @@ -190,12 +196,12 @@ extern "C" {
env->ThrowNew(newExc, "The collision object does not exist.");
return;
}
jmeUserPointer *userPointer = (jmeUserPointer*)collisionObject->getUserPointer();
jmeUserPointer *userPointer = (jmeUserPointer*) collisionObject->getUserPointer();
userPointer -> space = space;
space->getDynamicsWorld()->addCollisionObject(collisionObject,
btBroadphaseProxy::CharacterFilter,
btBroadphaseProxy::StaticFilter | btBroadphaseProxy::DefaultFilter
);
);
}

/*
Expand All @@ -205,8 +211,8 @@ extern "C" {
*/
JNIEXPORT void JNICALL Java_com_jme3_bullet_PhysicsSpace_removeCharacterObject
(JNIEnv * env, jobject object, jlong spaceId, jlong objectId) {
jmePhysicsSpace* space = reinterpret_cast<jmePhysicsSpace*>(spaceId);
btCollisionObject* collisionObject = reinterpret_cast<btCollisionObject*>(objectId);
jmePhysicsSpace* space = reinterpret_cast<jmePhysicsSpace*> (spaceId);
btCollisionObject* collisionObject = reinterpret_cast<btCollisionObject*> (objectId);
if (space == NULL) {
jclass newExc = env->FindClass("java/lang/NullPointerException");
env->ThrowNew(newExc, "The physics space does not exist.");
Expand All @@ -217,7 +223,7 @@ extern "C" {
env->ThrowNew(newExc, "The collision object does not exist.");
return;
}
jmeUserPointer *userPointer = (jmeUserPointer*)collisionObject->getUserPointer();
jmeUserPointer *userPointer = (jmeUserPointer*) collisionObject->getUserPointer();
userPointer -> space = NULL;
space->getDynamicsWorld()->removeCollisionObject(collisionObject);
}
Expand All @@ -229,8 +235,8 @@ extern "C" {
*/
JNIEXPORT void JNICALL Java_com_jme3_bullet_PhysicsSpace_addAction
(JNIEnv * env, jobject object, jlong spaceId, jlong objectId) {
jmePhysicsSpace* space = reinterpret_cast<jmePhysicsSpace*>(spaceId);
btActionInterface* actionObject = reinterpret_cast<btActionInterface*>(objectId);
jmePhysicsSpace* space = reinterpret_cast<jmePhysicsSpace*> (spaceId);
btActionInterface* actionObject = reinterpret_cast<btActionInterface*> (objectId);
if (space == NULL) {
jclass newExc = env->FindClass("java/lang/NullPointerException");
env->ThrowNew(newExc, "The physics space does not exist.");
Expand All @@ -251,8 +257,8 @@ extern "C" {
*/
JNIEXPORT void JNICALL Java_com_jme3_bullet_PhysicsSpace_removeAction
(JNIEnv * env, jobject object, jlong spaceId, jlong objectId) {
jmePhysicsSpace* space = reinterpret_cast<jmePhysicsSpace*>(spaceId);
btActionInterface* actionObject = reinterpret_cast<btActionInterface*>(objectId);
jmePhysicsSpace* space = reinterpret_cast<jmePhysicsSpace*> (spaceId);
btActionInterface* actionObject = reinterpret_cast<btActionInterface*> (objectId);
if (space == NULL) {
jclass newExc = env->FindClass("java/lang/NullPointerException");
env->ThrowNew(newExc, "The physics space does not exist.");
Expand All @@ -273,8 +279,8 @@ extern "C" {
*/
JNIEXPORT void JNICALL Java_com_jme3_bullet_PhysicsSpace_addVehicle
(JNIEnv * env, jobject object, jlong spaceId, jlong objectId) {
jmePhysicsSpace* space = reinterpret_cast<jmePhysicsSpace*>(spaceId);
btActionInterface* actionObject = reinterpret_cast<btActionInterface*>(objectId);
jmePhysicsSpace* space = reinterpret_cast<jmePhysicsSpace*> (spaceId);
btActionInterface* actionObject = reinterpret_cast<btActionInterface*> (objectId);
if (space == NULL) {
jclass newExc = env->FindClass("java/lang/NullPointerException");
env->ThrowNew(newExc, "The physics space does not exist.");
Expand All @@ -295,8 +301,8 @@ extern "C" {
*/
JNIEXPORT void JNICALL Java_com_jme3_bullet_PhysicsSpace_removeVehicle
(JNIEnv * env, jobject object, jlong spaceId, jlong objectId) {
jmePhysicsSpace* space = reinterpret_cast<jmePhysicsSpace*>(spaceId);
btActionInterface* actionObject = reinterpret_cast<btActionInterface*>(objectId);
jmePhysicsSpace* space = reinterpret_cast<jmePhysicsSpace*> (spaceId);
btActionInterface* actionObject = reinterpret_cast<btActionInterface*> (objectId);
if (space == NULL) {
jclass newExc = env->FindClass("java/lang/NullPointerException");
env->ThrowNew(newExc, "The physics space does not exist.");
Expand All @@ -317,8 +323,8 @@ extern "C" {
*/
JNIEXPORT void JNICALL Java_com_jme3_bullet_PhysicsSpace_addConstraint
(JNIEnv * env, jobject object, jlong spaceId, jlong objectId) {
jmePhysicsSpace* space = reinterpret_cast<jmePhysicsSpace*>(spaceId);
btTypedConstraint* constraint = reinterpret_cast<btTypedConstraint*>(objectId);
jmePhysicsSpace* space = reinterpret_cast<jmePhysicsSpace*> (spaceId);
btTypedConstraint* constraint = reinterpret_cast<btTypedConstraint*> (objectId);
if (space == NULL) {
jclass newExc = env->FindClass("java/lang/NullPointerException");
env->ThrowNew(newExc, "The physics space does not exist.");
Expand All @@ -339,8 +345,8 @@ extern "C" {
*/
JNIEXPORT void JNICALL Java_com_jme3_bullet_PhysicsSpace_addConstraintC
(JNIEnv * env, jobject object, jlong spaceId, jlong objectId, jboolean collision) {
jmePhysicsSpace* space = reinterpret_cast<jmePhysicsSpace*>(spaceId);
btTypedConstraint* constraint = reinterpret_cast<btTypedConstraint*>(objectId);
jmePhysicsSpace* space = reinterpret_cast<jmePhysicsSpace*> (spaceId);
btTypedConstraint* constraint = reinterpret_cast<btTypedConstraint*> (objectId);
if (space == NULL) {
jclass newExc = env->FindClass("java/lang/NullPointerException");
env->ThrowNew(newExc, "The physics space does not exist.");
Expand All @@ -361,8 +367,8 @@ extern "C" {
*/
JNIEXPORT void JNICALL Java_com_jme3_bullet_PhysicsSpace_removeConstraint
(JNIEnv * env, jobject object, jlong spaceId, jlong objectId) {
jmePhysicsSpace* space = reinterpret_cast<jmePhysicsSpace*>(spaceId);
btTypedConstraint* constraint = reinterpret_cast<btTypedConstraint*>(objectId);
jmePhysicsSpace* space = reinterpret_cast<jmePhysicsSpace*> (spaceId);
btTypedConstraint* constraint = reinterpret_cast<btTypedConstraint*> (objectId);
if (space == NULL) {
jclass newExc = env->FindClass("java/lang/NullPointerException");
env->ThrowNew(newExc, "The physics space does not exist.");
Expand All @@ -383,14 +389,15 @@ extern "C" {
*/
JNIEXPORT void JNICALL Java_com_jme3_bullet_PhysicsSpace_setGravity
(JNIEnv * env, jobject object, jlong spaceId, jobject vector) {
jmePhysicsSpace* space = reinterpret_cast<jmePhysicsSpace*>(spaceId);
jmePhysicsSpace* space = reinterpret_cast<jmePhysicsSpace*> (spaceId);
if (space == NULL) {
jclass newExc = env->FindClass("java/lang/NullPointerException");
env->ThrowNew(newExc, "The physics space does not exist.");
return;
}
btVector3 gravity = btVector3();
jmeBulletUtil::convert(env, vector, &gravity);

space->getDynamicsWorld()->setGravity(gravity);
}

Expand All @@ -411,13 +418,13 @@ extern "C" {
*/
JNIEXPORT void JNICALL Java_com_jme3_bullet_PhysicsSpace_finalizeNative
(JNIEnv * env, jobject object, jlong spaceId) {
jmePhysicsSpace* space = reinterpret_cast<jmePhysicsSpace*>(spaceId);
jmePhysicsSpace* space = reinterpret_cast<jmePhysicsSpace*> (spaceId);
if (space == NULL) {
return;
}
delete(space);
}

JNIEXPORT void JNICALL Java_com_jme3_bullet_PhysicsSpace_rayTest_1native
(JNIEnv * env, jobject object, jobject from, jobject to, jlong spaceId, jobject resultlist, jint flags) {

Expand Down Expand Up @@ -465,13 +472,12 @@ extern "C" {
resultCallback.resultlist = resultlist;
resultCallback.m_flags = flags;
space->getDynamicsWorld()->rayTest(native_from, native_to, resultCallback);

return;
}



JNIEXPORT void JNICALL Java_com_jme3_bullet_PhysicsSpace_sweepTest_1native
(JNIEnv * env, jobject object, jlong shapeId, jobject from, jobject to, jlong spaceId, jobject resultlist, jfloat allowedCcdPenetration) {
(JNIEnv * env, jobject object, jlong shapeId, jobject from, jobject to, jlong spaceId, jobject resultlist, jfloat allowedCcdPenetration) {

jmePhysicsSpace* space = reinterpret_cast<jmePhysicsSpace*> (spaceId);
if (space == NULL) {
Expand All @@ -489,7 +495,7 @@ extern "C" {

struct AllConvexResultCallback : public btCollisionWorld::ConvexResultCallback {

AllConvexResultCallback(const btTransform& convexFromWorld, const btTransform & convexToWorld) : m_convexFromWorld(convexFromWorld), m_convexToWorld(convexToWorld) {
AllConvexResultCallback(const btTransform& convexFromWorld, const btTransform & convexToWorld) : m_convexFromWorld(convexFromWorld), m_convexToWorld(convexToWorld) {
}
jobject resultlist;
JNIEnv* env;
Expand All @@ -500,17 +506,16 @@ extern "C" {
btVector3 m_hitPointWorld;

virtual btScalar addSingleResult(btCollisionWorld::LocalConvexResult& convexResult, bool normalInWorldSpace) {
if (normalInWorldSpace) {
m_hitNormalWorld = convexResult.m_hitNormalLocal;
}
else {
m_hitNormalWorld = convexResult.m_hitCollisionObject->getWorldTransform().getBasis() * convexResult.m_hitNormalLocal;
}
m_hitPointWorld.setInterpolate3(m_convexFromWorld.getBasis() * m_convexFromWorld.getOrigin(), m_convexToWorld.getBasis() * m_convexToWorld.getOrigin(), convexResult.m_hitFraction);
if (normalInWorldSpace) {
m_hitNormalWorld = convexResult.m_hitNormalLocal;
} else {
m_hitNormalWorld = convexResult.m_hitCollisionObject->getWorldTransform().getBasis() * convexResult.m_hitNormalLocal;
}
m_hitPointWorld.setInterpolate3(m_convexFromWorld.getBasis() * m_convexFromWorld.getOrigin(), m_convexToWorld.getBasis() * m_convexToWorld.getOrigin(), convexResult.m_hitFraction);

jmeBulletUtil::addSweepResult(env, resultlist, &m_hitNormalWorld, &m_hitPointWorld, convexResult.m_hitFraction, convexResult.m_hitCollisionObject);
jmeBulletUtil::addSweepResult(env, resultlist, &m_hitNormalWorld, &m_hitPointWorld, convexResult.m_hitFraction, convexResult.m_hitCollisionObject);

return 1.f;
return 1.f;
}
};

Expand All @@ -528,16 +533,16 @@ extern "C" {
space->getDynamicsWorld()->convexSweepTest((btConvexShape *) shape, native_from, native_to, resultCallback, native_allowed_ccd_penetration);
return;
}

JNIEXPORT void JNICALL Java_com_jme3_bullet_PhysicsSpace_setSolverNumIterations
(JNIEnv *env, jobject object, jlong spaceId, jint value) {
jmePhysicsSpace* space = reinterpret_cast<jmePhysicsSpace*>(spaceId);
jmePhysicsSpace* space = reinterpret_cast<jmePhysicsSpace*> (spaceId);
if (space == NULL) {
jclass newExc = env->FindClass("java/lang/NullPointerException");
env->ThrowNew(newExc, "The physics space does not exist.");
return;
}

space->getDynamicsWorld()->getSolverInfo().m_numIterations = value;
}

Expand Down