Search in sources :

Example 41 with Vector3f

use of javax.vecmath.Vector3f 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 42 with Vector3f

use of javax.vecmath.Vector3f 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 43 with Vector3f

use of javax.vecmath.Vector3f 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)

Example 44 with Vector3f

use of javax.vecmath.Vector3f in project bdx by GoranM.

the class CompoundShape method addChildShape.

public void addChildShape(Transform localTransform, CollisionShape shape) {
    //m_childTransforms.push_back(localTransform);
    //m_childShapes.push_back(shape);
    CompoundShapeChild child = new CompoundShapeChild();
    child.transform.set(localTransform);
    child.childShape = shape;
    child.childShapeType = shape.getShapeType();
    child.childMargin = shape.getMargin();
    children.add(child);
    Stack stack = Stack.enter();
    // extend the local aabbMin/aabbMax
    Vector3f _localAabbMin = stack.allocVector3f(), _localAabbMax = stack.allocVector3f();
    shape.getAabb(localTransform, _localAabbMin, _localAabbMax);
    // JAVA NOTE: rewritten
    //		for (int i=0;i<3;i++)
    //		{
    //			if (this.localAabbMin[i] > _localAabbMin[i])
    //			{
    //				this.localAabbMin[i] = _localAabbMin[i];
    //			}
    //			if (this.localAabbMax[i] < _localAabbMax[i])
    //			{
    //				this.localAabbMax[i] = _localAabbMax[i];
    //			}
    //		}
    VectorUtil.setMin(this.localAabbMin, _localAabbMin);
    VectorUtil.setMax(this.localAabbMax, _localAabbMax);
    stack.leave();
}
Also used : Vector3f(javax.vecmath.Vector3f) Stack(com.bulletphysics.util.Stack)

Example 45 with Vector3f

use of javax.vecmath.Vector3f in project bdx by GoranM.

the class ConeShape method localGetSupportingVertex.

@Override
public Vector3f localGetSupportingVertex(Vector3f vec, Vector3f out) {
    Vector3f supVertex = coneLocalSupport(vec, out);
    if (getMargin() != 0f) {
        Stack stack = Stack.enter();
        Vector3f vecnorm = stack.alloc(vec);
        if (vecnorm.lengthSquared() < (BulletGlobals.FLT_EPSILON * BulletGlobals.FLT_EPSILON)) {
            vecnorm.set(-1f, -1f, -1f);
        }
        vecnorm.normalize();
        supVertex.scaleAdd(getMargin(), vecnorm, supVertex);
        stack.leave();
    }
    return supVertex;
}
Also used : Vector3f(javax.vecmath.Vector3f) Stack(com.bulletphysics.util.Stack)

Aggregations

Vector3f (javax.vecmath.Vector3f)266 Stack (com.bulletphysics.util.Stack)197 Transform (com.bulletphysics.linearmath.Transform)53 Matrix3f (javax.vecmath.Matrix3f)25 ManifoldPoint (com.bulletphysics.collision.narrowphase.ManifoldPoint)14 StaticAlloc (com.bulletphysics.util.StaticAlloc)12 Matrix4f (javax.vecmath.Matrix4f)10 Vector4f (javax.vecmath.Vector4f)8 CollisionShape (com.bulletphysics.collision.shapes.CollisionShape)7 TypedConstraint (com.bulletphysics.dynamics.constraintsolver.TypedConstraint)7 CollisionObject (com.bulletphysics.collision.dispatch.CollisionObject)6 ObjectArrayList (com.bulletphysics.util.ObjectArrayList)5 Quat4f (javax.vecmath.Quat4f)5 ConvexShape (com.bulletphysics.collision.shapes.ConvexShape)4 SphereShape (com.bulletphysics.collision.shapes.SphereShape)4 RigidBody (com.bulletphysics.dynamics.RigidBody)4 HashMap (java.util.HashMap)4 VoronoiSimplexSolver (com.bulletphysics.collision.narrowphase.VoronoiSimplexSolver)3 CompoundShape (com.bulletphysics.collision.shapes.CompoundShape)3 ConcaveShape (com.bulletphysics.collision.shapes.ConcaveShape)3