Search in sources :

Example 11 with Vector4f

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

the class BoxShape method getPlane.

@Override
public void getPlane(Vector3f planeNormal, Vector3f planeSupport, int i) {
    // this plane might not be aligned...
    Stack stack = Stack.enter();
    Vector4f plane = stack.allocVector4f();
    getPlaneEquation(plane, i);
    planeNormal.set(plane.x, plane.y, plane.z);
    Vector3f tmp = stack.allocVector3f();
    tmp.negate(planeNormal);
    localGetSupportingVertex(tmp, planeSupport);
    stack.leave();
}
Also used : Vector4f(javax.vecmath.Vector4f) Vector3f(javax.vecmath.Vector3f) Stack(com.bulletphysics.util.Stack)

Example 12 with Vector4f

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

the class GeometryOperations method segment_collision.

/**
	 * Find closest points on segments.
	 */
public static void segment_collision(Vector3f vA1, Vector3f vA2, Vector3f vB1, Vector3f vB2, Vector3f vPointA, Vector3f vPointB) {
    Stack stack = Stack.enter();
    Vector3f AD = stack.allocVector3f();
    AD.sub(vA2, vA1);
    Vector3f BD = stack.allocVector3f();
    BD.sub(vB2, vB1);
    Vector3f N = stack.allocVector3f();
    N.cross(AD, BD);
    float[] tp = new float[] { N.lengthSquared() };
    //plane
    Vector4f _M = stack.allocVector4f();
    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);
            }
        }
        stack.leave();
        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);
    stack.leave();
}
Also used : Vector4f(javax.vecmath.Vector4f) Vector3f(javax.vecmath.Vector3f) Stack(com.bulletphysics.util.Stack)

Example 13 with Vector4f

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

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, ObjectArrayList<Vector3f> clipped_points) {
    // edge 0
    Stack stack = Stack.enter();
    ObjectArrayList<Vector3f> temp_points = tmpVecList1;
    Vector4f edgeplane = stack.allocVector4f();
    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;
    }
    ObjectArrayList<Vector3f> 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);
    stack.leave();
    return clipped_count;
}
Also used : Vector4f(javax.vecmath.Vector4f) Vector3f(javax.vecmath.Vector3f) Stack(com.bulletphysics.util.Stack)

Example 14 with Vector4f

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

the class TriangleShapeEx method overlap_test_conservative.

public boolean overlap_test_conservative(TriangleShapeEx other) {
    float total_margin = getMargin() + other.getMargin();
    Stack stack = Stack.enter();
    Vector4f plane0 = stack.allocVector4f();
    buildTriPlane(plane0);
    Vector4f plane1 = stack.allocVector4f();
    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) {
        stack.leave();
        // 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;
    stack.leave();
    if (dis0 > 0.0f && dis1 > 0.0f && dis2 > 0.0f) {
        return false;
    }
    return true;
}
Also used : Vector4f(javax.vecmath.Vector4f) Stack(com.bulletphysics.util.Stack)

Example 15 with Vector4f

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

the class Stack method allocVector4f.

public Vector4f allocVector4f() {
    types[sp++] = TYPE_VECTOR4F;
    int pos = stackPositions[TYPE_VECTOR4F]++;
    if (vector4fStack.size() <= pos) {
        vector4fStack.add(new Vector4f());
    }
    return vector4fStack.get(pos);
}
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