Search in sources :

Example 61 with Stack

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

the class TriangleMeshShape method localGetSupportingVertex.

public Vector3f localGetSupportingVertex(Vector3f vec, Vector3f out) {
    Stack stack = Stack.enter();
    Vector3f tmp = stack.allocVector3f();
    Vector3f supportVertex = out;
    Transform ident = stack.allocTransform();
    ident.setIdentity();
    SupportVertexCallback supportCallback = new SupportVertexCallback(vec, ident);
    Vector3f aabbMax = stack.allocVector3f();
    aabbMax.set(1e30f, 1e30f, 1e30f);
    tmp.negate(aabbMax);
    processAllTriangles(supportCallback, tmp, aabbMax);
    supportCallback.getSupportVertexLocal(supportVertex);
    stack.leave();
    return out;
}
Also used : Vector3f(javax.vecmath.Vector3f) Transform(com.bulletphysics.linearmath.Transform) Stack(com.bulletphysics.util.Stack)

Example 62 with Stack

use of com.bulletphysics.util.Stack 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 63 with Stack

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

the class DiscreteDynamicsWorld method stepSimulation.

@Override
public int stepSimulation(float timeStep, int maxSubSteps, float fixedTimeStep) {
    startProfiling(timeStep);
    long t0 = Clock.nanoTime();
    BulletStats.pushProfile("stepSimulation");
    Stack stack = Stack.enter();
    int sp = stack.getSp();
    try {
        int numSimulationSubSteps = 0;
        if (maxSubSteps != 0) {
            // fixed timestep with interpolation
            localTime += timeStep;
            if (localTime >= fixedTimeStep) {
                numSimulationSubSteps = (int) (localTime / fixedTimeStep);
                localTime -= numSimulationSubSteps * fixedTimeStep;
            }
        } else {
            //variable timestep
            fixedTimeStep = timeStep;
            localTime = timeStep;
            if (ScalarUtil.fuzzyZero(timeStep)) {
                numSimulationSubSteps = 0;
                maxSubSteps = 0;
            } else {
                numSimulationSubSteps = 1;
                maxSubSteps = 1;
            }
        }
        // process some debugging flags
        if (getDebugDrawer() != null) {
            BulletGlobals.setDeactivationDisabled((getDebugDrawer().getDebugMode() & DebugDrawModes.NO_DEACTIVATION) != 0);
        }
        if (numSimulationSubSteps != 0) {
            saveKinematicState(fixedTimeStep);
            applyGravity();
            // clamp the number of substeps, to prevent simulation grinding spiralling down to a halt
            int clampedSimulationSteps = (numSimulationSubSteps > maxSubSteps) ? maxSubSteps : numSimulationSubSteps;
            for (int i = 0; i < clampedSimulationSteps; i++) {
                internalSingleStepSimulation(fixedTimeStep);
                synchronizeMotionStates();
            }
        }
        synchronizeMotionStates();
        clearForces();
        //#ifndef BT_NO_PROFILE
        CProfileManager.incrementFrameCounter();
        return numSimulationSubSteps;
    } finally {
        BulletStats.popProfile();
        BulletStats.stepSimulationTime = (Clock.nanoTime() - t0) / 1000000;
        stack.leave(sp);
    }
}
Also used : TypedConstraint(com.bulletphysics.dynamics.constraintsolver.TypedConstraint) ManifoldPoint(com.bulletphysics.collision.narrowphase.ManifoldPoint) Stack(com.bulletphysics.util.Stack)

Example 64 with Stack

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

the class DiscreteDynamicsWorld method internalSingleStepSimulation.

protected void internalSingleStepSimulation(float timeStep) {
    BulletStats.pushProfile("internalSingleStepSimulation");
    Stack stack = Stack.enter();
    int sp = stack.getSp();
    try {
        // apply gravity, predict motion
        predictUnconstraintMotion(timeStep);
        DispatcherInfo dispatchInfo = getDispatchInfo();
        dispatchInfo.timeStep = timeStep;
        dispatchInfo.stepCount = 0;
        dispatchInfo.debugDraw = getDebugDrawer();
        // perform collision detection
        performDiscreteCollisionDetection();
        calculateSimulationIslands();
        getSolverInfo().timeStep = timeStep;
        // solve contact and other joint constraints
        solveConstraints(getSolverInfo());
        //CallbackTriggers();
        // integrate transforms
        integrateTransforms(timeStep);
        // update vehicle simulation
        updateActions(timeStep);
        // update vehicle simulation
        updateVehicles(timeStep);
        updateActivationState(timeStep);
        if (internalTickCallback != null) {
            internalTickCallback.internalTick(this, timeStep);
        }
    } finally {
        BulletStats.popProfile();
        stack.leave(sp);
    }
}
Also used : DispatcherInfo(com.bulletphysics.collision.broadphase.DispatcherInfo) TypedConstraint(com.bulletphysics.dynamics.constraintsolver.TypedConstraint) ManifoldPoint(com.bulletphysics.collision.narrowphase.ManifoldPoint) Stack(com.bulletphysics.util.Stack)

Example 65 with Stack

use of com.bulletphysics.util.Stack 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)

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