Search in sources :

Example 1 with CollisionObject

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;
        }
    });
}
Also used : PhysicsCollisionObject(com.jme3.bullet.collision.PhysicsCollisionObject) CollisionObject(com.bulletphysics.collision.dispatch.CollisionObject) ContactDestroyedCallback(com.bulletphysics.ContactDestroyedCallback) ManifoldPoint(com.bulletphysics.collision.narrowphase.ManifoldPoint) ContactAddedCallback(com.bulletphysics.ContactAddedCallback) CollisionObject(com.bulletphysics.collision.dispatch.CollisionObject) PairCachingGhostObject(com.bulletphysics.collision.dispatch.PairCachingGhostObject) PhysicsCollisionObject(com.jme3.bullet.collision.PhysicsCollisionObject) PhysicsGhostObject(com.jme3.bullet.objects.PhysicsGhostObject) CollisionObject(com.bulletphysics.collision.dispatch.CollisionObject) ContactProcessedCallback(com.bulletphysics.ContactProcessedCallback) TypedConstraint(com.bulletphysics.dynamics.constraintsolver.TypedConstraint) ManifoldPoint(com.bulletphysics.collision.narrowphase.ManifoldPoint) PhysicsJoint(com.jme3.bullet.joints.PhysicsJoint) PhysicsCollisionObject(com.jme3.bullet.collision.PhysicsCollisionObject)

Example 2 with CollisionObject

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);
}
Also used : PhysicsCollisionObject(com.jme3.bullet.collision.PhysicsCollisionObject) CollisionObject(com.bulletphysics.collision.dispatch.CollisionObject) PhysicsCollisionGroupListener(com.jme3.bullet.collision.PhysicsCollisionGroupListener) CollisionObject(com.bulletphysics.collision.dispatch.CollisionObject) BroadphaseProxy(com.bulletphysics.collision.broadphase.BroadphaseProxy) OverlapFilterCallback(com.bulletphysics.collision.broadphase.OverlapFilterCallback) PhysicsCollisionObject(com.jme3.bullet.collision.PhysicsCollisionObject)

Example 3 with CollisionObject

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();
    }
}
Also used : CollisionObject(com.bulletphysics.collision.dispatch.CollisionObject) Vector3f(javax.vecmath.Vector3f) TypedConstraint(com.bulletphysics.dynamics.constraintsolver.TypedConstraint) ManifoldPoint(com.bulletphysics.collision.narrowphase.ManifoldPoint) Stack(com.bulletphysics.util.Stack)

Example 4 with CollisionObject

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();
    }
}
Also used : CollisionObject(com.bulletphysics.collision.dispatch.CollisionObject) Vector3f(javax.vecmath.Vector3f) SphereShape(com.bulletphysics.collision.shapes.SphereShape) Transform(com.bulletphysics.linearmath.Transform) TypedConstraint(com.bulletphysics.dynamics.constraintsolver.TypedConstraint) ManifoldPoint(com.bulletphysics.collision.narrowphase.ManifoldPoint) Stack(com.bulletphysics.util.Stack)

Example 5 with CollisionObject

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();
    }
}
Also used : CollisionObject(com.bulletphysics.collision.dispatch.CollisionObject) Transform(com.bulletphysics.linearmath.Transform) TypedConstraint(com.bulletphysics.dynamics.constraintsolver.TypedConstraint) ManifoldPoint(com.bulletphysics.collision.narrowphase.ManifoldPoint) Stack(com.bulletphysics.util.Stack)

Aggregations

CollisionObject (com.bulletphysics.collision.dispatch.CollisionObject)19 ManifoldPoint (com.bulletphysics.collision.narrowphase.ManifoldPoint)12 TypedConstraint (com.bulletphysics.dynamics.constraintsolver.TypedConstraint)11 Stack (com.bulletphysics.util.Stack)10 Transform (com.bulletphysics.linearmath.Transform)9 Vector3f (javax.vecmath.Vector3f)6 PersistentManifold (com.bulletphysics.collision.narrowphase.PersistentManifold)2 PhysicsCollisionObject (com.jme3.bullet.collision.PhysicsCollisionObject)2 ContactAddedCallback (com.bulletphysics.ContactAddedCallback)1 ContactDestroyedCallback (com.bulletphysics.ContactDestroyedCallback)1 ContactProcessedCallback (com.bulletphysics.ContactProcessedCallback)1 BroadphaseInterface (com.bulletphysics.collision.broadphase.BroadphaseInterface)1 BroadphaseProxy (com.bulletphysics.collision.broadphase.BroadphaseProxy)1 OverlapFilterCallback (com.bulletphysics.collision.broadphase.OverlapFilterCallback)1 PairCachingGhostObject (com.bulletphysics.collision.dispatch.PairCachingGhostObject)1 SphereShape (com.bulletphysics.collision.shapes.SphereShape)1 RigidBody (com.bulletphysics.dynamics.RigidBody)1 PhysicsCollisionGroupListener (com.jme3.bullet.collision.PhysicsCollisionGroupListener)1 PhysicsJoint (com.jme3.bullet.joints.PhysicsJoint)1 PhysicsGhostObject (com.jme3.bullet.objects.PhysicsGhostObject)1