Search in sources :

Example 46 with Vector3f

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

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

the class ConvexHullShape method addPoint.

public void addPoint(Vector3f point) {
    points.add(new Vector3f(point));
    recalcLocalAabb();
}
Also used : Vector3f(javax.vecmath.Vector3f)

Example 48 with Vector3f

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

the class ConvexHullShape method localGetSupportingVertex.

@Override
public Vector3f localGetSupportingVertex(Vector3f vec, Vector3f out) {
    Vector3f supVertex = localGetSupportingVertexWithoutMargin(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 out;
}
Also used : Vector3f(javax.vecmath.Vector3f) Stack(com.bulletphysics.util.Stack)

Example 49 with Vector3f

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

the class ConvexHullShape method localGetSupportingVertexWithoutMargin.

@Override
public Vector3f localGetSupportingVertexWithoutMargin(Vector3f vec0, Vector3f out) {
    Vector3f supVec = out;
    supVec.set(0f, 0f, 0f);
    float newDot, maxDot = -1e30f;
    Stack stack = Stack.enter();
    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();
    for (int i = 0; i < points.size(); i++) {
        VectorUtil.mul(vtx, points.getQuick(i), localScaling);
        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 50 with Vector3f

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

the class ConvexInternalShape method getAabbSlow.

@Override
public void getAabbSlow(Transform trans, Vector3f minAabb, Vector3f maxAabb) {
    Stack stack = Stack.enter();
    float margin = getMargin();
    Vector3f vec = stack.allocVector3f();
    Vector3f tmp1 = stack.allocVector3f();
    Vector3f tmp2 = stack.allocVector3f();
    for (int i = 0; i < 3; i++) {
        vec.set(0f, 0f, 0f);
        VectorUtil.setCoord(vec, i, 1f);
        MatrixUtil.transposeTransform(tmp1, vec, trans.basis);
        localGetSupportingVertex(tmp1, tmp2);
        trans.transform(tmp2);
        VectorUtil.setCoord(maxAabb, i, VectorUtil.getCoord(tmp2, i) + margin);
        VectorUtil.setCoord(vec, i, -1f);
        MatrixUtil.transposeTransform(tmp1, vec, trans.basis);
        localGetSupportingVertex(tmp1, tmp2);
        trans.transform(tmp2);
        VectorUtil.setCoord(minAabb, i, VectorUtil.getCoord(tmp2, i) - margin);
    }
    stack.leave();
}
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