Search in sources :

Example 6 with Vector4f

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

the class VectorUtil method closestAxis4.

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

Example 7 with Vector4f

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

the class TriangleShapeEx method overlap_test_conservative.

public boolean overlap_test_conservative(TriangleShapeEx other) {
    float total_margin = getMargin() + other.getMargin();
    Vector4f plane0 = new Vector4f();
    buildTriPlane(plane0);
    Vector4f plane1 = new Vector4f();
    other.buildTriPlane(plane1);
    // classify points on other triangle
    float dis0 = ClipPolygon.distance_point_plane(plane0, other.vertices1[0]) - total_margin;
    float dis1 = ClipPolygon.distance_point_plane(plane0, other.vertices1[1]) - total_margin;
    float dis2 = ClipPolygon.distance_point_plane(plane0, other.vertices1[2]) - total_margin;
    if (dis0 > 0.0f && dis1 > 0.0f && dis2 > 0.0f) {
        // classify points on this triangle
        return false;
    }
    dis0 = ClipPolygon.distance_point_plane(plane1, vertices1[0]) - total_margin;
    dis1 = ClipPolygon.distance_point_plane(plane1, vertices1[1]) - total_margin;
    dis2 = ClipPolygon.distance_point_plane(plane1, vertices1[2]) - total_margin;
    return !(dis0 > 0.0f && dis1 > 0.0f && dis2 > 0.0f);
}
Also used : Vector4f(spacegraph.util.math.Vector4f)

Example 8 with Vector4f

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

the class GeometryUtil method isPointInsidePlanes.

public static boolean isPointInsidePlanes(OArrayList<Vector4f> planeEquations, v3 point, float margin) {
    int numbrushes = planeEquations.size();
    for (int i = 0; i < numbrushes; i++) {
        // return array[index];
        Vector4f N1 = planeEquations.get(i);
        float dist = VectorUtil.dot3(N1, point) + N1.w - margin;
        if (dist > 0f) {
            return false;
        }
    }
    return true;
}
Also used : Vector4f(spacegraph.util.math.Vector4f)

Example 9 with Vector4f

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

the class GeometryOperations method segment_collision.

/**
 * Find closest points on segments.
 */
public static void segment_collision(v3 vA1, v3 vA2, v3 vB1, v3 vB2, v3 vPointA, v3 vPointB) {
    v3 AD = new v3();
    AD.sub(vA2, vA1);
    v3 BD = new v3();
    BD.sub(vB2, vB1);
    v3 N = new v3();
    N.cross(AD, BD);
    float[] tp = { N.lengthSquared() };
    // plane
    Vector4f _M = new Vector4f();
    if (// ARE PARALELE
    tp[0] < BulletGlobals.SIMD_EPSILON) {
        // project B over A
        boolean invert_b_order = false;
        _M.x = vB1.dot(AD);
        _M.y = vB2.dot(AD);
        if (_M.x > _M.y) {
            invert_b_order = true;
            // BT_SWAP_NUMBERS(_M[0],_M[1]);
            _M.x = _M.x + _M.y;
            _M.y = _M.x - _M.y;
            _M.x = _M.x - _M.y;
        }
        _M.z = vA1.dot(AD);
        _M.w = vA2.dot(AD);
        // mid points
        N.x = (_M.x + _M.y) * 0.5f;
        N.y = (_M.z + _M.w) * 0.5f;
        if (N.x < N.y) {
            if (_M.y < _M.z) {
                vPointB = invert_b_order ? vB1 : vB2;
                vPointA = vA1;
            } else if (_M.y < _M.w) {
                vPointB = invert_b_order ? vB1 : vB2;
                closest_point_on_segment(vPointA, vPointB, vA1, vA2);
            } else {
                vPointA = vA2;
                closest_point_on_segment(vPointB, vPointA, vB1, vB2);
            }
        } else {
            if (_M.w < _M.x) {
                vPointB = invert_b_order ? vB2 : vB1;
                vPointA = vA2;
            } else if (_M.w < _M.y) {
                vPointA = vA2;
                closest_point_on_segment(vPointB, vPointA, vB1, vB2);
            } else {
                vPointB = invert_b_order ? vB1 : vB2;
                closest_point_on_segment(vPointA, vPointB, vA1, vA2);
            }
        }
        return;
    }
    N.cross(N, BD);
    _M.set(N.x, N.y, N.z, vB1.dot(N));
    // get point A as the plane collision point
    line_plane_collision(_M, AD, vA1, vPointA, tp, 0f, 1f);
    /*Closest point on segment*/
    vPointB.sub(vPointA, vB1);
    tp[0] = vPointB.dot(BD);
    tp[0] /= BD.dot(BD);
    tp[0] = CLAMP(tp[0], 0.0f, 1.0f);
    vPointB.scaleAdd(tp[0], BD, vB1);
}
Also used : Vector4f(spacegraph.util.math.Vector4f) spacegraph.util.math.v3(spacegraph.util.math.v3)

Example 10 with Vector4f

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

the class PrimitiveTriangle method clip_triangle.

/**
 * Clips the triangle against this.
 *
 * @param clipped_points must have MAX_TRI_CLIPPING size, and this triangle must have its plane calculated.
 * @return the number of clipped points
 */
public int clip_triangle(PrimitiveTriangle other, OArrayList<v3> clipped_points) {
    // edge 0
    OArrayList<v3> temp_points = tmpVecList1;
    Vector4f edgeplane = new Vector4f();
    get_edge_plane(0, edgeplane);
    int clipped_count = ClipPolygon.plane_clip_triangle(edgeplane, other.vertices[0], other.vertices[1], other.vertices[2], temp_points);
    if (clipped_count == 0) {
        return 0;
    }
    OArrayList<v3> temp_points1 = tmpVecList2;
    // edge 1
    get_edge_plane(1, edgeplane);
    clipped_count = ClipPolygon.plane_clip_polygon(edgeplane, temp_points, clipped_count, temp_points1);
    if (clipped_count == 0) {
        // edge 2
        return 0;
    }
    get_edge_plane(2, edgeplane);
    clipped_count = ClipPolygon.plane_clip_polygon(edgeplane, temp_points1, clipped_count, clipped_points);
    return clipped_count;
}
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