Search in sources :

Example 56 with Transform

use of com.bulletphysics.linearmath.Transform in project bdx by GoranM.

the class SimpleDynamicsWorld method integrateTransforms.

protected void integrateTransforms(float timeStep) {
    Stack stack = Stack.enter();
    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) {
            if (body.isActive() && (!body.isStaticObject())) {
                body.predictIntegratedTransform(timeStep, predictedTrans);
                body.proceedToTransform(predictedTrans);
            }
        }
    }
    stack.leave();
}
Also used : CollisionObject(com.bulletphysics.collision.dispatch.CollisionObject) Transform(com.bulletphysics.linearmath.Transform) Stack(com.bulletphysics.util.Stack)

Example 57 with Transform

use of com.bulletphysics.linearmath.Transform in project bdx by GoranM.

the class SimpleDynamicsWorld method synchronizeMotionStates.

public void synchronizeMotionStates() {
    Stack stack = Stack.enter();
    Transform tmpTrans = stack.allocTransform();
    // todo: iterate over awake simulation islands!
    for (int i = 0; i < collisionObjects.size(); i++) {
        CollisionObject colObj = collisionObjects.getQuick(i);
        RigidBody body = RigidBody.upcast(colObj);
        if (body != null && body.getMotionState() != null) {
            if (body.getActivationState() != CollisionObject.ISLAND_SLEEPING) {
                body.getMotionState().setWorldTransform(body.getWorldTransform(tmpTrans));
            }
        }
    }
    stack.leave();
}
Also used : CollisionObject(com.bulletphysics.collision.dispatch.CollisionObject) Transform(com.bulletphysics.linearmath.Transform) Stack(com.bulletphysics.util.Stack)

Example 58 with Transform

use of com.bulletphysics.linearmath.Transform in project bdx by GoranM.

the class KinematicCharacterController method recoverFromPenetration.

protected boolean recoverFromPenetration(CollisionWorld collisionWorld) {
    boolean penetration = false;
    Stack stack = Stack.enter();
    collisionWorld.getDispatcher().dispatchAllCollisionPairs(ghostObject.getOverlappingPairCache(), collisionWorld.getDispatchInfo(), collisionWorld.getDispatcher());
    currentPosition.set(ghostObject.getWorldTransform(stack.allocTransform()).origin);
    float maxPen = 0.0f;
    for (int i = 0; i < ghostObject.getOverlappingPairCache().getNumOverlappingPairs(); i++) {
        manifoldArray.clear();
        BroadphasePair collisionPair = ghostObject.getOverlappingPairCache().getOverlappingPairArray().getQuick(i);
        if (collisionPair.algorithm != null) {
            collisionPair.algorithm.getAllContactManifolds(manifoldArray);
        }
        for (int j = 0; j < manifoldArray.size(); j++) {
            PersistentManifold manifold = manifoldArray.getQuick(j);
            float directionSign = manifold.getBody0() == ghostObject ? -1.0f : 1.0f;
            for (int p = 0; p < manifold.getNumContacts(); p++) {
                ManifoldPoint pt = manifold.getContactPoint(p);
                float dist = pt.getDistance();
                if (dist < 0.0f) {
                    if (dist < maxPen) {
                        maxPen = dist;
                        //??
                        touchingNormal.set(pt.normalWorldOnB);
                        touchingNormal.scale(directionSign);
                    }
                    currentPosition.scaleAdd(directionSign * dist * 0.2f, pt.normalWorldOnB, currentPosition);
                    penetration = true;
                } else {
                //printf("touching %f\n", dist);
                }
            }
        //manifold->clearManifold();
        }
    }
    Transform newTrans = ghostObject.getWorldTransform(stack.allocTransform());
    newTrans.origin.set(currentPosition);
    ghostObject.setWorldTransform(newTrans);
    //printf("m_touchingNormal = %f,%f,%f\n",m_touchingNormal[0],m_touchingNormal[1],m_touchingNormal[2]);
    //System.out.println("recoverFromPenetration "+penetration+" "+touchingNormal);
    stack.leave();
    return penetration;
}
Also used : ManifoldPoint(com.bulletphysics.collision.narrowphase.ManifoldPoint) PersistentManifold(com.bulletphysics.collision.narrowphase.PersistentManifold) BroadphasePair(com.bulletphysics.collision.broadphase.BroadphasePair) Transform(com.bulletphysics.linearmath.Transform) ManifoldPoint(com.bulletphysics.collision.narrowphase.ManifoldPoint) Stack(com.bulletphysics.util.Stack)

Example 59 with Transform

use of com.bulletphysics.linearmath.Transform in project bdx by GoranM.

the class KinematicCharacterController method stepUp.

