Search in sources :

Example 16 with Transform

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();
}
Also used : Vector3f(javax.vecmath.Vector3f) Transform(com.bulletphysics.linearmath.Transform) Stack(com.bulletphysics.util.Stack)

Example 17 with Transform

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();
}
Also used : Vector3f(javax.vecmath.Vector3f) Transform(com.bulletphysics.linearmath.Transform) Stack(com.bulletphysics.util.Stack)

Example 18 with Transform

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;
}
Also used : Vector3f(javax.vecmath.Vector3f) Transform(com.bulletphysics.linearmath.Transform) Stack(com.bulletphysics.util.Stack)

Example 19 with Transform

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();
    }
}
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 20 with Transform

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();
    }
}
Also used : CollisionObject(com.bulletphysics.collision.dispatch.CollisionObject) Transform(com.bulletphysics.linearmath.Transform) TypedConstraint(com.bulletphysics.dynamics.constraintsolver.TypedConstraint) ManifoldPoint(com.bulletphysics.collision.narrowphase.ManifoldPoint) Stack(com.bulletphysics.util.Stack)

Aggregations

Transform (com.bulletphysics.linearmath.Transform)81 Stack (com.bulletphysics.util.Stack)65 Vector3f (javax.vecmath.Vector3f)53 CollisionShape (com.bulletphysics.collision.shapes.CollisionShape)11 ManifoldPoint (com.bulletphysics.collision.narrowphase.ManifoldPoint)10 CompoundShape (com.bulletphysics.collision.shapes.CompoundShape)10 CollisionObject (com.bulletphysics.collision.dispatch.CollisionObject)9 Matrix3f (javax.vecmath.Matrix3f)8 TypedConstraint (com.bulletphysics.dynamics.constraintsolver.TypedConstraint)7 SphereShape (com.bulletphysics.collision.shapes.SphereShape)5 ConcaveShape (com.bulletphysics.collision.shapes.ConcaveShape)4 ConvexShape (com.bulletphysics.collision.shapes.ConvexShape)4 PersistentManifold (com.bulletphysics.collision.narrowphase.PersistentManifold)3 VoronoiSimplexSolver (com.bulletphysics.collision.narrowphase.VoronoiSimplexSolver)3 StaticPlaneShape (com.bulletphysics.collision.shapes.StaticPlaneShape)3 BroadphaseInterface (com.bulletphysics.collision.broadphase.BroadphaseInterface)2 ConvexCast (com.bulletphysics.collision.narrowphase.ConvexCast)2 CastResult (com.bulletphysics.collision.narrowphase.ConvexCast.CastResult)2 GjkConvexCast (com.bulletphysics.collision.narrowphase.GjkConvexCast)2 SubsimplexConvexCast (com.bulletphysics.collision.narrowphase.SubsimplexConvexCast)2