native bullet:

- add ray test code, thanks to @EmpirePhoenix
- clean up import structure
- remove separate jmeUserPointer class


git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@8577 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
nor..67 13 years ago
parent 83ab68264b
commit 439c5b36b8
  1. 22
      engine/src/bullet/com/jme3/bullet/PhysicsSpace.java
  2. 25
      engine/src/bullet/com/jme3/bullet/collision/PhysicsRayTestResult.java
  3. 1
      engine/src/bullet/com/jme3/bullet/joints/SliderJoint.java
  4. 2
      engine/src/bullet/native/bullet.properties
  5. 51
      engine/src/bullet/native/com_jme3_bullet_PhysicsSpace.cpp
  6. 8
      engine/src/bullet/native/com_jme3_bullet_PhysicsSpace.h
  7. 1
      engine/src/bullet/native/com_jme3_bullet_collision_PhysicsCollisionObject.cpp
  8. 2
      engine/src/bullet/native/com_jme3_bullet_objects_PhysicsGhostObject.cpp
  9. 31
      engine/src/bullet/native/jmeBulletUtil.cpp
  10. 9
      engine/src/bullet/native/jmeBulletUtil.h
  11. 71
      engine/src/bullet/native/jmeClasses.cpp
  12. 8
      engine/src/bullet/native/jmeClasses.h
  13. 3
      engine/src/bullet/native/jmePhysicsSpace.cpp
  14. 11
      engine/src/bullet/native/jmeUserPointer.h

