Search in sources :

Example 56 with Vector3f

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

the class OptimizedBvh method setQuantizationValues.

public void setQuantizationValues(Vector3f aabbMin, Vector3f aabbMax, float quantizationMargin) {
    // enlarge the AABB to avoid division by zero when initializing the quantization values
    Stack stack = Stack.enter();
    Vector3f clampValue = stack.allocVector3f();
    clampValue.set(quantizationMargin, quantizationMargin, quantizationMargin);
    bvhAabbMin.sub(aabbMin, clampValue);
    bvhAabbMax.add(aabbMax, clampValue);
    Vector3f aabbSize = stack.allocVector3f();
    aabbSize.sub(bvhAabbMax, bvhAabbMin);
    bvhQuantization.set(65535f, 65535f, 65535f);
    VectorUtil.div(bvhQuantization, bvhQuantization, aabbSize);
    stack.leave();
}
Also used : Vector3f(javax.vecmath.Vector3f) Stack(com.bulletphysics.util.Stack)

Example 57 with Vector3f

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

the class OptimizedBvh method getAabbMax.

public Vector3f getAabbMax(int nodeIndex) {
    if (useQuantization) {
        Vector3f tmp = new Vector3f();
        unQuantize(tmp, quantizedLeafNodes.getQuantizedAabbMax(nodeIndex));
        return tmp;
    }
    // non-quantized
    return leafNodes.getQuick(nodeIndex).aabbMaxOrg;
}
Also used : Vector3f(javax.vecmath.Vector3f)

Example 58 with Vector3f

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

the class OptimizedBvh method refit.

public void refit(StridingMeshInterface meshInterface) {
    if (useQuantization) {
        // calculate new aabb
        Stack stack = Stack.enter();
        Vector3f aabbMin = stack.allocVector3f(), aabbMax = stack.allocVector3f();
        meshInterface.calculateAabbBruteForce(aabbMin, aabbMax);
        setQuantizationValues(aabbMin, aabbMax);
        updateBvhNodes(meshInterface, 0, curNodeIndex, 0);
        // now update all subtree headers
        int i;
        for (i = 0; i < SubtreeHeaders.size(); i++) {
            BvhSubtreeInfo subtree = SubtreeHeaders.getQuick(i);
            subtree.setAabbFromQuantizeNode(quantizedContiguousNodes, subtree.rootNodeIndex);
        }
        stack.leave();
    } else {
        // JAVA NOTE: added for testing, it's too slow for practical use
        build(meshInterface, false, null, null);
    }
}
Also used : Vector3f(javax.vecmath.Vector3f) Stack(com.bulletphysics.util.Stack)

Example 59 with Vector3f

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

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

the class PolyhedralConvexShape method localGetSupportingVertexWithoutMargin.

//	/** optional Hull is for optional Separating Axis Test Hull collision detection, see Hull.cpp */
//	public Hull optionalHull = null;
@Override
public Vector3f localGetSupportingVertexWithoutMargin(Vector3f vec0, Vector3f out) {
    int i;
    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;
    for (i = 0; i < getNumVertices(); i++) {
        getVertex(i, vtx);
        newDot = vec.dot(vtx);
        if (newDot > maxDot) {
            maxDot = newDot;
            supVec = vtx;
        }
    }
    stack.leave();
    return out;
}
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