use of com.bulletphysics.linearmath.Transform in project bdx by GoranM.
the class ConeShape method calculateLocalInertia.
@Override
public void calculateLocalInertia(float mass, Vector3f inertia) {
Stack stack = Stack.enter();
Transform identity = stack.allocTransform();
identity.setIdentity();
Vector3f aabbMin = stack.allocVector3f(), aabbMax = stack.allocVector3f();
getAabb(identity, aabbMin, aabbMax);
Vector3f halfExtents = stack.allocVector3f();
halfExtents.sub(aabbMax, aabbMin);
halfExtents.scale(0.5f);
float margin = getMargin();
float lx = 2f * (halfExtents.x + margin);
float ly = 2f * (halfExtents.y + margin);
float lz = 2f * (halfExtents.z + margin);
float x2 = lx * lx;
float y2 = ly * ly;
float z2 = lz * lz;
float scaledmass = mass * 0.08333333f;
inertia.set(y2 + z2, x2 + z2, x2 + y2);
inertia.scale(scaledmass);
//inertia.x() = scaledmass * (y2+z2);
//inertia.y() = scaledmass * (x2+z2);
//inertia.z() = scaledmass * (x2+y2);
stack.leave();
}
use of com.bulletphysics.linearmath.Transform in project bdx by GoranM.
the class PolyhedralConvexShape method calculateLocalInertia.
@Override
public void calculateLocalInertia(float mass, Vector3f inertia) {
// not yet, return box inertia
Stack stack = Stack.enter();
float margin = getMargin();
Transform ident = stack.allocTransform();
ident.setIdentity();
Vector3f aabbMin = stack.allocVector3f(), aabbMax = stack.allocVector3f();
getAabb(ident, aabbMin, aabbMax);
Vector3f halfExtents = stack.allocVector3f();
halfExtents.sub(aabbMax, aabbMin);
halfExtents.scale(0.5f);
float lx = 2f * (halfExtents.x + margin);
float ly = 2f * (halfExtents.y + margin);
float lz = 2f * (halfExtents.z + margin);
float x2 = lx * lx;
float y2 = ly * ly;
float z2 = lz * lz;
float scaledmass = mass * 0.08333333f;
inertia.set(y2 + z2, x2 + z2, x2 + y2);
inertia.scale(scaledmass);
stack.leave();
}
use of com.bulletphysics.linearmath.Transform 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.linearmath.Transform 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();
}
}
use of com.bulletphysics.linearmath.Transform in project bdx by GoranM.
the class DiscreteDynamicsWorld method predictUnconstraintMotion.
protected void predictUnconstraintMotion(float timeStep) {
BulletStats.pushProfile("predictUnconstraintMotion");
Stack stack = Stack.enter();
int sp = stack.getSp();
try {
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.isStaticOrKinematicObject()) {
if (body.isActive()) {
body.integrateVelocities(timeStep);
// damping
body.applyDamping(timeStep);
body.predictIntegratedTransform(timeStep, body.getInterpolationWorldTransform(tmpTrans));
}
}
}
}
} finally {
stack.leave(sp);
BulletStats.popProfile();
}
}
Aggregations