protected void stepUp(CollisionWorld world) {
    // phase 1: up
    Stack stack = Stack.enter();
    Transform start = stack.allocTransform();
    Transform end = stack.allocTransform();
    targetPosition.scaleAdd(stepHeight + (verticalOffset > 0.0 ? verticalOffset : 0.0f), upAxisDirection[upAxis], currentPosition);
    start.setIdentity();
    end.setIdentity();
    /* FIXME: Handle penetration properly */
    start.origin.scaleAdd(convexShape.getMargin() + addedMargin, upAxisDirection[upAxis], currentPosition);
    end.origin.set(targetPosition);
    // Find only sloped/flat surface hits, avoid wall and ceiling hits...
    Vector3f up = stack.allocVector3f();
    up.scale(-1f, upAxisDirection[upAxis]);
    KinematicClosestNotMeConvexResultCallback callback = new KinematicClosestNotMeConvexResultCallback(ghostObject, up, 0.0f);
    callback.collisionFilterGroup = getGhostObject().getBroadphaseHandle().collisionFilterGroup;
    callback.collisionFilterMask = getGhostObject().getBroadphaseHandle().collisionFilterMask;
    if (useGhostObjectSweepTest) {
        ghostObject.convexSweepTest(convexShape, start, end, callback, world.getDispatchInfo().allowedCcdPenetration);
    } else {
        world.convexSweepTest(convexShape, start, end, callback);
    }
    if (callback.hasHit()) {
        // we moved up only a fraction of the step height
        currentStepOffset = stepHeight * callback.closestHitFraction;
        currentPosition.interpolate(currentPosition, targetPosition, callback.closestHitFraction);
        verticalVelocity = 0.0f;
        verticalOffset = 0.0f;
    } else {
        currentStepOffset = stepHeight;
        currentPosition.set(targetPosition);
    }
    stack.leave();
}
Also used : Vector3f(javax.vecmath.Vector3f) Transform(com.bulletphysics.linearmath.Transform) Stack(com.bulletphysics.util.Stack)

Example 60 with Transform

use of com.bulletphysics.linearmath.Transform in project bdx by GoranM.

the class KinematicCharacterController method playerStep.

public void playerStep(CollisionWorld collisionWorld, float dt) {
    // quick check...
    if (!useWalkDirection && velocityTimeInterval <= 0.0f) {
        // no motion
        return;
    }
    wasOnGround = onGround();
    // Update fall velocity.
    verticalVelocity -= gravity * dt;
    if (verticalVelocity > 0.0 && verticalVelocity > jumpSpeed) {
        verticalVelocity = jumpSpeed;
    }
    if (verticalVelocity < 0.0 && Math.abs(verticalVelocity) > Math.abs(fallSpeed)) {
        verticalVelocity = -Math.abs(fallSpeed);
    }
    verticalOffset = verticalVelocity * dt;
    Stack stack = Stack.enter();
    Transform xform = ghostObject.getWorldTransform(stack.allocTransform());
    //printf("walkDirection(%f,%f,%f)\n",walkDirection[0],walkDirection[1],walkDirection[2]);
    //printf("walkSpeed=%f\n",walkSpeed);
    stepUp(collisionWorld);
    if (useWalkDirection) {
        //System.out.println("playerStep 3");
        stepForwardAndStrafe(collisionWorld, walkDirection);
    } else {
        System.out.println("playerStep 4");
        //printf("  time: %f", m_velocityTimeInterval);
        // still have some time left for moving!
        float dtMoving = (dt < velocityTimeInterval) ? dt : velocityTimeInterval;
        velocityTimeInterval -= dt;
        // how far will we move while we are moving?
        Vector3f move = stack.allocVector3f();
        move.scale(dtMoving, walkDirection);
        //printf("  dtMoving: %f", dtMoving);
        // okay, step
        stepForwardAndStrafe(collisionWorld, move);
    }
    stepDown(collisionWorld, dt);
    //printf("\n");
    xform.origin.set(currentPosition);
    ghostObject.setWorldTransform(xform);
    stack.leave();
}
Also used : Vector3f(javax.vecmath.Vector3f) Transform(com.bulletphysics.linearmath.Transform) Stack(com.bulletphysics.util.Stack)

Aggregations

Transform (com.bulletphysics.linearmath.Transform)81 Stack (com.bulletphysics.util.Stack)65 Vector3f (javax.vecmath.Vector3f)53 CollisionShape (com.bulletphysics.collision.shapes.CollisionShape)11 ManifoldPoint (com.bulletphysics.collision.narrowphase.ManifoldPoint)10 CompoundShape (com.bulletphysics.collision.shapes.CompoundShape)10 CollisionObject (com.bulletphysics.collision.dispatch.CollisionObject)9 Matrix3f (javax.vecmath.Matrix3f)8 TypedConstraint (com.bulletphysics.dynamics.constraintsolver.TypedConstraint)7 SphereShape (com.bulletphysics.collision.shapes.SphereShape)5 ConcaveShape (com.bulletphysics.collision.shapes.ConcaveShape)4 ConvexShape (com.bulletphysics.collision.shapes.ConvexShape)4 PersistentManifold (com.bulletphysics.collision.narrowphase.PersistentManifold)3 VoronoiSimplexSolver (com.bulletphysics.collision.narrowphase.VoronoiSimplexSolver)3 StaticPlaneShape (com.bulletphysics.collision.shapes.StaticPlaneShape)3 BroadphaseInterface (com.bulletphysics.collision.broadphase.BroadphaseInterface)2 ConvexCast (com.bulletphysics.collision.narrowphase.ConvexCast)2 CastResult (com.bulletphysics.collision.narrowphase.ConvexCast.CastResult)2 GjkConvexCast (com.bulletphysics.collision.narrowphase.GjkConvexCast)2 SubsimplexConvexCast (com.bulletphysics.collision.narrowphase.SubsimplexConvexCast)2