use of com.bulletphysics.linearmath.Transform in project bdx by GoranM.
the class SimpleDynamicsWorld method integrateTransforms.
protected void integrateTransforms(float timeStep) {
Stack stack = Stack.enter();
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) {
if (body.isActive() && (!body.isStaticObject())) {
body.predictIntegratedTransform(timeStep, predictedTrans);
body.proceedToTransform(predictedTrans);
}
}
}
stack.leave();
}
use of com.bulletphysics.linearmath.Transform in project bdx by GoranM.
the class SimpleDynamicsWorld method synchronizeMotionStates.
public void synchronizeMotionStates() {
Stack stack = Stack.enter();
Transform tmpTrans = stack.allocTransform();
// todo: iterate over awake simulation islands!
for (int i = 0; i < collisionObjects.size(); i++) {
CollisionObject colObj = collisionObjects.getQuick(i);
RigidBody body = RigidBody.upcast(colObj);
if (body != null && body.getMotionState() != null) {
if (body.getActivationState() != CollisionObject.ISLAND_SLEEPING) {
body.getMotionState().setWorldTransform(body.getWorldTransform(tmpTrans));
}
}
}
stack.leave();
}
use of com.bulletphysics.linearmath.Transform in project bdx by GoranM.
the class KinematicCharacterController method recoverFromPenetration.
protected boolean recoverFromPenetration(CollisionWorld collisionWorld) {
boolean penetration = false;
Stack stack = Stack.enter();
collisionWorld.getDispatcher().dispatchAllCollisionPairs(ghostObject.getOverlappingPairCache(), collisionWorld.getDispatchInfo(), collisionWorld.getDispatcher());
currentPosition.set(ghostObject.getWorldTransform(stack.allocTransform()).origin);
float maxPen = 0.0f;
for (int i = 0; i < ghostObject.getOverlappingPairCache().getNumOverlappingPairs(); i++) {
manifoldArray.clear();
BroadphasePair collisionPair = ghostObject.getOverlappingPairCache().getOverlappingPairArray().getQuick(i);
if (collisionPair.algorithm != null) {
collisionPair.algorithm.getAllContactManifolds(manifoldArray);
}
for (int j = 0; j < manifoldArray.size(); j++) {
PersistentManifold manifold = manifoldArray.getQuick(j);
float directionSign = manifold.getBody0() == ghostObject ? -1.0f : 1.0f;
for (int p = 0; p < manifold.getNumContacts(); p++) {
ManifoldPoint pt = manifold.getContactPoint(p);
float dist = pt.getDistance();
if (dist < 0.0f) {
if (dist < maxPen) {
maxPen = dist;
//??
touchingNormal.set(pt.normalWorldOnB);
touchingNormal.scale(directionSign);
}
currentPosition.scaleAdd(directionSign * dist * 0.2f, pt.normalWorldOnB, currentPosition);
penetration = true;
} else {
//printf("touching %f\n", dist);
}
}
//manifold->clearManifold();
}
}
Transform newTrans = ghostObject.getWorldTransform(stack.allocTransform());
newTrans.origin.set(currentPosition);
ghostObject.setWorldTransform(newTrans);
//printf("m_touchingNormal = %f,%f,%f\n",m_touchingNormal[0],m_touchingNormal[1],m_touchingNormal[2]);
//System.out.println("recoverFromPenetration "+penetration+" "+touchingNormal);
stack.leave();
return penetration;
}
use of com.bulletphysics.linearmath.Transform in project bdx by GoranM.
the class KinematicCharacterController method stepUp.
protected void stepUp(CollisionWorld world) {
// phase 1: up
Stack stack = Stack.enter();
Transform start = stack.allocTransform();
Transform end = stack.allocTransform();
targetPosition.scaleAdd(stepHeight + (verticalOffset > 0.0 ? verticalOffset : 0.0f), upAxisDirection[upAxis], currentPosition);
start.setIdentity();
end.setIdentity();
/* FIXME: Handle penetration properly */
start.origin.scaleAdd(convexShape.getMargin() + addedMargin, upAxisDirection[upAxis], currentPosition);
end.origin.set(targetPosition);
// Find only sloped/flat surface hits, avoid wall and ceiling hits...
Vector3f up = stack.allocVector3f();
up.scale(-1f, upAxisDirection[upAxis]);
KinematicClosestNotMeConvexResultCallback callback = new KinematicClosestNotMeConvexResultCallback(ghostObject, up, 0.0f);
callback.collisionFilterGroup = getGhostObject().getBroadphaseHandle().collisionFilterGroup;
callback.collisionFilterMask = getGhostObject().getBroadphaseHandle().collisionFilterMask;
if (useGhostObjectSweepTest) {
ghostObject.convexSweepTest(convexShape, start, end, callback, world.getDispatchInfo().allowedCcdPenetration);
} else {
world.convexSweepTest(convexShape, start, end, callback);
}
if (callback.hasHit()) {
// we moved up only a fraction of the step height
currentStepOffset = stepHeight * callback.closestHitFraction;
currentPosition.interpolate(currentPosition, targetPosition, callback.closestHitFraction);
verticalVelocity = 0.0f;
verticalOffset = 0.0f;
} else {
currentStepOffset = stepHeight;
currentPosition.set(targetPosition);
}
stack.leave();
}
use of com.bulletphysics.linearmath.Transform in project bdx by GoranM.
the class KinematicCharacterController method playerStep.
public void playerStep(CollisionWorld collisionWorld, float dt) {
// quick check...
if (!useWalkDirection && velocityTimeInterval <= 0.0f) {
// no motion
return;
}
wasOnGround = onGround();
// Update fall velocity.
verticalVelocity -= gravity * dt;
if (verticalVelocity > 0.0 && verticalVelocity > jumpSpeed) {
verticalVelocity = jumpSpeed;
}
if (verticalVelocity < 0.0 && Math.abs(verticalVelocity) > Math.abs(fallSpeed)) {
verticalVelocity = -Math.abs(fallSpeed);
}
verticalOffset = verticalVelocity * dt;
Stack stack = Stack.enter();
Transform xform = ghostObject.getWorldTransform(stack.allocTransform());
//printf("walkDirection(%f,%f,%f)\n",walkDirection[0],walkDirection[1],walkDirection[2]);
//printf("walkSpeed=%f\n",walkSpeed);
stepUp(collisionWorld);
if (useWalkDirection) {
//System.out.println("playerStep 3");
stepForwardAndStrafe(collisionWorld, walkDirection);
} else {
System.out.println("playerStep 4");
//printf(" time: %f", m_velocityTimeInterval);
// still have some time left for moving!
float dtMoving = (dt < velocityTimeInterval) ? dt : velocityTimeInterval;
velocityTimeInterval -= dt;
// how far will we move while we are moving?
Vector3f move = stack.allocVector3f();
move.scale(dtMoving, walkDirection);
//printf(" dtMoving: %f", dtMoving);
// okay, step
stepForwardAndStrafe(collisionWorld, move);
}
stepDown(collisionWorld, dt);
//printf("\n");
xform.origin.set(currentPosition);
ghostObject.setWorldTransform(xform);
stack.leave();
}
Aggregations