Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,118 @@ extern "C" {
return ghost->getCcdSquareMotionThreshold();
}

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

btPairCachingGhostObject* ghost = reinterpret_cast<btPairCachingGhostObject*>(objectId);
if (ghost == 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;
resultCallback.m_flags = flags;
ghost->rayTest(native_from, native_to, resultCallback);
return;
}



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

btPairCachingGhostObject* ghost = reinterpret_cast<btPairCachingGhostObject*>(objectId);
if (ghost == NULL) {
jclass newExc = env->FindClass("java/lang/NullPointerException");
env->ThrowNew(newExc, "The physics space does not exist.");
return;
}

btCollisionShape* shape = reinterpret_cast<btCollisionShape*> (shapeId);
if (shape == NULL) {
jclass newExc = env->FindClass("java/lang/NullPointerException");
env->ThrowNew(newExc, "The shape does not exist.");
return;
}

struct AllConvexResultCallback : public btCollisionWorld::ConvexResultCallback {

AllConvexResultCallback(const btTransform& convexFromWorld, const btTransform & convexToWorld) : m_convexFromWorld(convexFromWorld), m_convexToWorld(convexToWorld) {
}
jobject resultlist;
JNIEnv* env;
btTransform m_convexFromWorld; //used to calculate hitPointWorld from hitFraction
btTransform m_convexToWorld;

btVector3 m_hitNormalWorld;
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);

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

return 1.f;
}
};

btTransform native_to = btTransform();
jmeBulletUtil::convert(env, to, &native_to);

btTransform native_from = btTransform();
jmeBulletUtil::convert(env, from, &native_from);

btScalar native_allowed_ccd_penetration = btScalar(allowedCcdPenetration);

AllConvexResultCallback resultCallback(native_from, native_to);
resultCallback.env = env;
resultCallback.resultlist = resultlist;
ghost->convexSweepTest((btConvexShape *)shape, native_from, native_to, resultCallback, native_allowed_ccd_penetration);
return;
}

#ifdef __cplusplus
}
#endif

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions jme3-bullet/src/main/java/com/jme3/bullet/PhysicsSpace.java
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,7 @@ public List<PhysicsRayTestResult> rayTest(Vector3f from, Vector3f to, List<Physi
return results;
}

public native void rayTest_native(Vector3f from, Vector3f to, long physicsSpaceId, List<PhysicsRayTestResult> results, int flags);
public native void rayTest_native(Vector3f from, Vector3f to, long objectId, List<PhysicsRayTestResult> results, int flags);

// private class InternalRayListener extends CollisionWorld.RayResultCallback {
//
Expand Down Expand Up @@ -841,7 +841,7 @@ public List<PhysicsSweepTestResult> sweepTest(CollisionShape shape, Transform st
return sweepTest(shape, start, end, results, 0.0f);
}

public native void sweepTest_native(long shape, Transform from, Transform to, long physicsSpaceId, List<PhysicsSweepTestResult> results, float allowedCcdPenetration);
public native void sweepTest_native(long shape, Transform from, Transform to, long objectId, List<PhysicsSweepTestResult> results, float allowedCcdPenetration);
/**
* Performs a sweep collision test and returns the results as a list of
* PhysicsSweepTestResults<br/> You have to use different Transforms for
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@
*/
package com.jme3.bullet.objects;

import com.jme3.bullet.collision.*;
import com.jme3.bullet.collision.PhysicsCollisionObject;
import com.jme3.bullet.collision.shapes.CollisionShape;
import com.jme3.math.Transform;
import com.jme3.export.InputCapsule;
import com.jme3.export.JmeExporter;
import com.jme3.export.JmeImporter;
Expand Down Expand Up @@ -278,6 +280,45 @@ public float getCcdSquareMotionThreshold() {

private native float getCcdSquareMotionThreshold(long objectId);

public List<PhysicsRayTestResult> rayTest(Vector3f from, Vector3f to, List<PhysicsRayTestResult> results, int rayTestFlags) {
results.clear();
rayTest_native(from, to, objectId, results, rayTestFlags);
return results;
}

public native void rayTest_native(Vector3f from, Vector3f to, long objectId, List<PhysicsRayTestResult> results, int flags);

/**
* Performs a sweep collision test and returns the results as a list of
* PhysicsSweepTestResults<br/> You have to use different Transforms for
* start and end (at least distance > 0.4f). SweepTest will not see a
* collision if it starts INSIDE an object and is moving AWAY from its
* center.
*/
public List<PhysicsSweepTestResult> sweepTest(CollisionShape shape, Transform start, Transform end) {
List results = new LinkedList();
sweepTest(shape, start, end , results);
return (List<PhysicsSweepTestResult>) results;
}

public List<PhysicsSweepTestResult> sweepTest(CollisionShape shape, Transform start, Transform end, List<PhysicsSweepTestResult> results) {
return sweepTest(shape, start, end, results, 0.0f);
}

public native void sweepTest_native(long shape, Transform from, Transform to, long objectId, List<PhysicsSweepTestResult> results, float allowedCcdPenetration);
/**
* Performs a sweep collision test and returns the results as a list of
* PhysicsSweepTestResults<br/> You have to use different Transforms for
* start and end (at least distance > allowedCcdPenetration). SweepTest will not see a
* collision if it starts INSIDE an object and is moving AWAY from its
* center.
*/
public List<PhysicsSweepTestResult> sweepTest(CollisionShape shape, Transform start, Transform end, List<PhysicsSweepTestResult> results, float allowedCcdPenetration ) {
results.clear();
sweepTest_native(shape.getObjectId(), start, end, objectId, results, allowedCcdPenetration);
return results;
}

@Override
public void write(JmeExporter e) throws IOException {
super.write(e);
Expand Down