use of com.bulletphysics.collision.dispatch.CollisionObject in project jmonkeyengine by jMonkeyEngine.
the class PhysicsSpace method setContactCallbacks.
private void setContactCallbacks() {
BulletGlobals.setContactAddedCallback(new ContactAddedCallback() {
public boolean contactAdded(ManifoldPoint cp, com.bulletphysics.collision.dispatch.CollisionObject colObj0, int partId0, int index0, com.bulletphysics.collision.dispatch.CollisionObject colObj1, int partId1, int index1) {
System.out.println("contact added");
return true;
}
});
BulletGlobals.setContactProcessedCallback(new ContactProcessedCallback() {
public boolean contactProcessed(ManifoldPoint cp, Object body0, Object body1) {
if (body0 instanceof CollisionObject && body1 instanceof CollisionObject) {
PhysicsCollisionObject node = null, node1 = null;
CollisionObject rBody0 = (CollisionObject) body0;
CollisionObject rBody1 = (CollisionObject) body1;
node = (PhysicsCollisionObject) rBody0.getUserPointer();
node1 = (PhysicsCollisionObject) rBody1.getUserPointer();
collisionEvents.add(eventFactory.getEvent(PhysicsCollisionEvent.TYPE_PROCESSED, node, node1, cp));
}
return true;
}
});
BulletGlobals.setContactDestroyedCallback(new ContactDestroyedCallback() {
public boolean contactDestroyed(Object userPersistentData) {
System.out.println("contact destroyed");
return true;
}
});
}
use of com.bulletphysics.collision.dispatch.CollisionObject in project jmonkeyengine by jMonkeyEngine.
the class PhysicsSpace method setOverlapFilterCallback.
private void setOverlapFilterCallback() {
OverlapFilterCallback callback = new OverlapFilterCallback() {
public boolean needBroadphaseCollision(BroadphaseProxy bp, BroadphaseProxy bp1) {
boolean collides = (bp.collisionFilterGroup & bp1.collisionFilterMask) != 0;
if (collides) {
collides = (bp1.collisionFilterGroup & bp.collisionFilterMask) != 0;
}
if (collides) {
assert (bp.clientObject instanceof com.bulletphysics.collision.dispatch.CollisionObject && bp.clientObject instanceof com.bulletphysics.collision.dispatch.CollisionObject);
com.bulletphysics.collision.dispatch.CollisionObject colOb = (com.bulletphysics.collision.dispatch.CollisionObject) bp.clientObject;
com.bulletphysics.collision.dispatch.CollisionObject colOb1 = (com.bulletphysics.collision.dispatch.CollisionObject) bp1.clientObject;
assert (colOb.getUserPointer() != null && colOb1.getUserPointer() != null);
PhysicsCollisionObject collisionObject = (PhysicsCollisionObject) colOb.getUserPointer();
PhysicsCollisionObject collisionObject1 = (PhysicsCollisionObject) colOb1.getUserPointer();
if ((collisionObject.getCollideWithGroups() & collisionObject1.getCollisionGroup()) > 0 || (collisionObject1.getCollideWithGroups() & collisionObject.getCollisionGroup()) > 0) {
PhysicsCollisionGroupListener listener = collisionGroupListeners.get(collisionObject.getCollisionGroup());
PhysicsCollisionGroupListener listener1 = collisionGroupListeners.get(collisionObject1.getCollisionGroup());
if (listener != null) {
collides = listener.collide(collisionObject, collisionObject1);
}
if (listener1 != null && collisionObject.getCollisionGroup() != collisionObject1.getCollisionGroup()) {
collides = listener1.collide(collisionObject, collisionObject1) && collides;
}
} else {
return false;
}
}
return collides;
}
};
dynamicsWorld.getPairCache().setOverlapFilterCallback(callback);
}
use of com.bulletphysics.collision.dispatch.CollisionObject in project bdx by GoranM.
the class DiscreteDynamicsWorld method updateActivationState.
protected void updateActivationState(float timeStep) {
BulletStats.pushProfile("updateActivationState");
Stack stack = Stack.enter();
int sp = stack.getSp();
try {
Vector3f tmp = stack.allocVector3f();
for (int i = 0; i < collisionObjects.size(); i++) {
CollisionObject colObj = collisionObjects.getQuick(i);
RigidBody body = RigidBody.upcast(colObj);
if (body != null) {
body.updateDeactivation(timeStep);
if (body.wantsSleeping()) {
if (body.isStaticOrKinematicObject()) {
body.setActivationState(CollisionObject.ISLAND_SLEEPING);
} else {
if (body.getActivationState() == CollisionObject.ACTIVE_TAG) {
body.setActivationState(CollisionObject.WANTS_DEACTIVATION);
}
if (body.getActivationState() == CollisionObject.ISLAND_SLEEPING) {
tmp.set(0f, 0f, 0f);
body.setAngularVelocity(tmp);
body.setLinearVelocity(tmp);
}
}
} else {
if (body.getActivationState() != CollisionObject.DISABLE_DEACTIVATION) {
body.setActivationState(CollisionObject.ACTIVE_TAG);
}
}
}
}
} finally {
stack.leave(sp);
BulletStats.popProfile();
}
}
use of com.bulletphysics.collision.dispatch.CollisionObject in project bdx by GoranM.
the class DiscreteDynamicsWorld method integrateTransforms.
protected void integrateTransforms(float timeStep) {
BulletStats.pushProfile("integrateTransforms");
Stack stack = Stack.enter();
int sp = stack.getSp();
try {
Vector3f tmp = stack.allocVector3f();
Transform tmpTrans = stack.allocTransform();
Transform predictedTrans = stack.allocTransform();
for (int i = 0; i < collisionObjects.size(); i++) {
CollisionObject colObj = collisionObjects.getQuick(i);
RigidBody body = RigidBody.upcast(colObj);
if (body != null) {
body.setHitFraction(1f);
if (body.isActive() && (!body.isStaticOrKinematicObject())) {
body.predictIntegratedTransform(timeStep, predictedTrans);
tmp.sub(predictedTrans.origin, body.getWorldTransform(tmpTrans).origin);
float squareMotion = tmp.lengthSquared();
if (body.getCcdSquareMotionThreshold() != 0f && body.getCcdSquareMotionThreshold() < squareMotion) {
BulletStats.pushProfile("CCD motion clamping");
try {
if (body.getCollisionShape().isConvex()) {
BulletStats.gNumClampedCcdMotions++;
ClosestNotMeConvexResultCallback sweepResults = new ClosestNotMeConvexResultCallback(body, body.getWorldTransform(tmpTrans).origin, predictedTrans.origin, getBroadphase().getOverlappingPairCache(), getDispatcher());
//ConvexShape convexShape = (ConvexShape)body.getCollisionShape();
//btConvexShape* convexShape = static_cast<btConvexShape*>(body->getCollisionShape());
SphereShape tmpSphere = new SphereShape(body.getCcdSweptSphereRadius());
sweepResults.collisionFilterGroup = body.getBroadphaseProxy().collisionFilterGroup;
sweepResults.collisionFilterMask = body.getBroadphaseProxy().collisionFilterMask;
convexSweepTest(tmpSphere, body.getWorldTransform(tmpTrans), predictedTrans, sweepResults);
// JAVA NOTE: added closestHitFraction test to prevent objects being stuck
if (sweepResults.hasHit() && (sweepResults.closestHitFraction > 0.0001f)) {
body.setHitFraction(sweepResults.closestHitFraction);
body.predictIntegratedTransform(timeStep * body.getHitFraction(), predictedTrans);
body.setHitFraction(0f);
//System.out.printf("clamped integration to hit fraction = %f\n", sweepResults.closestHitFraction);
}
}
} finally {
BulletStats.popProfile();
}
}
body.proceedToTransform(predictedTrans);
}
}
}
} finally {
stack.leave(sp);
BulletStats.popProfile();
}
}
use of com.bulletphysics.collision.dispatch.CollisionObject in project bdx by GoranM.
the class DiscreteDynamicsWorld method predictUnconstraintMotion.
protected void predictUnconstraintMotion(float timeStep) {
BulletStats.pushProfile("predictUnconstraintMotion");
Stack stack = Stack.enter();
int sp = stack.getSp();
try {
Transform tmpTrans = stack.allocTransform();
for (int i = 0; i < collisionObjects.size(); i++) {
CollisionObject colObj = collisionObjects.getQuick(i);
RigidBody body = RigidBody.upcast(colObj);
if (body != null) {
if (!body.isStaticOrKinematicObject()) {
if (body.isActive()) {
body.integrateVelocities(timeStep);
// damping
body.applyDamping(timeStep);
body.predictIntegratedTransform(timeStep, body.getInterpolationWorldTransform(tmpTrans));
}
}
}
}
} finally {
stack.leave(sp);
BulletStats.popProfile();
}
}
Aggregations