Search in sources :

Example 96 with Vector3f

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

the class Quantization method bt_quantize_clamp.

public static void bt_quantize_clamp(short[] out, Vector3f point, Vector3f min_bound, Vector3f max_bound, Vector3f bvhQuantization) {
    Stack stack = Stack.enter();
    Vector3f clampedPoint = stack.alloc(point);
    VectorUtil.setMax(clampedPoint, min_bound);
    VectorUtil.setMin(clampedPoint, max_bound);
    Vector3f v = stack.allocVector3f();
    v.sub(clampedPoint, min_bound);
    VectorUtil.mul(v, v, bvhQuantization);
    out[0] = (short) (v.x + 0.5f);
    out[1] = (short) (v.y + 0.5f);
    out[2] = (short) (v.z + 0.5f);
    stack.leave();
}
Also used : Vector3f(javax.vecmath.Vector3f) Stack(com.bulletphysics.util.Stack)

Example 97 with Vector3f

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

the class Quantization method bt_calc_quantization_parameters.

public static void bt_calc_quantization_parameters(Vector3f outMinBound, Vector3f outMaxBound, Vector3f bvhQuantization, Vector3f srcMinBound, Vector3f srcMaxBound, 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);
    outMinBound.sub(srcMinBound, clampValue);
    outMaxBound.add(srcMaxBound, clampValue);
    Vector3f aabbSize = stack.allocVector3f();
    aabbSize.sub(outMaxBound, outMinBound);
    bvhQuantization.set(65535.0f, 65535.0f, 65535.0f);
    VectorUtil.div(bvhQuantization, bvhQuantization, aabbSize);
    stack.leave();
}
Also used : Vector3f(javax.vecmath.Vector3f) Stack(com.bulletphysics.util.Stack)

Example 98 with Vector3f

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

the class TriangleShapeEx method buildTriPlane.

public void buildTriPlane(Vector4f plane) {
    Stack stack = Stack.enter();
    Vector3f tmp1 = stack.allocVector3f();
    Vector3f tmp2 = stack.allocVector3f();
    Vector3f normal = stack.allocVector3f();
    tmp1.sub(vertices1[1], vertices1[0]);
    tmp2.sub(vertices1[2], vertices1[0]);
    normal.cross(tmp1, tmp2);
    normal.normalize();
    plane.set(normal.x, normal.y, normal.z, vertices1[0].dot(normal));
    stack.leave();
}
Also used : Vector3f(javax.vecmath.Vector3f) Stack(com.bulletphysics.util.Stack)

Example 99 with Vector3f

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

the class GeometryUtil method getPlaneEquationsFromVertices.

public static void getPlaneEquationsFromVertices(ObjectArrayList<Vector3f> vertices, ObjectArrayList<Vector4f> planeEquationsOut) {
    Stack stack = Stack.enter();
    Vector4f planeEquation = stack.allocVector4f();
    Vector3f edge0 = stack.allocVector3f(), edge1 = stack.allocVector3f();
    Vector3f tmp = stack.allocVector3f();
    int numvertices = vertices.size();
    // brute force:
    for (int i = 0; i < numvertices; i++) {
        Vector3f N1 = vertices.getQuick(i);
        for (int j = i + 1; j < numvertices; j++) {
            Vector3f N2 = vertices.getQuick(j);
            for (int k = j + 1; k < numvertices; k++) {
                Vector3f N3 = vertices.getQuick(k);
                edge0.sub(N2, N1);
                edge1.sub(N3, N1);
                float normalSign = 1f;
                for (int ww = 0; ww < 2; ww++) {
                    tmp.cross(edge0, edge1);
                    planeEquation.x = normalSign * tmp.x;
                    planeEquation.y = normalSign * tmp.y;
                    planeEquation.z = normalSign * tmp.z;
                    if (VectorUtil.lengthSquared3(planeEquation) > 0.0001f) {
                        VectorUtil.normalize3(planeEquation);
                        if (notExist(planeEquation, planeEquationsOut)) {
                            planeEquation.w = -VectorUtil.dot3(planeEquation, N1);
                            // check if inside, and replace supportingVertexOut if needed
                            if (areVerticesBehindPlane(planeEquation, vertices, 0.01f)) {
                                planeEquationsOut.add(new Vector4f(planeEquation));
                            }
                        }
                    }
                    normalSign = -1f;
                }
            }
        }
    }
    stack.leave();
}
Also used : Vector4f(javax.vecmath.Vector4f) Vector3f(javax.vecmath.Vector3f) Stack(com.bulletphysics.util.Stack)

Example 100 with Vector3f

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

the class GeometryUtil method getVerticesFromPlaneEquations.

public static void getVerticesFromPlaneEquations(ObjectArrayList<Vector4f> planeEquations, ObjectArrayList<Vector3f> verticesOut) {
    Stack stack = Stack.enter();
    Vector3f n2n3 = stack.allocVector3f();
    Vector3f n3n1 = stack.allocVector3f();
    Vector3f n1n2 = stack.allocVector3f();
    Vector3f potentialVertex = stack.allocVector3f();
    int numbrushes = planeEquations.size();
    // brute force:
    for (int i = 0; i < numbrushes; i++) {
        Vector4f N1 = planeEquations.getQuick(i);
        for (int j = i + 1; j < numbrushes; j++) {
            Vector4f N2 = planeEquations.getQuick(j);
            for (int k = j + 1; k < numbrushes; k++) {
                Vector4f N3 = planeEquations.getQuick(k);
                VectorUtil.cross3(n2n3, N2, N3);
                VectorUtil.cross3(n3n1, N3, N1);
                VectorUtil.cross3(n1n2, N1, N2);
                if ((n2n3.lengthSquared() > 0.0001f) && (n3n1.lengthSquared() > 0.0001f) && (n1n2.lengthSquared() > 0.0001f)) {
                    // point P out of 3 plane equations:
                    // 	     d1 ( N2 * N3 ) + d2 ( N3 * N1 ) + d3 ( N1 * N2 )  
                    // P =  -------------------------------------------------------------------------  
                    //    N1 . ( N2 * N3 )  
                    float quotient = VectorUtil.dot3(N1, n2n3);
                    if (Math.abs(quotient) > 0.000001f) {
                        quotient = -1f / quotient;
                        n2n3.scale(N1.w);
                        n3n1.scale(N2.w);
                        n1n2.scale(N3.w);
                        potentialVertex.set(n2n3);
                        potentialVertex.add(n3n1);
                        potentialVertex.add(n1n2);
                        potentialVertex.scale(quotient);
                        // check if inside, and replace supportingVertexOut if needed
                        if (isPointInsidePlanes(planeEquations, potentialVertex, 0.01f)) {
                            verticesOut.add(new Vector3f(potentialVertex));
                        }
                    }
                }
            }
        }
    }
    stack.leave();
}
Also used : Vector4f(javax.vecmath.Vector4f) Vector3f(javax.vecmath.Vector3f) Stack(com.bulletphysics.util.Stack)

Aggregations

Vector3f (javax.vecmath.Vector3f)265 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)9 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 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 Quat4f (javax.vecmath.Quat4f)4 VoronoiSimplexSolver (com.bulletphysics.collision.narrowphase.VoronoiSimplexSolver)3 CompoundShape (com.bulletphysics.collision.shapes.CompoundShape)3 ConcaveShape (com.bulletphysics.collision.shapes.ConcaveShape)3