Search in sources :

Example 21 with Transform

use of com.bulletphysics.linearmath.Transform 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 22 with Transform

use of com.bulletphysics.linearmath.Transform 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 23 with Transform

use of com.bulletphysics.linearmath.Transform 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 24 with Transform

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

the class KinematicCharacterController method warp.

public void warp(Vector3f origin) {
    Stack stack = Stack.enter();
    Transform xform = stack.allocTransform();
    xform.setIdentity();
    xform.origin.set(origin);
    ghostObject.setWorldTransform(xform);
    stack.leave();
}
Also used : Transform(com.bulletphysics.linearmath.Transform) Stack(com.bulletphysics.util.Stack)

Example 25 with Transform

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

the class ConeTwistConstraint method solveConstraint.

@Override
public void solveConstraint(float timeStep) {
    Stack stack = Stack.enter();
    Vector3f tmp = stack.allocVector3f();
    Vector3f tmp2 = stack.allocVector3f();
    Vector3f tmpVec = stack.allocVector3f();
    Transform tmpTrans = stack.allocTransform();
    Vector3f pivotAInW = stack.alloc(rbAFrame.origin);
    rbA.getCenterOfMassTransform(tmpTrans).transform(pivotAInW);
    Vector3f pivotBInW = stack.alloc(rbBFrame.origin);
    rbB.getCenterOfMassTransform(tmpTrans).transform(pivotBInW);
    float tau = 0.3f;
    // linear part
    if (!angularOnly) {
        Vector3f rel_pos1 = stack.allocVector3f();
        rel_pos1.sub(pivotAInW, rbA.getCenterOfMassPosition(tmpVec));
        Vector3f rel_pos2 = stack.allocVector3f();
        rel_pos2.sub(pivotBInW, rbB.getCenterOfMassPosition(tmpVec));
        Vector3f vel1 = rbA.getVelocityInLocalPoint(rel_pos1, stack.allocVector3f());
        Vector3f vel2 = rbB.getVelocityInLocalPoint(rel_pos2, stack.allocVector3f());
        Vector3f vel = stack.allocVector3f();
        vel.sub(vel1, vel2);
        for (int i = 0; i < 3; i++) {
            Vector3f normal = jac[i].linearJointAxis;
            float jacDiagABInv = 1f / jac[i].getDiagonal();
            float rel_vel;
            rel_vel = normal.dot(vel);
            // positional error (zeroth order error)
            tmp.sub(pivotAInW, pivotBInW);
            // this is the error projected on the normal
            float depth = -(tmp).dot(normal);
            float impulse = depth * tau / timeStep * jacDiagABInv - rel_vel * jacDiagABInv;
            appliedImpulse += impulse;
            Vector3f impulse_vector = stack.allocVector3f();
            impulse_vector.scale(impulse, normal);
            tmp.sub(pivotAInW, rbA.getCenterOfMassPosition(tmpVec));
            rbA.applyImpulse(impulse_vector, tmp);
            tmp.negate(impulse_vector);
            tmp2.sub(pivotBInW, rbB.getCenterOfMassPosition(tmpVec));
            rbB.applyImpulse(tmp, tmp2);
        }
    }
    {
        // solve angular part
        Vector3f angVelA = getRigidBodyA().getAngularVelocity(stack.allocVector3f());
        Vector3f angVelB = getRigidBodyB().getAngularVelocity(stack.allocVector3f());
        // solve swing limit
        if (solveSwingLimit) {
            tmp.sub(angVelB, angVelA);
            float amplitude = ((tmp).dot(swingAxis) * relaxationFactor * relaxationFactor + swingCorrection * (1f / timeStep) * biasFactor);
            float impulseMag = amplitude * kSwing;
            // Clamp the accumulated impulse
            float temp = accSwingLimitImpulse;
            accSwingLimitImpulse = Math.max(accSwingLimitImpulse + impulseMag, 0.0f);
            impulseMag = accSwingLimitImpulse - temp;
            Vector3f impulse = stack.allocVector3f();
            impulse.scale(impulseMag, swingAxis);
            rbA.applyTorqueImpulse(impulse);
            tmp.negate(impulse);
            rbB.applyTorqueImpulse(tmp);
        }
        // solve twist limit
        if (solveTwistLimit) {
            tmp.sub(angVelB, angVelA);
            float amplitude = ((tmp).dot(twistAxis) * relaxationFactor * relaxationFactor + twistCorrection * (1f / timeStep) * biasFactor);
            float impulseMag = amplitude * kTwist;
            // Clamp the accumulated impulse
            float temp = accTwistLimitImpulse;
            accTwistLimitImpulse = Math.max(accTwistLimitImpulse + impulseMag, 0.0f);
            impulseMag = accTwistLimitImpulse - temp;
            Vector3f impulse = stack.allocVector3f();
            impulse.scale(impulseMag, twistAxis);
            rbA.applyTorqueImpulse(impulse);
            tmp.negate(impulse);
            rbB.applyTorqueImpulse(tmp);
        }
    }
    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