@ -213,15 +213,14 @@ public class PhysicsSpace {
physicsTickCallback.physicsTick(this, f);
}
}
private void addCollision_native(){
private void addCollision_native() {
}
private boolean needCollision_native(PhysicsCollisionObject objectA, PhysicsCollisionObject objectB){
private boolean needCollision_native(PhysicsCollisionObject objectA, PhysicsCollisionObject objectB) {
return false;
}
// private void setOverlapFilterCallback() {
// OverlapFilterCallback callback = new OverlapFilterCallback() {
//
@ -333,6 +332,7 @@ public class PhysicsSpace {
// System.out.println("addCollisionEvent:"+node.getObjectId()+" "+ node1.getObjectId());
collisionEvents.add(eventFactory.getEvent(PhysicsCollisionEvent.TYPE_PROCESSED, node, node1, manifoldPointObjectId));
}
/**
* updates the physics space
* @param time the current time value
@ -715,10 +715,10 @@ public class PhysicsSpace {
/**
* Performs a ray collision test and returns the results as a list of PhysicsRayTestResults
*/
public List<PhysicsRayTestResult> rayTest(Vector3f from, Vector3f to) {
List<PhysicsRayTestResult> results = new LinkedList<PhysicsRayTestResult>();
// dynamicsWorld.rayTest(Converter.convert(from, rayVec1), Converter.convert(to, rayVec2), new InternalRayListener(results));
return results;
public List rayTest(Vector3f from, Vector3f to) {
List results = new LinkedList();
rayTest(from, to, results);
return (List<PhysicsRayTestResult>) results;
}
/**
@ -726,10 +726,12 @@ public class PhysicsSpace {
*/
public List<PhysicsRayTestResult> rayTest(Vector3f from, Vector3f to, List<PhysicsRayTestResult> results) {
results.clear();
// dynamicsWorld.rayTest(Converter.convert(from, rayVec1), Converter.convert(to, rayVec2), new InternalRayListener(results));
rayTest_native(from, to, physicsSpaceId, results);
return results;
}
public native void rayTest_native(Vector3f from, Vector3f to, long physicsSpaceId, List<PhysicsRayTestResult> results);
// private class InternalRayListener extends CollisionWorld.RayResultCallback {
//
// private List<PhysicsRayTestResult> results;

@ -35,23 +35,21 @@ import com.jme3.math.Vector3f;
/**
* Contains the results of a PhysicsSpace rayTest
* @author normenhansen
* bulletAppState.getPhysicsSpace().rayTest(new Vector3f(0,1000,0),new Vector3f(0,-1000,0));
javap -s java.util.List
* @author Empire-Phoenix,normenhansen
*/
public class PhysicsRayTestResult {
private PhysicsCollisionObject collisionObject;
private Vector3f hitNormalLocal;
private float hitFraction;
private boolean normalInWorldSpace;
private boolean normalInWorldSpace = true;
public PhysicsRayTestResult() {
}
public PhysicsRayTestResult(PhysicsCollisionObject collisionObject, Vector3f hitNormalLocal, float hitFraction, boolean normalInWorldSpace) {
this.collisionObject = collisionObject;
this.hitNormalLocal = hitNormalLocal;
this.hitFraction = hitFraction;
this.normalInWorldSpace = normalInWorldSpace;
/**
* allocated by native code only
*/
private PhysicsRayTestResult() {
}
/**
@ -81,11 +79,4 @@ public class PhysicsRayTestResult {
public boolean isNormalInWorldSpace() {
return normalInWorldSpace;
}
public void fill(PhysicsCollisionObject collisionObject, Vector3f hitNormalLocal, float hitFraction, boolean normalInWorldSpace) {
this.collisionObject = collisionObject;
this.hitNormalLocal = hitNormalLocal;
this.hitFraction = hitFraction;
this.normalInWorldSpace = normalInWorldSpace;
}
}

@ -35,7 +35,6 @@ import com.jme3.export.JmeExporter;
import com.jme3.math.Matrix3f;
import com.jme3.math.Vector3f;
import com.jme3.bullet.objects.PhysicsRigidBody;
import com.jme3.bullet.util.Converter;
import com.jme3.export.InputCapsule;
import com.jme3.export.JmeImporter;
import com.jme3.export.OutputCapsule;

@ -12,7 +12,7 @@ bullet.compile.debug=false
# native library compilation options
bullet.osx.compiler=g++
bullet.osx.syslibroot=/Developer/SDKs/MacOSX10.5.sdk
bullet.osx.syslibroot=/Developer/SDKs/MacOSX10.5u.sdk
# change this to msvc for MS Visual Studio compiler
bullet.windows.compiler=g++
bullet.linux.compiler=g++

@ -32,7 +32,7 @@
#include "com_jme3_bullet_PhysicsSpace.h"
#include "jmePhysicsSpace.h"
#include "jmeBulletUtil.h"
#include "jmeUserPointer.h"
/**
* Author: Normen Hansen
*/
@ -395,6 +395,55 @@ extern "C" {
}
delete(space);
}
JNIEXPORT void JNICALL Java_com_jme3_bullet_PhysicsSpace_rayTest_1native
(JNIEnv * env, jobject object, jobject to, jobject from, jlong spaceId, jobject resultlist) {
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;
}
struct AllRayResultCallback : public btCollisionWorld::RayResultCallback {
AllRayResultCallback(const btVector3& rayFromWorld, const btVector3 & rayToWorld) : m_rayFromWorld(rayFromWorld), m_rayToWorld(rayToWorld) {
}
jobject resultlist;
JNIEnv* env;
btVector3 m_rayFromWorld; //used to calculate hitPointWorld from hitFraction
btVector3 m_rayToWorld;
btVector3 m_hitNormalWorld;
btVector3 m_hitPointWorld;
virtual btScalar addSingleResult(btCollisionWorld::LocalRayResult& rayResult, bool normalInWorldSpace) {
if (normalInWorldSpace) {
m_hitNormalWorld = rayResult.m_hitNormalLocal;
} else {
m_hitNormalWorld = m_collisionObject->getWorldTransform().getBasis() * rayResult.m_hitNormalLocal;
}
m_hitPointWorld.setInterpolate3(m_rayFromWorld, m_rayToWorld, rayResult.m_hitFraction);
jmeBulletUtil::addResult(env, resultlist, m_hitNormalWorld, m_hitPointWorld, rayResult.m_hitFraction, rayResult.m_collisionObject);
return 1.f;
}
};
btVector3 native_to = btVector3();
jmeBulletUtil::convert(env, to, &native_to);
btVector3 native_from = btVector3();
jmeBulletUtil::convert(env, from, &native_from);
AllRayResultCallback resultCallback(native_from, native_to);
resultCallback.env = env;
resultCallback.resultlist = resultlist;
space->getDynamicsWorld()->rayTest(native_from, native_to, resultCallback);
return;
}
#ifdef __cplusplus
}

@ -135,6 +135,14 @@ JNIEXPORT void JNICALL Java_com_jme3_bullet_PhysicsSpace_removeConstraint
JNIEXPORT void JNICALL Java_com_jme3_bullet_PhysicsSpace_setGravity
(JNIEnv *, jobject, jlong, jobject);
/*
* Class: com_jme3_bullet_PhysicsSpace
* Method: rayTest_native
* Signature: (Lcom/jme3/math/Vector3f;Lcom/jme3/math/Vector3f;JLjava/util/List;)V
*/
JNIEXPORT void JNICALL Java_com_jme3_bullet_PhysicsSpace_rayTest_1native
(JNIEnv *, jobject, jobject, jobject, jlong, jobject);
/*
* Class: com_jme3_bullet_PhysicsSpace
* Method: initNativePhysics

@ -36,7 +36,6 @@
#include "com_jme3_bullet_collision_PhysicsCollisionObject.h"
#include "jmeBulletUtil.h"
#include "jmePhysicsSpace.h"
#include "jmeUserPointer.h"
#ifdef __cplusplus
extern "C" {

@ -40,7 +40,7 @@
#include "BulletCollision/BroadphaseCollision/btOverlappingPairCache.h"
#include "jmeBulletUtil.h"
#include "jmePhysicsSpace.h"
#include "jmeUserPointer.h"
#ifdef __cplusplus
extern "C" {
#endif

@ -33,23 +33,23 @@
#include "jmeBulletUtil.h"
/**
* Author: Normen Hansen
* Author: Normen Hansen,Empire Phoenix, Lutherion
*/
void jmeBulletUtil::convert(JNIEnv* env, jobject in, btVector3* out) {
if (in == NULL || out == NULL) {
jmeClasses::throwNPE(env);
}
float x = env->GetFloatField(in, jmeClasses::Vector3f_x);//env->CallFloatMethod(in, jmeClasses::Vector3f_getX);
float x = env->GetFloatField(in, jmeClasses::Vector3f_x); //env->CallFloatMethod(in, jmeClasses::Vector3f_getX);
if (env->ExceptionCheck()) {
env->Throw(env->ExceptionOccurred());
return;
}
float y = env->GetFloatField(in, jmeClasses::Vector3f_y);//env->CallFloatMethod(in, jmeClasses::Vector3f_getY);
float y = env->GetFloatField(in, jmeClasses::Vector3f_y); //env->CallFloatMethod(in, jmeClasses::Vector3f_getY);
if (env->ExceptionCheck()) {
env->Throw(env->ExceptionOccurred());
return;
}
float z = env->GetFloatField(in, jmeClasses::Vector3f_z);//env->CallFloatMethod(in, jmeClasses::Vector3f_getZ);
float z = env->GetFloatField(in, jmeClasses::Vector3f_z); //env->CallFloatMethod(in, jmeClasses::Vector3f_getZ);
if (env->ExceptionCheck()) {
env->Throw(env->ExceptionOccurred());
return;
@ -77,7 +77,7 @@ void jmeBulletUtil::convert(JNIEnv* env, const btVector3* in, jobject out) {
return;
}
env->SetFloatField(out, jmeClasses::Vector3f_z, z);
// env->CallObjectMethod(out, jmeClasses::Vector3f_set, x, y, z);
// env->CallObjectMethod(out, jmeClasses::Vector3f_set, x, y, z);
if (env->ExceptionCheck()) {
env->Throw(env->ExceptionOccurred());
return;
@ -300,7 +300,26 @@ void jmeBulletUtil::convertQuat(JNIEnv* env, const btMatrix3x3* in, jobject out)
return;
}
env->SetFloatField(out, jmeClasses::Quaternion_w, w);
// env->CallObjectMethod(out, jmeClasses::Quaternion_set, x, y, z, w);
// env->CallObjectMethod(out, jmeClasses::Quaternion_set, x, y, z, w);
if (env->ExceptionCheck()) {
env->Throw(env->ExceptionOccurred());
return;
}
}
void jmeBulletUtil::addResult(JNIEnv* env, jobject resultlist, btVector3 hitnormal, btVector3 m_hitPointWorld, btScalar m_hitFraction, btCollisionObject* hitobject) {
jobject singleresult = env->AllocObject(jmeClasses::PhysicsRay_Class);
jobject hitnormalvec = env->AllocObject(jmeClasses::Vector3f);
convert(env, const_cast<btVector3*> (&hitnormal), hitnormalvec);
jmeUserPointer *up1 = (jmeUserPointer*) hitobject -> getUserPointer();
env->SetObjectField(singleresult, jmeClasses::PhysicsRay_normalInWorldSpace, hitnormalvec);
env->SetFloatField(singleresult, jmeClasses::PhysicsRay_hitfraction, m_hitFraction);
env->SetObjectField(singleresult, jmeClasses::PhysicsRay_collisionObject, up1->javaCollisionObject);
env->CallVoidMethod(resultlist, jmeClasses::PhysicsRay_addmethod, singleresult);
if (env->ExceptionCheck()) {
env->Throw(env->ExceptionOccurred());
return;

@ -45,8 +45,17 @@ public:
static void convert(JNIEnv* env, const btMatrix3x3* in, jobject out);
static void convertQuat(JNIEnv* env, jobject in, btMatrix3x3* out);
static void convertQuat(JNIEnv* env, const btMatrix3x3* in, jobject out);
static void addResult(JNIEnv* env, jobject resultlist, const btVector3 hitnormal,const btVector3 m_hitPointWorld,const btScalar m_hitFraction,btCollisionObject* hitobject);
private:
jmeBulletUtil(){};
~jmeBulletUtil(){};
};
class jmeUserPointer {
public:
jobject javaCollisionObject;
jint group;
jint groups;
void *space;
};

@ -33,7 +33,7 @@
#include <stdio.h>
/**
* Author: Normen Hansen
* Author: Normen Hansen,Empire Phoenix, Lutherion
*/
//public fields
jclass jmeClasses::PhysicsSpace;
@ -81,6 +81,16 @@ jfieldID jmeClasses::Matrix3f_m22;
jclass jmeClasses::DebugMeshCallback;
jmethodID jmeClasses::DebugMeshCallback_addVector;
jclass jmeClasses::PhysicsRay_Class;
jmethodID jmeClasses::PhysicsRay_newSingleResult;
jfieldID jmeClasses::PhysicsRay_normalInWorldSpace;
jfieldID jmeClasses::PhysicsRay_hitfraction;
jfieldID jmeClasses::PhysicsRay_collisionObject;
jclass jmeClasses::PhysicsRay_listresult;
jmethodID jmeClasses::PhysicsRay_addmethod;
//private fields
//JNIEnv* jmeClasses::env;
JavaVM* jmeClasses::vm;
@ -103,7 +113,7 @@ void jmeClasses::initJavaClasses(JNIEnv* env) {
// jmeClasses::env = env;
env->GetJavaVM(&vm);
PhysicsSpace = env->FindClass("com/jme3/bullet/PhysicsSpace");
PhysicsSpace = (jclass)env->NewGlobalRef(env->FindClass("com/jme3/bullet/PhysicsSpace"));
if (env->ExceptionCheck()) {
env->Throw(env->ExceptionOccurred());
return;
@ -117,7 +127,7 @@ void jmeClasses::initJavaClasses(JNIEnv* env) {
return;
}
PhysicsGhostObject = env->FindClass("com/jme3/bullet/objects/PhysicsGhostObject");
PhysicsGhostObject = (jclass)env->NewGlobalRef(env->FindClass("com/jme3/bullet/objects/PhysicsGhostObject"));
if (env->ExceptionCheck()) {
env->Throw(env->ExceptionOccurred());
return;
@ -128,7 +138,7 @@ void jmeClasses::initJavaClasses(JNIEnv* env) {
return;
}
Vector3f = env->FindClass("com/jme3/math/Vector3f");
Vector3f = (jclass)env->NewGlobalRef(env->FindClass("com/jme3/math/Vector3f"));
Vector3f_set = env->GetMethodID(Vector3f, "set", "(FFF)Lcom/jme3/math/Vector3f;");
Vector3f_toArray = env->GetMethodID(Vector3f, "toArray", "([F)[F");
Vector3f_getX = env->GetMethodID(Vector3f, "getX", "()F");
@ -138,7 +148,7 @@ void jmeClasses::initJavaClasses(JNIEnv* env) {
Vector3f_y = env->GetFieldID(Vector3f, "y", "F");
Vector3f_z = env->GetFieldID(Vector3f, "z", "F");
Quaternion = env->FindClass("com/jme3/math/Quaternion");
Quaternion = (jclass)env->NewGlobalRef(env->FindClass("com/jme3/math/Quaternion"));
if (env->ExceptionCheck()) {
env->Throw(env->ExceptionOccurred());
return;
@ -153,7 +163,7 @@ void jmeClasses::initJavaClasses(JNIEnv* env) {
Quaternion_z = env->GetFieldID(Quaternion, "z", "F");
Quaternion_w = env->GetFieldID(Quaternion, "w", "F");
Matrix3f = env->FindClass("com/jme3/math/Matrix3f");
Matrix3f = (jclass)env->NewGlobalRef(env->FindClass("com/jme3/math/Matrix3f"));
if (env->ExceptionCheck()) {
env->Throw(env->ExceptionOccurred());
return;
@ -174,17 +184,62 @@ void jmeClasses::initJavaClasses(JNIEnv* env) {
Matrix3f_m21 = env->GetFieldID(Matrix3f, "m21", "F");
Matrix3f_m22 = env->GetFieldID(Matrix3f, "m22", "F");
DebugMeshCallback = env->FindClass("com/jme3/bullet/util/DebugMeshCallback");
DebugMeshCallback = (jclass)env->NewGlobalRef(env->FindClass("com/jme3/bullet/util/DebugMeshCallback"));
if (env->ExceptionCheck()) {
env->Throw(env->ExceptionOccurred());
return;
}
DebugMeshCallback_addVector = env->GetMethodID(DebugMeshCallback, "addVector", "(FFFII)V");
if (env->ExceptionCheck()) {
env->Throw(env->ExceptionOccurred());
return;
}
PhysicsRay_Class = (jclass)env->NewGlobalRef(env->FindClass("com/jme3/bullet/collision/PhysicsRayTestResult"));
if (env->ExceptionCheck()) {
env->Throw(env->ExceptionOccurred());
return;
}
PhysicsRay_newSingleResult = env->GetMethodID(PhysicsRay_Class,"<init>","()V");
if (env->ExceptionCheck()) {
env->Throw(env->ExceptionOccurred());
return;
}
PhysicsRay_normalInWorldSpace = env->GetFieldID(PhysicsRay_Class,"hitNormalLocal","Lcom/jme3/math/Vector3f;");
if (env->ExceptionCheck()) {
env->Throw(env->ExceptionOccurred());
return;
}
PhysicsRay_hitfraction = env->GetFieldID(PhysicsRay_Class,"hitFraction","F");
if (env->ExceptionCheck()) {
env->Throw(env->ExceptionOccurred());
return;
}
PhysicsRay_collisionObject = env->GetFieldID(PhysicsRay_Class,"collisionObject","Lcom/jme3/bullet/collision/PhysicsCollisionObject;");
if (env->ExceptionCheck()) {
env->Throw(env->ExceptionOccurred());
return;
}
PhysicsRay_listresult = env->FindClass("java/util/List");
PhysicsRay_listresult = (jclass)env->NewGlobalRef(PhysicsRay_listresult);
if (env->ExceptionCheck()) {
env->Throw(env->ExceptionOccurred());
return;
}
PhysicsRay_addmethod = env->GetMethodID(PhysicsRay_listresult,"add","(Ljava/lang/Object;)Z");
if (env->ExceptionCheck()) {
env->Throw(env->ExceptionOccurred());
return;
}
}
void jmeClasses::throwNPE(JNIEnv* env) {

@ -81,6 +81,14 @@ public:
static jfieldID Matrix3f_m21;
static jfieldID Matrix3f_m22;
static jclass PhysicsRay_Class;
static jmethodID PhysicsRay_newSingleResult;
static jfieldID PhysicsRay_normalInWorldSpace;
static jfieldID PhysicsRay_hitfraction;
static jfieldID PhysicsRay_collisionObject;
static jclass PhysicsRay_listresult;
static jmethodID PhysicsRay_addmethod;
static jclass DebugMeshCallback;
static jmethodID DebugMeshCallback_addVector;

@ -31,7 +31,6 @@
*/
#include "jmePhysicsSpace.h"
#include "jmeBulletUtil.h"
#include "jmeUserPointer.h"
#include <stdio.h>
/**
@ -240,7 +239,7 @@ bool jmePhysicsSpace::contactProcessedCallback(btManifoldPoint &cp, void *body0,
btCollisionObject* co1 = (btCollisionObject*) body1;
jmeUserPointer *up1 = (jmeUserPointer*) co1 -> getUserPointer();
if (up0 != NULL) {
jmePhysicsSpace *dynamicsWorld = up0->space;
jmePhysicsSpace *dynamicsWorld = (jmePhysicsSpace *)up0->space;
if (dynamicsWorld != NULL) {
JNIEnv* env = dynamicsWorld->getEnv();
jobject javaPhysicsSpace = env->NewLocalRef(dynamicsWorld->getJavaPhysicsSpace());

@ -1,11 +0,0 @@
#ifndef _Included_jmeUserPointer
#define _Included_jmeUserPointer
#include <jni.h>
class jmeUserPointer {
public:
jobject javaCollisionObject;
jint group;
jint groups;
jmePhysicsSpace *space;
};
#endif
Loading…
Cancel
Save