Search in sources :

Example 71 with Stack

use of com.bulletphysics.util.Stack in project bdx by GoranM.

the class RigidBody method updateDeactivation.

public void updateDeactivation(float timeStep) {
    if ((getActivationState() == ISLAND_SLEEPING) || (getActivationState() == DISABLE_DEACTIVATION)) {
        return;
    }
    Stack stack = Stack.enter();
    if ((getLinearVelocity(stack.allocVector3f()).lengthSquared() < linearSleepingThreshold * linearSleepingThreshold) && (getAngularVelocity(stack.allocVector3f()).lengthSquared() < angularSleepingThreshold * angularSleepingThreshold)) {
        deactivationTime += timeStep;
    } else {
        deactivationTime = 0f;
        setActivationState(0);
    }
    stack.leave();
}
Also used : Stack(com.bulletphysics.util.Stack)

Example 72 with Stack

use of com.bulletphysics.util.Stack in project bdx by GoranM.

the class SimpleDynamicsWorld method predictUnconstraintMotion.

protected void predictUnconstraintMotion(float timeStep) {
    Stack stack = Stack.enter();
    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.isStaticObject()) {
                if (body.isActive()) {
                    body.applyGravity();
                    body.integrateVelocities(timeStep);
                    body.applyDamping(timeStep);
                    body.predictIntegratedTransform(timeStep, body.getInterpolationWorldTransform(tmpTrans));
                }
            }
        }
    }
    stack.leave();
}
Also used : CollisionObject(com.bulletphysics.collision.dispatch.CollisionObject) Transform(com.bulletphysics.linearmath.Transform) Stack(com.bulletphysics.util.Stack)

Example 73 with Stack

use of com.bulletphysics.util.Stack in project bdx by GoranM.

the class SimpleDynamicsWorld method updateAabbs.

@Override
public void updateAabbs() {
    Stack stack = Stack.enter();
    Transform tmpTrans = stack.allocTransform();
    //		Transform predictedTrans = stack.allocTransform();
    Vector3f minAabb = stack.allocVector3f(), maxAabb = stack.allocVector3f();
    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())) {
                colObj.getCollisionShape().getAabb(colObj.getWorldTransform(tmpTrans), minAabb, maxAabb);
                BroadphaseInterface bp = getBroadphase();
                bp.setAabb(body.getBroadphaseHandle(), minAabb, maxAabb, dispatcher1);
            }
        }
    }
    stack.leave();
}
Also used : CollisionObject(com.bulletphysics.collision.dispatch.CollisionObject) BroadphaseInterface(com.bulletphysics.collision.broadphase.BroadphaseInterface) Vector3f(javax.vecmath.Vector3f) Transform(com.bulletphysics.linearmath.Transform) Stack(com.bulletphysics.util.Stack)

Example 74 with Stack

use of com.bulletphysics.util.Stack in project bdx by GoranM.

the class KinematicCharacterController method stepDown.

protected void stepDown(CollisionWorld collisionWorld, float dt) {
    Stack stack = Stack.enter();
    Transform start = stack.allocTransform();
    Transform end = stack.allocTransform();
    // phase 3: down
    float additionalDownStep = (wasOnGround) ? stepHeight : 0.0f;
    Vector3f step_drop = stack.allocVector3f();
    step_drop.scale(currentStepOffset + additionalDownStep, upAxisDirection[upAxis]);
    float downVelocity = (additionalDownStep == 0.0f && verticalVelocity < 0.0f ? -verticalVelocity : 0.0f) * dt;
    Vector3f gravity_drop = stack.allocVector3f();
    gravity_drop.scale(downVelocity, upAxisDirection[upAxis]);
    targetPosition.sub(step_drop);
    targetPosition.sub(gravity_drop);
    start.setIdentity();
    end.setIdentity();
    start.origin.set(currentPosition);
    end.origin.set(targetPosition);
    KinematicClosestNotMeConvexResultCallback callback = new KinematicClosestNotMeConvexResultCallback(ghostObject, upAxisDirection[upAxis], maxSlopeCosine);
    callback.collisionFilterGroup = getGhostObject().getBroadphaseHandle().collisionFilterGroup;
    callback.collisionFilterMask = getGhostObject().getBroadphaseHandle().collisionFilterMask;
    if (useGhostObjectSweepTest) {
        ghostObject.convexSweepTest(convexShape, start, end, callback, collisionWorld.getDispatchInfo().allowedCcdPenetration);
    } else {
        collisionWorld.convexSweepTest(convexShape, start, end, callback);
    }
    if (callback.hasHit()) {
        // we dropped a fraction of the height -> hit floor
        currentPosition.interpolate(currentPosition, targetPosition, callback.closestHitFraction);
        verticalVelocity = 0.0f;
        verticalOffset = 0.0f;
    } else {
        // we dropped the full height
        currentPosition.set(targetPosition);
    }
    stack.leave();
}
Also used : Vector3f(javax.vecmath.Vector3f) Transform(com.bulletphysics.linearmath.Transform) Stack(com.bulletphysics.util.Stack)

Example 75 with Stack

use of com.bulletphysics.util.Stack in project bdx by GoranM.

the class KinematicCharacterController method preStep.

public void preStep(CollisionWorld collisionWorld) {
    int numPenetrationLoops = 0;
    touchingContact = false;
    while (recoverFromPenetration(collisionWorld)) {
        numPenetrationLoops++;
        touchingContact = true;
        if (numPenetrationLoops > 4) {
            //printf("character could not recover from penetration = %d\n", numPenetrationLoops);
            break;
        }
    }
    Stack stack = Stack.enter();
    currentPosition.set(ghostObject.getWorldTransform(stack.allocTransform()).origin);
    targetPosition.set(currentPosition);
    //printf("m_targetPosition=%f,%f,%f\n",m_targetPosition[0],m_targetPosition[1],m_targetPosition[2]);
    stack.leave();
}
Also used : ManifoldPoint(com.bulletphysics.collision.narrowphase.ManifoldPoint) Stack(com.bulletphysics.util.Stack)

Aggregations

Stack (com.bulletphysics.util.Stack)252 Vector3f (javax.vecmath.Vector3f)197 Transform (com.bulletphysics.linearmath.Transform)65 Matrix3f (javax.vecmath.Matrix3f)23 ManifoldPoint (com.bulletphysics.collision.narrowphase.ManifoldPoint)15 AABB (com.bulletphysics.extras.gimpact.BoxCollision.AABB)15 StaticAlloc (com.bulletphysics.util.StaticAlloc)12 CollisionObject (com.bulletphysics.collision.dispatch.CollisionObject)10 CollisionShape (com.bulletphysics.collision.shapes.CollisionShape)10 TypedConstraint (com.bulletphysics.dynamics.constraintsolver.TypedConstraint)10 Vector4f (javax.vecmath.Vector4f)8 CompoundShape (com.bulletphysics.collision.shapes.CompoundShape)6 ConcaveShape (com.bulletphysics.collision.shapes.ConcaveShape)5 SphereShape (com.bulletphysics.collision.shapes.SphereShape)5 RigidBody (com.bulletphysics.dynamics.RigidBody)5 Quat4f (javax.vecmath.Quat4f)5 ConvexShape (com.bulletphysics.collision.shapes.ConvexShape)4 ObjectArrayList (com.bulletphysics.util.ObjectArrayList)4 PersistentManifold (com.bulletphysics.collision.narrowphase.PersistentManifold)3 VoronoiSimplexSolver (com.bulletphysics.collision.narrowphase.VoronoiSimplexSolver)3