Search in sources :

Example 36 with Stack

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

the class BoxShape method getHalfExtentsWithMargin.

public Vector3f getHalfExtentsWithMargin(Vector3f out) {
    Stack stack = Stack.enter();
    Vector3f halfExtents = getHalfExtentsWithoutMargin(out);
    Vector3f margin = stack.allocVector3f();
    margin.set(getMargin(), getMargin(), getMargin());
    halfExtents.add(margin);
    stack.leave();
    return out;
}
Also used : Vector3f(javax.vecmath.Vector3f) Stack(com.bulletphysics.util.Stack)

Example 37 with Stack

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

the class BoxShape method getPlaneEquation.

public void getPlaneEquation(Vector4f plane, int i) {
    Stack stack = Stack.enter();
    Vector3f halfExtents = getHalfExtentsWithoutMargin(stack.allocVector3f());
    switch(i) {
        case 0:
            plane.set(1f, 0f, 0f, -halfExtents.x);
            break;
        case 1:
            plane.set(-1f, 0f, 0f, -halfExtents.x);
            break;
        case 2:
            plane.set(0f, 1f, 0f, -halfExtents.y);
            break;
        case 3:
            plane.set(0f, -1f, 0f, -halfExtents.y);
            break;
        case 4:
            plane.set(0f, 0f, 1f, -halfExtents.z);
            break;
        case 5:
            plane.set(0f, 0f, -1f, -halfExtents.z);
            break;
        default:
            assert (false);
    }
    stack.leave();
}
Also used : Vector3f(javax.vecmath.Vector3f) Stack(com.bulletphysics.util.Stack)

Example 38 with Stack

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

the class CapsuleShape method localGetSupportingVertexWithoutMargin.

@Override
public Vector3f localGetSupportingVertexWithoutMargin(Vector3f vec0, Vector3f out) {
    Stack stack = Stack.enter();
    Vector3f supVec = out;
    supVec.set(0f, 0f, 0f);
    float maxDot = -1e30f;
    Vector3f vec = stack.alloc(vec0);
    float lenSqr = vec.lengthSquared();
    if (lenSqr < 0.0001f) {
        vec.set(1f, 0f, 0f);
    } else {
        float rlen = 1f / (float) Math.sqrt(lenSqr);
        vec.scale(rlen);
    }
    Vector3f vtx = stack.allocVector3f();
    float newDot;
    float radius = getRadius();
    Vector3f tmp1 = stack.allocVector3f();
    Vector3f tmp2 = stack.allocVector3f();
    Vector3f pos = stack.allocVector3f();
    {
        pos.set(0f, 0f, 0f);
        VectorUtil.setCoord(pos, getUpAxis(), getHalfHeight());
        VectorUtil.mul(tmp1, vec, localScaling);
        tmp1.scale(radius);
        tmp2.scale(getMargin(), vec);
        vtx.add(pos, tmp1);
        vtx.sub(tmp2);
        newDot = vec.dot(vtx);
        if (newDot > maxDot) {
            maxDot = newDot;
            supVec.set(vtx);
        }
    }
    {
        pos.set(0f, 0f, 0f);
        VectorUtil.setCoord(pos, getUpAxis(), -getHalfHeight());
        VectorUtil.mul(tmp1, vec, localScaling);
        tmp1.scale(radius);
        tmp2.scale(getMargin(), vec);
        vtx.add(pos, tmp1);
        vtx.sub(tmp2);
        newDot = vec.dot(vtx);
        if (newDot > maxDot) {
            maxDot = newDot;
            supVec.set(vtx);
        }
    }
    stack.leave();
    return out;
}
Also used : Vector3f(javax.vecmath.Vector3f) Stack(com.bulletphysics.util.Stack)

Example 39 with Stack

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

the class CollisionShape method calculateTemporalAabb.

///calculateTemporalAabb calculates the enclosing aabb for the moving object over interval [0..timeStep)
///result is conservative
public void calculateTemporalAabb(Transform curTrans, Vector3f linvel, Vector3f angvel, float timeStep, Vector3f temporalAabbMin, Vector3f temporalAabbMax) {
    //start with static aabb
    getAabb(curTrans, temporalAabbMin, temporalAabbMax);
    Stack stack = Stack.enter();
    float temporalAabbMaxx = temporalAabbMax.x;
    float temporalAabbMaxy = temporalAabbMax.y;
    float temporalAabbMaxz = temporalAabbMax.z;
    float temporalAabbMinx = temporalAabbMin.x;
    float temporalAabbMiny = temporalAabbMin.y;
    float temporalAabbMinz = temporalAabbMin.z;
    // add linear motion
    Vector3f linMotion = stack.alloc(linvel);
    linMotion.scale(timeStep);
    //todo: simd would have a vector max/min operation, instead of per-element access
    if (linMotion.x > 0f) {
        temporalAabbMaxx += linMotion.x;
    } else {
        temporalAabbMinx += linMotion.x;
    }
    if (linMotion.y > 0f) {
        temporalAabbMaxy += linMotion.y;
    } else {
        temporalAabbMiny += linMotion.y;
    }
    if (linMotion.z > 0f) {
        temporalAabbMaxz += linMotion.z;
    } else {
        temporalAabbMinz += linMotion.z;
    }
    //add conservative angular motion
    float angularMotion = angvel.length() * getAngularMotionDisc() * timeStep;
    Vector3f angularMotion3d = stack.allocVector3f();
    angularMotion3d.set(angularMotion, angularMotion, angularMotion);
    temporalAabbMin.set(temporalAabbMinx, temporalAabbMiny, temporalAabbMinz);
    temporalAabbMax.set(temporalAabbMaxx, temporalAabbMaxy, temporalAabbMaxz);
    temporalAabbMin.sub(angularMotion3d);
    temporalAabbMax.add(angularMotion3d);
    stack.leave();
}
Also used : Vector3f(javax.vecmath.Vector3f) Stack(com.bulletphysics.util.Stack)

Example 40 with Stack

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

the class CollisionShape method getBoundingSphere.

public float getBoundingSphere(Vector3f center) {
    Stack stack = Stack.enter();
    Vector3f tmp = stack.allocVector3f();
    Transform tr = stack.allocTransform();
    tr.setIdentity();
    Vector3f aabbMin = stack.allocVector3f(), aabbMax = stack.allocVector3f();
    getAabb(tr, aabbMin, aabbMax);
    tmp.sub(aabbMax, aabbMin);
    float radius = tmp.length() * 0.5f;
    tmp.add(aabbMin, aabbMax);
    center.scale(0.5f, tmp);
    stack.leave();
    return radius;
}
Also used : Vector3f(javax.vecmath.Vector3f) Transform(com.bulletphysics.linearmath.Transform) 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