Search in sources :

Example 6 with Vector4f

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

the class GImpactCollisionAlgorithm method gimpacttrimeshpart_vs_plane_collision.

protected void gimpacttrimeshpart_vs_plane_collision(CollisionObject body0, CollisionObject body1, GImpactMeshShapePart shape0, StaticPlaneShape shape1, boolean swapped) {
    Stack stack = Stack.enter();
    Transform orgtrans0 = body0.getWorldTransform(stack.allocTransform());
    Transform orgtrans1 = body1.getWorldTransform(stack.allocTransform());
    StaticPlaneShape planeshape = shape1;
    Vector4f plane = stack.allocVector4f();
    PlaneShape.get_plane_equation_transformed(planeshape, orgtrans1, plane);
    // test box against plane
    AABB tribox = stack.allocAABB();
    shape0.getAabb(orgtrans0, tribox.min, tribox.max);
    tribox.increment_margin(planeshape.getMargin());
    if (tribox.plane_classify(plane) != PlaneIntersectionType.COLLIDE_PLANE) {
        return;
    }
    shape0.lockChildShapes();
    float margin = shape0.getMargin() + planeshape.getMargin();
    Vector3f vertex = stack.allocVector3f();
    Vector3f tmp = stack.allocVector3f();
    int vi = shape0.getVertexCount();
    while ((vi--) != 0) {
        shape0.getVertex(vi, vertex);
        orgtrans0.transform(vertex);
        float distance = VectorUtil.dot3(vertex, plane) - plane.w - margin;
        if (//add contact
        distance < 0f) {
            if (swapped) {
                tmp.set(-plane.x, -plane.y, -plane.z);
                addContactPoint(body1, body0, vertex, tmp, distance);
            } else {
                tmp.set(plane.x, plane.y, plane.z);
                addContactPoint(body0, body1, vertex, tmp, distance);
            }
        }
    }
    shape0.unlockChildShapes();
    stack.leave();
}
Also used : Vector4f(javax.vecmath.Vector4f) Vector3f(javax.vecmath.Vector3f) StaticPlaneShape(com.bulletphysics.collision.shapes.StaticPlaneShape) Transform(com.bulletphysics.linearmath.Transform) AABB(com.bulletphysics.extras.gimpact.BoxCollision.AABB) Stack(com.bulletphysics.util.Stack)

Example 7 with Vector4f

use of javax.vecmath.Vector4f 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 8 with Vector4f

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

the class GeometryUtil method isPointInsidePlanes.

public static boolean isPointInsidePlanes(ObjectArrayList<Vector4f> planeEquations, Vector3f point, float margin) {
    int numbrushes = planeEquations.size();
    for (int i = 0; i < numbrushes; i++) {
        Vector4f N1 = planeEquations.getQuick(i);
        float dist = VectorUtil.dot3(N1, point) + N1.w - margin;
        if (dist > 0f) {
            return false;
        }
    }
    return true;
}
Also used : Vector4f(javax.vecmath.Vector4f)

Example 9 with Vector4f

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

Example 10 with Vector4f

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

the class VectorUtil method closestAxis4.

public static int closestAxis4(Vector4f vec) {
    Vector4f tmp = new Vector4f(vec);
    tmp.absolute();
    return maxAxis4(tmp);
}
Also used : Vector4f(javax.vecmath.Vector4f)

Aggregations

Vector4f (javax.vecmath.Vector4f)19 Stack (com.bulletphysics.util.Stack)8 Vector3f (javax.vecmath.Vector3f)8 Matrix4f (javax.vecmath.Matrix4f)2 TRSRTransformation (net.minecraftforge.common.model.TRSRTransformation)2 IMixinTextureAtlasSprite (com.almuradev.content.mixin.iface.IMixinTextureAtlasSprite)1 Face (com.almuradev.content.model.obj.geometry.Face)1 Group (com.almuradev.content.model.obj.geometry.Group)1 Vertex (com.almuradev.content.model.obj.geometry.Vertex)1 VertexDefinition (com.almuradev.content.model.obj.geometry.VertexDefinition)1 VertexNormal (com.almuradev.content.model.obj.geometry.VertexNormal)1 VertexTextureCoordinate (com.almuradev.content.model.obj.geometry.VertexTextureCoordinate)1 MaterialDefinition (com.almuradev.content.model.obj.material.MaterialDefinition)1 StaticPlaneShape (com.bulletphysics.collision.shapes.StaticPlaneShape)1 AABB (com.bulletphysics.extras.gimpact.BoxCollision.AABB)1 Transform (com.bulletphysics.linearmath.Transform)1 Matrix3f (javax.vecmath.Matrix3f)1 BlockFaceUV (net.minecraft.client.renderer.block.model.BlockFaceUV)1 TextureAtlasSprite (net.minecraft.client.renderer.texture.TextureAtlasSprite)1 ResourceLocation (net.minecraft.util.ResourceLocation)1