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;
}
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();
}
}
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);
}
}
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);
}
}
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();
}
}
Aggregations