Search in sources :

Example 1 with Vector4f

use of spacegraph.util.math.Vector4f in project narchy by automenta.

the class GImpactCollisionAlgorithm method gimpacttrimeshpart_vs_plane_collision.

protected void gimpacttrimeshpart_vs_plane_collision(Collidable body0, Collidable body1, GImpactMeshShape.GImpactMeshShapePart shape0, StaticPlaneShape shape1, boolean swapped) {
    Transform orgtrans0 = body0.transform;
    Transform orgtrans1 = body1.transform;
    StaticPlaneShape planeshape = shape1;
    Vector4f plane = new Vector4f();
    PlaneShape.get_plane_equation_transformed(planeshape, orgtrans1, plane);
    // test box against plane
    BoxCollision.AABB tribox = new BoxCollision.AABB();
    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();
    v3 vertex = new v3();
    v3 tmp = new v3();
    int vi = shape0.getVertexCount();
    float breakingThresh = manifoldPtr.getContactBreakingThreshold();
    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, breakingThresh);
            } else {
                tmp.set(plane.x, plane.y, plane.z);
                addContactPoint(body0, body1, vertex, tmp, distance, breakingThresh);
            }
        }
    }
    shape0.unlockChildShapes();
}
Also used : Vector4f(spacegraph.util.math.Vector4f) Transform(spacegraph.space3d.phys.math.Transform) spacegraph.util.math.v3(spacegraph.util.math.v3)

Example 2 with Vector4f

use of spacegraph.util.math.Vector4f in project narchy by automenta.

the class PersistentManifold method sortCachedPoints.

// / sort cached points so most isolated points come first
private int sortCachedPoints(ManifoldPoint pt) {
    // calculate 4 possible cases areas, and take biggest area
    // also need to keep 'deepest'
    int maxPenetrationIndex = -1;
    // #define KEEP_DEEPEST_POINT 1
    // #ifdef KEEP_DEEPEST_POINT
    float maxPenetration = pt.distance1;
    for (int i = 0; i < 4; i++) {
        ManifoldPoint pii = pointCache[i];
        float pid = pii.distance1;
        if (pid < maxPenetration) {
            maxPenetrationIndex = i;
            maxPenetration = pid;
        }
    }
    // #endif //KEEP_DEEPEST_POINT
    float res0 = 0f, res1 = 0f, res2 = 0f, res3 = 0f;
    if (maxPenetrationIndex != 0) {
        v3 a0 = new v3(pt.localPointA);
        a0.sub(pointCache[1].localPointA);
        v3 b0 = new v3(pointCache[3].localPointA);
        b0.sub(pointCache[2].localPointA);
        v3 cross = new v3();
        cross.cross(a0, b0);
        res0 = cross.lengthSquared();
    }
    if (maxPenetrationIndex != 1) {
        v3 a1 = new v3(pt.localPointA);
        a1.sub(pointCache[0].localPointA);
        v3 b1 = new v3(pointCache[3].localPointA);
        b1.sub(pointCache[2].localPointA);
        v3 cross = new v3();
        cross.cross(a1, b1);
        res1 = cross.lengthSquared();
    }
    if (maxPenetrationIndex != 2) {
        v3 a2 = new v3(pt.localPointA);
        a2.sub(pointCache[0].localPointA);
        v3 b2 = new v3(pointCache[3].localPointA);
        b2.sub(pointCache[1].localPointA);
        v3 cross = new v3();
        cross.cross(a2, b2);
        res2 = cross.lengthSquared();
    }
    if (maxPenetrationIndex != 3) {
        v3 a3 = new v3(pt.localPointA);
        a3.sub(pointCache[0].localPointA);
        v3 b3 = new v3(pointCache[2].localPointA);
        b3.sub(pointCache[1].localPointA);
        v3 cross = new v3();
        cross.cross(a3, b3);
        res3 = cross.lengthSquared();
    }
    Vector4f maxvec = new Vector4f();
    maxvec.set(res0, res1, res2, res3);
    int biggestarea = VectorUtil.closestAxis4(maxvec);
    return biggestarea;
}
Also used : Vector4f(spacegraph.util.math.Vector4f) spacegraph.util.math.v3(spacegraph.util.math.v3)

Example 3 with Vector4f

use of spacegraph.util.math.Vector4f in project narchy by automenta.

the class SimpleBoxShape method getPlane.

@Override
public void getPlane(v3 planeNormal, v3 planeSupport, int i) {
    // this plane might not be aligned...
    Vector4f plane = new Vector4f();
    v3 tmp = new v3(implicitShapeDimensions);
    getPlaneEquation(plane, i, tmp);
    planeNormal.set(plane.x, plane.y, plane.z);
    tmp.negate(planeNormal);
    localGetSupportingVertex(tmp, planeSupport);
}
Also used : Vector4f(spacegraph.util.math.Vector4f) spacegraph.util.math.v3(spacegraph.util.math.v3)

Example 4 with Vector4f

use of spacegraph.util.math.Vector4f in project narchy by automenta.

the class GeometryUtil method getPlaneEquationsFromVertices.

public static void getPlaneEquationsFromVertices(OArrayList<v3> vertices, OArrayList<Vector4f> planeEquationsOut) {
    Vector4f planeEquation = new Vector4f();
    v3 edge0 = new v3(), edge1 = new v3();
    v3 tmp = new v3();
    int numvertices = vertices.size();
    // brute force:
    for (int i = 0; i < numvertices; i++) {
        // return array[index];
        v3 N1 = vertices.get(i);
        for (int j = i + 1; j < numvertices; j++) {
            // return array[index];
            v3 N2 = vertices.get(j);
            for (int k = j + 1; k < numvertices; k++) {
                // return array[index];
                v3 N3 = vertices.get(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;
                }
            }
        }
    }
}
Also used : Vector4f(spacegraph.util.math.Vector4f) spacegraph.util.math.v3(spacegraph.util.math.v3)

Example 5 with Vector4f

use of spacegraph.util.math.Vector4f in project narchy by automenta.

the class BoxShape method getPlane.

@Override
public void getPlane(v3 planeNormal, v3 planeSupport, int i) {
    // this plane might not be aligned...
    Vector4f plane = new Vector4f();
    v3 tmp = new v3();
    getPlaneEquation(plane, i, tmp);
    planeNormal.set(plane.x, plane.y, plane.z);
    tmp.negate(planeNormal);
    localGetSupportingVertex(tmp, planeSupport);
}
Also used : Vector4f(spacegraph.util.math.Vector4f) spacegraph.util.math.v3(spacegraph.util.math.v3)

Aggregations

Vector4f (spacegraph.util.math.Vector4f)10 spacegraph.util.math.v3 (spacegraph.util.math.v3)7 Transform (spacegraph.space3d.phys.math.Transform)1