Search in sources :

Example 66 with Vector3f

use of javax.vecmath.Vector3f 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 67 with Vector3f

use of javax.vecmath.Vector3f in project bdx by GoranM.

the class RigidBody method computeImpulseDenominator.

public float computeImpulseDenominator(Vector3f pos, Vector3f normal) {
    Stack stack = Stack.enter();
    Vector3f r0 = stack.allocVector3f();
    r0.sub(pos, getCenterOfMassPosition(stack.allocVector3f()));
    Vector3f c0 = stack.allocVector3f();
    c0.cross(r0, normal);
    Vector3f tmp = stack.allocVector3f();
    MatrixUtil.transposeTransform(tmp, c0, getInvInertiaTensorWorld(stack.allocMatrix3f()));
    Vector3f vec = stack.allocVector3f();
    vec.cross(tmp, r0);
    float result = inverseMass + normal.dot(vec);
    stack.leave();
    return result;
}
Also used : Vector3f(javax.vecmath.Vector3f) Stack(com.bulletphysics.util.Stack)

Example 68 with Vector3f

use of javax.vecmath.Vector3f in project bdx by GoranM.

the class RigidBody method applyForce.

public void applyForce(Vector3f force, Vector3f rel_pos) {
    Stack stack = Stack.enter();
    applyCentralForce(force);
    Vector3f tmp = stack.allocVector3f();
    tmp.cross(rel_pos, force);
    tmp.scale(angularFactor);
    applyTorque(tmp);
    stack.leave();
}
Also used : Vector3f(javax.vecmath.Vector3f) Stack(com.bulletphysics.util.Stack)

Example 69 with Vector3f

use of javax.vecmath.Vector3f in project bdx by GoranM.

the class RigidBody method applyImpulse.

@StaticAlloc
public void applyImpulse(Vector3f impulse, Vector3f rel_pos) {
    if (inverseMass != 0f) {
        applyCentralImpulse(impulse);
        if (angularFactor != 0f) {
            Stack stack = Stack.enter();
            Vector3f tmp = stack.allocVector3f();
            tmp.cross(rel_pos, impulse);
            tmp.scale(angularFactor);
            applyTorqueImpulse(tmp);
            stack.leave();
        }
    }
}
Also used : Vector3f(javax.vecmath.Vector3f) Stack(com.bulletphysics.util.Stack) StaticAlloc(com.bulletphysics.util.StaticAlloc)

Example 70 with Vector3f

use of javax.vecmath.Vector3f 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)

Aggregations

Vector3f (javax.vecmath.Vector3f)266 Stack (com.bulletphysics.util.Stack)197 Transform (com.bulletphysics.linearmath.Transform)53 Matrix3f (javax.vecmath.Matrix3f)25 ManifoldPoint (com.bulletphysics.collision.narrowphase.ManifoldPoint)14 StaticAlloc (com.bulletphysics.util.StaticAlloc)12 Matrix4f (javax.vecmath.Matrix4f)10 Vector4f (javax.vecmath.Vector4f)8 CollisionShape (com.bulletphysics.collision.shapes.CollisionShape)7 TypedConstraint (com.bulletphysics.dynamics.constraintsolver.TypedConstraint)7 CollisionObject (com.bulletphysics.collision.dispatch.CollisionObject)6 ObjectArrayList (com.bulletphysics.util.ObjectArrayList)5 Quat4f (javax.vecmath.Quat4f)5 ConvexShape (com.bulletphysics.collision.shapes.ConvexShape)4 SphereShape (com.bulletphysics.collision.shapes.SphereShape)4 RigidBody (com.bulletphysics.dynamics.RigidBody)4 HashMap (java.util.HashMap)4 VoronoiSimplexSolver (com.bulletphysics.collision.narrowphase.VoronoiSimplexSolver)3 CompoundShape (com.bulletphysics.collision.shapes.CompoundShape)3 ConcaveShape (com.bulletphysics.collision.shapes.ConcaveShape)3