Java Code Examples for org.lwjgl.util.vector.Vector4f#setX()

The following examples show how to use org.lwjgl.util.vector.Vector4f#setX() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VM08SlicerPro.java    From ldparteditor with MIT License 6 votes vote down vote up
private GData3 checkNormal(GData3 g3, Matrix4f vport) {
    Vertex[] v = triangles.get(g3);

    Vector4f n = new Vector4f();
    n.setW(1f);
    n.setX((v[2].y - v[0].y) * (v[1].z - v[0].z) - (v[2].z - v[0].z) * (v[1].y - v[0].y));
    n.setY((v[2].z - v[0].z) * (v[1].x - v[0].x) - (v[2].x - v[0].x) * (v[1].z - v[0].z));
    n.setZ((v[2].x - v[0].x) * (v[1].y - v[0].y) - (v[2].y - v[0].y) * (v[1].x - v[0].x));
    Matrix4f.transform(vport, n, n);
    Vector4f.sub(n, new Vector4f(vport.m03, vport.m13, vport.m23, 0f), n);
    if (n.z > 0f ^ Editor3DWindow.getWindow().hasBfcToggle()) {
        return new GData3(g3.colourNumber, g3.r, g3.g, g3.b, g3.a, v[0], v[2], v[1], View.DUMMY_REFERENCE, linkedDatFile, g3.isTriangle);
    } else {
        return null;
    }

}
 
Example 2
Source File: VM23FlatSubfileTester.java    From ldparteditor with MIT License 4 votes vote down vote up
public Axis isFlatOnAxis(GData1 ref) {

        if (ref == null) return Axis.NONE;

        Matrix4f tMatrix = (Matrix4f) ref.accurateLocalMatrix.getMatrix4f().invert();

        boolean plainOnX = true;
        boolean plainOnY = true;
        boolean plainOnZ = true;

        Set<VertexInfo> verts = lineLinkedToVertices.get(ref);
        if (verts == null) return Axis.NONE;
        for (VertexInfo vi : verts) {
            Vector4f vert = vi.vertex.toVector4f();
            vert.setX(vert.x / 1000f);
            vert.setY(vert.y / 1000f);
            vert.setZ(vert.z / 1000f);
            Vector4f vert2 = Matrix4f.transform(tMatrix, vert, null);

            if (plainOnX && Math.abs(vert2.x) > 0.001f) {
                plainOnX = false;
            }
            if (plainOnY && Math.abs(vert2.y) > 0.001f) {
                plainOnY = false;
            }
            if (plainOnZ && Math.abs(vert2.z) > 0.001f) {
                plainOnZ = false;
            }
            if (!plainOnX && !plainOnY && !plainOnZ) {
                return Axis.NONE;
            }
        }

        if (plainOnX) {
            return Axis.X;
        } else if (plainOnY) {
            return Axis.Y;
        } else if (plainOnZ) {
            return Axis.Z;
        } else {
            return Axis.NONE;
        }
    }
 
Example 3
Source File: VM23FlatSubfileTester.java    From ldparteditor with MIT License 4 votes vote down vote up
public ArrayList<ParsingResult> checkForFlatScaling(GData1 ref) {
    ArrayList<ParsingResult> result = new ArrayList<ParsingResult>();

    Matrix4f tMatrix = (Matrix4f) ref.accurateLocalMatrix.getMatrix4f().invert();

    boolean plainOnX = true;
    boolean plainOnY = true;
    boolean plainOnZ = true;

    Set<VertexInfo> verts = lineLinkedToVertices.get(ref);
    if (verts == null) return result;
    for (VertexInfo vi : verts) {
        Vector4f vert = vi.vertex.toVector4f();
        vert.setX(vert.x / 1000f);
        vert.setY(vert.y / 1000f);
        vert.setZ(vert.z / 1000f);
        Vector4f vert2 = Matrix4f.transform(tMatrix, vert, null);

        if (plainOnX && Math.abs(vert2.x) > 0.001f) {
            plainOnX = false;
        }
        if (plainOnY && Math.abs(vert2.y) > 0.001f) {
            plainOnY = false;
        }
        if (plainOnZ && Math.abs(vert2.z) > 0.001f) {
            plainOnZ = false;
        }
        if (!plainOnX && !plainOnY && !plainOnZ) {
            return result;
        }
    }

    Matrix TMatrix2 = ref.accurateLocalMatrix;
    final BigDecimal lengthX =  plainOnX ? MathHelper.sqrt(TMatrix2.M00.multiply(TMatrix2.M00).add(TMatrix2.M01.multiply(TMatrix2.M01)).add(TMatrix2.M02.multiply(TMatrix2.M02))).subtract(BigDecimal.ONE).abs() : null;
    final BigDecimal lengthY =  plainOnY ? MathHelper.sqrt(TMatrix2.M10.multiply(TMatrix2.M10).add(TMatrix2.M11.multiply(TMatrix2.M11)).add(TMatrix2.M12.multiply(TMatrix2.M12))).subtract(BigDecimal.ONE).abs() : null;
    final BigDecimal lengthZ =  plainOnZ ? MathHelper.sqrt(TMatrix2.M20.multiply(TMatrix2.M20).add(TMatrix2.M21.multiply(TMatrix2.M21)).add(TMatrix2.M22.multiply(TMatrix2.M22))).subtract(BigDecimal.ONE).abs() : null;
    // Epsilon is 0.000001 / DATHeader default value is 0.0005
    final BigDecimal epsilon = new BigDecimal("0.000001"); //$NON-NLS-1$
    if (plainOnX && epsilon.compareTo(lengthX) < 0) {
        result.add(new ParsingResult(I18n.VM_FlatScaledX, "[W02] " + I18n.DATPARSER_Warning, ResultType.WARN)); //$NON-NLS-1$
    }
    if (plainOnY && epsilon.compareTo(lengthY) < 0) {
        result.add(new ParsingResult(I18n.VM_FlatScaledY, "[W03] " + I18n.DATPARSER_Warning, ResultType.WARN)); //$NON-NLS-1$
    }
    if (plainOnZ && epsilon.compareTo(lengthZ) < 0) {
        result.add(new ParsingResult(I18n.VM_FlatScaledZ, "[W04] " + I18n.DATPARSER_Warning, ResultType.WARN)); //$NON-NLS-1$
    }

    return result;
}