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

The following examples show how to use org.lwjgl.util.vector.Vector4f#set() . 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: PowerRay.java    From ldparteditor with MIT License 5 votes vote down vote up
public boolean TRIANGLE_INTERSECT(Vector4f orig, Vector4f dir, Vertex vert0, Vertex vert1, Vertex vert2, Vector4f intersection_point, double[] dist) {
    double[] orig_arr = new double[] { orig.x, orig.y, orig.z };
    double[] dir_arr = new double[] { dir.x, dir.y, dir.z };
    double[] vert0_arr = new double[] { vert0.x, vert0.y, vert0.z };
    double[] vert1_arr = new double[] { vert1.x, vert1.y, vert1.z };
    double[] vert2_arr = new double[] { vert2.x, vert2.y, vert2.z };
    if (TRIANGLE_INTERSECT2(orig_arr, dir_arr, vert0_arr, vert1_arr, vert2_arr)) {
        intersection_point.set((float) (orig_arr[0] + dir_arr[0] * t), (float) (orig_arr[1] + dir_arr[1] * t), (float) (orig_arr[2] + dir_arr[2] * t), 1f);
        dist[0] = t;
        return true;
    }
    return false;
}
 
Example 2
Source File: PowerRay.java    From ldparteditor with MIT License 5 votes vote down vote up
public double[] BARYCENTRIC(double[] point, double[] normal, double[] vert0, double[] vert1, double[] vert2, Vector4f intersection_point) {
    double[] orig = new double[] { 100.0 * normal[0] + point[0], 100.0 * normal[1] + point[1], 100.0 * normal[2] + point[2] };
    double diskr = 0;
    double inv_diskr = 0;
    corner1[0] = vert1[0] - vert0[0];
    corner1[1] = vert1[1] - vert0[1];
    corner1[2] = vert1[2] - vert0[2];
    corner2[0] = vert2[0] - vert0[0];
    corner2[1] = vert2[1] - vert0[1];
    corner2[2] = vert2[2] - vert0[2];
    pvec[0] = normal[1] * corner2[2] - normal[2] * corner2[1];
    pvec[1] = normal[2] * corner2[0] - normal[0] * corner2[2];
    pvec[2] = normal[0] * corner2[1] - normal[1] * corner2[0];
    diskr = corner1[0] * pvec[0] + corner1[1] * pvec[1] + corner1[2] * pvec[2];
    if (diskr > -TOLERANCE && diskr < TOLERANCE)
        return null;
    inv_diskr = 1d / diskr;
    tvec[0] = orig[0] - vert0[0];
    tvec[1] = orig[1] - vert0[1];
    tvec[2] = orig[2] - vert0[2];
    u = (tvec[0] * pvec[0] + tvec[1] * pvec[1] + tvec[2] * pvec[2]) * inv_diskr;
    if (u < 0 || u > 1d)
        return null;
    qvec[0] = tvec[1] * corner1[2] - tvec[2] * corner1[1];
    qvec[1] = tvec[2] * corner1[0] - tvec[0] * corner1[2];
    qvec[2] = tvec[0] * corner1[1] - tvec[1] * corner1[0];
    v = (normal[0] * qvec[0] + normal[1] * qvec[1] + normal[2] * qvec[2]) * inv_diskr;
    if (v < 0 || u + v > 1d)
        return null;
    double w = 1.0 - u - v;
    intersection_point.set((float) (vert0[0] * w + vert1[0] * u + vert2[0] * v), (float) (vert0[1] * w + vert1[1] * u + vert2[1] * v), (float) (vert0[2] * w + vert1[2] * u + vert2[2] * v), 1f);
    return new double[] { u, v, w };
}
 
Example 3
Source File: Particle.java    From tribaltrouble with GNU General Public License v2.0 5 votes vote down vote up
public Particle(float angle) {
	Matrix4f rot_matrix = new Matrix4f();
	Vector3f axis = new Vector3f();
	Vector4f uv_vector = new Vector4f();
	Vector4f transform_uv_vector = new Vector4f();
	
	rot_matrix.setIdentity();
	axis.set(0f, 0f, 1f);
	rot_matrix.rotate(angle, axis);

	uv_vector.set(-.5f, -.5f, 0f, 0f);
	Matrix4f.transform(rot_matrix, uv_vector, transform_uv_vector);
	u1 = transform_uv_vector.getX() + .5f;
	v1 = transform_uv_vector.getY() + .5f;
	
	uv_vector.set(.5f, -.5f, 0f, 0f);
	Matrix4f.transform(rot_matrix, uv_vector, transform_uv_vector);
	u2 = transform_uv_vector.getX() + .5f;
	v2 = transform_uv_vector.getY() + .5f;

	uv_vector.set(.5f, .5f, 0f, 0f);
	Matrix4f.transform(rot_matrix, uv_vector, transform_uv_vector);
	u3 = transform_uv_vector.getX() + .5f;
	v3 = transform_uv_vector.getY() + .5f;

	uv_vector.set(-.5f, .5f, 0f, 0f);
	Matrix4f.transform(rot_matrix, uv_vector, transform_uv_vector);
	u4 = transform_uv_vector.getX() + .5f;
	v4 = transform_uv_vector.getY() + .5f;
}
 
Example 4
Source File: GData1.java    From ldparteditor with MIT License 4 votes vote down vote up
@Override
public void drawGL20(Composite3D c3d) {
    if (!visible)
        return;
    if (matrix != null) {

        final Rectangle bounds = c3d.getClientArea();
        final PerspectiveCalculator PC = c3d.getPerspectiveCalculator();

        Vector4f bbmin = new Vector4f();
        Vector4f bbmax = new Vector4f();

        Vector4f c1 = new Vector4f(boundingBoxMin);
        Vector4f c2 = new Vector4f(boundingBoxMin);
        Vector4f c3 = new Vector4f(boundingBoxMin);
        Vector4f c4 = new Vector4f(boundingBoxMin);
        Vector4f c5 = new Vector4f(boundingBoxMax);
        Vector4f c6 = new Vector4f(boundingBoxMax);
        Vector4f c7 = new Vector4f(boundingBoxMax);
        Vector4f c8 = new Vector4f(boundingBoxMax);

        c2.x = boundingBoxMax.x;
        c3.y = boundingBoxMax.y;
        c4.z = boundingBoxMax.z;

        c6.x = boundingBoxMin.x;
        c7.y = boundingBoxMin.y;
        c8.z = boundingBoxMin.z;

        c1.set(PC.getScreenCoordinatesFrom3D(c1.x, c1.y, c1.z));
        c2.set(PC.getScreenCoordinatesFrom3D(c2.x, c2.y, c2.z));
        c3.set(PC.getScreenCoordinatesFrom3D(c3.x, c3.y, c3.z));
        c4.set(PC.getScreenCoordinatesFrom3D(c4.x, c4.y, c4.z));
        c5.set(PC.getScreenCoordinatesFrom3D(c5.x, c5.y, c5.z));
        c6.set(PC.getScreenCoordinatesFrom3D(c6.x, c6.y, c6.z));
        c7.set(PC.getScreenCoordinatesFrom3D(c7.x, c7.y, c7.z));
        c8.set(PC.getScreenCoordinatesFrom3D(c8.x, c8.y, c8.z));

        bbmin.x = Math.min(c1.x, Math.min(c2.x, Math.min(c3.x, Math.min(c4.x, Math.min(c5.x, Math.min(c6.x, Math.min(c7.x, c8.x)))))));
        bbmax.x = Math.max(c1.x, Math.max(c2.x, Math.max(c3.x, Math.max(c4.x, Math.max(c5.x, Math.max(c6.x, Math.max(c7.x, c8.x)))))));

        bbmin.y = Math.min(c1.y, Math.min(c2.y, Math.min(c3.y, Math.min(c4.y, Math.min(c5.y, Math.min(c6.y, Math.min(c7.y, c8.y)))))));
        bbmax.y = Math.max(c1.y, Math.max(c2.y, Math.max(c3.y, Math.max(c4.y, Math.max(c5.y, Math.max(c6.y, Math.max(c7.y, c8.y)))))));

        Rectangle boundingBox = new Rectangle((int) bbmin.x, (int) bbmin.y, (int) (bbmax.x - bbmin.x), (int) (bbmax.y - bbmin.y));

        boolean tempNegativeDeterminant = GData.globalNegativeDeterminant;
        GData.globalNegativeDeterminant = GData.globalNegativeDeterminant ^ negativeDeterminant;

        if (boundingBox.intersects(bounds) || boundingBox.contains(0, 0) || boundingBox.contains(bounds.width, bounds.height) || boundingBox.contains(bounds.width, 0)
                || boundingBox.contains(0, bounds.height) || bounds.contains(boundingBox.x, boundingBox.y) || bounds.contains(boundingBox.x, boundingBox.y + boundingBox.height)
                || bounds.contains(boundingBox.x + boundingBox.width, boundingBox.y) || bounds.contains(boundingBox.x + boundingBox.width, boundingBox.y + boundingBox.height)) {

            GL11.glPushMatrix();
            GL11.glMultMatrixf(matrix);

            if (c3d.isShowingLogo()) {
                if (filesWithLogo1.contains(shortName))
                    drawStudLogo1_GL20();
                else if (filesWithLogo2.contains(shortName))
                    drawStudLogo2_GL20();
            }

            GData data2draw = myGData;
            if (GData.accumClip > 0) {
                GData.accumClip++;
                while ((data2draw = data2draw.next) != null && !ViewIdleManager.pause[0].get())
                    data2draw.drawGL20(c3d);
                GData.accumClip--;
            } else {
                while ((data2draw = data2draw.next) != null && !ViewIdleManager.pause[0].get())
                    data2draw.drawGL20(c3d);
                if (GData.accumClip > 0)
                    GData.accumClip = 0;
            }

            GL11.glPopMatrix();

        }

        GData.globalNegativeDeterminant = tempNegativeDeterminant;

    }
}
 
Example 5
Source File: GData1.java    From ldparteditor with MIT License 4 votes vote down vote up
@Override
public void drawGL20_RandomColours(Composite3D c3d) {
    if (!visible)
        return;
    if (matrix != null) {

        final Rectangle bounds = c3d.getClientArea();
        final PerspectiveCalculator PC = c3d.getPerspectiveCalculator();

        Vector4f bbmin = new Vector4f();
        Vector4f bbmax = new Vector4f();

        Vector4f c1 = new Vector4f(boundingBoxMin);
        Vector4f c2 = new Vector4f(boundingBoxMin);
        Vector4f c3 = new Vector4f(boundingBoxMin);
        Vector4f c4 = new Vector4f(boundingBoxMin);
        Vector4f c5 = new Vector4f(boundingBoxMax);
        Vector4f c6 = new Vector4f(boundingBoxMax);
        Vector4f c7 = new Vector4f(boundingBoxMax);
        Vector4f c8 = new Vector4f(boundingBoxMax);

        c2.x = boundingBoxMax.x;
        c3.y = boundingBoxMax.y;
        c4.z = boundingBoxMax.z;

        c6.x = boundingBoxMin.x;
        c7.y = boundingBoxMin.y;
        c8.z = boundingBoxMin.z;

        c1.set(PC.getScreenCoordinatesFrom3D(c1.x, c1.y, c1.z));
        c2.set(PC.getScreenCoordinatesFrom3D(c2.x, c2.y, c2.z));
        c3.set(PC.getScreenCoordinatesFrom3D(c3.x, c3.y, c3.z));
        c4.set(PC.getScreenCoordinatesFrom3D(c4.x, c4.y, c4.z));
        c5.set(PC.getScreenCoordinatesFrom3D(c5.x, c5.y, c5.z));
        c6.set(PC.getScreenCoordinatesFrom3D(c6.x, c6.y, c6.z));
        c7.set(PC.getScreenCoordinatesFrom3D(c7.x, c7.y, c7.z));
        c8.set(PC.getScreenCoordinatesFrom3D(c8.x, c8.y, c8.z));

        bbmin.x = Math.min(c1.x, Math.min(c2.x, Math.min(c3.x, Math.min(c4.x, Math.min(c5.x, Math.min(c6.x, Math.min(c7.x, c8.x)))))));
        bbmax.x = Math.max(c1.x, Math.max(c2.x, Math.max(c3.x, Math.max(c4.x, Math.max(c5.x, Math.max(c6.x, Math.max(c7.x, c8.x)))))));

        bbmin.y = Math.min(c1.y, Math.min(c2.y, Math.min(c3.y, Math.min(c4.y, Math.min(c5.y, Math.min(c6.y, Math.min(c7.y, c8.y)))))));
        bbmax.y = Math.max(c1.y, Math.max(c2.y, Math.max(c3.y, Math.max(c4.y, Math.max(c5.y, Math.max(c6.y, Math.max(c7.y, c8.y)))))));

        Rectangle boundingBox = new Rectangle((int) bbmin.x, (int) bbmin.y, (int) (bbmax.x - bbmin.x), (int) (bbmax.y - bbmin.y));

        boolean tempNegativeDeterminant = GData.globalNegativeDeterminant;
        GData.globalNegativeDeterminant = GData.globalNegativeDeterminant ^ negativeDeterminant;

        if (boundingBox.intersects(bounds) || boundingBox.contains(0, 0) || boundingBox.contains(bounds.width, bounds.height) || boundingBox.contains(bounds.width, 0)
                || boundingBox.contains(0, bounds.height) || bounds.contains(boundingBox.x, boundingBox.y) || bounds.contains(boundingBox.x, boundingBox.y + boundingBox.height)
                || bounds.contains(boundingBox.x + boundingBox.width, boundingBox.y) || bounds.contains(boundingBox.x + boundingBox.width, boundingBox.y + boundingBox.height)) {

            GL11.glPushMatrix();
            GL11.glMultMatrixf(matrix);

            if (c3d.isShowingLogo()) {
                if (filesWithLogo1.contains(shortName))
                    drawStudLogo1_GL20();
                else if (filesWithLogo2.contains(shortName))
                    drawStudLogo2_GL20();
            }

            GData data2draw = myGData;
            if (GData.accumClip > 0) {
                GData.accumClip++;
                while ((data2draw = data2draw.next) != null && !ViewIdleManager.pause[0].get())
                    data2draw.drawGL20_RandomColours(c3d);
                GData.accumClip--;
            } else {
                while ((data2draw = data2draw.next) != null && !ViewIdleManager.pause[0].get())
                    data2draw.drawGL20_RandomColours(c3d);
                if (GData.accumClip > 0)
                    GData.accumClip = 0;
            }

            GL11.glPopMatrix();

        }

        GData.globalNegativeDeterminant = tempNegativeDeterminant;

    }
}
 
Example 6
Source File: GData1.java    From ldparteditor with MIT License 4 votes vote down vote up
@Override
public void drawGL20_BFCuncertified(Composite3D c3d) {
    if (!visible)
        return;
    if (matrix != null) {

        final Rectangle bounds = c3d.getClientArea();
        final PerspectiveCalculator PC = c3d.getPerspectiveCalculator();

        Vector4f bbmin = new Vector4f();
        Vector4f bbmax = new Vector4f();

        Vector4f c1 = new Vector4f(boundingBoxMin);
        Vector4f c2 = new Vector4f(boundingBoxMin);
        Vector4f c3 = new Vector4f(boundingBoxMin);
        Vector4f c4 = new Vector4f(boundingBoxMin);
        Vector4f c5 = new Vector4f(boundingBoxMax);
        Vector4f c6 = new Vector4f(boundingBoxMax);
        Vector4f c7 = new Vector4f(boundingBoxMax);
        Vector4f c8 = new Vector4f(boundingBoxMax);

        c2.x = boundingBoxMax.x;
        c3.y = boundingBoxMax.y;
        c4.z = boundingBoxMax.z;

        c6.x = boundingBoxMin.x;
        c7.y = boundingBoxMin.y;
        c8.z = boundingBoxMin.z;

        c1.set(PC.getScreenCoordinatesFrom3D(c1.x, c1.y, c1.z));
        c2.set(PC.getScreenCoordinatesFrom3D(c2.x, c2.y, c2.z));
        c3.set(PC.getScreenCoordinatesFrom3D(c3.x, c3.y, c3.z));
        c4.set(PC.getScreenCoordinatesFrom3D(c4.x, c4.y, c4.z));
        c5.set(PC.getScreenCoordinatesFrom3D(c5.x, c5.y, c5.z));
        c6.set(PC.getScreenCoordinatesFrom3D(c6.x, c6.y, c6.z));
        c7.set(PC.getScreenCoordinatesFrom3D(c7.x, c7.y, c7.z));
        c8.set(PC.getScreenCoordinatesFrom3D(c8.x, c8.y, c8.z));

        bbmin.x = Math.min(c1.x, Math.min(c2.x, Math.min(c3.x, Math.min(c4.x, Math.min(c5.x, Math.min(c6.x, Math.min(c7.x, c8.x)))))));
        bbmax.x = Math.max(c1.x, Math.max(c2.x, Math.max(c3.x, Math.max(c4.x, Math.max(c5.x, Math.max(c6.x, Math.max(c7.x, c8.x)))))));

        bbmin.y = Math.min(c1.y, Math.min(c2.y, Math.min(c3.y, Math.min(c4.y, Math.min(c5.y, Math.min(c6.y, Math.min(c7.y, c8.y)))))));
        bbmax.y = Math.max(c1.y, Math.max(c2.y, Math.max(c3.y, Math.max(c4.y, Math.max(c5.y, Math.max(c6.y, Math.max(c7.y, c8.y)))))));

        Rectangle boundingBox = new Rectangle((int) bbmin.x, (int) bbmin.y, (int) (bbmax.x - bbmin.x), (int) (bbmax.y - bbmin.y));


        byte tempWinding = GData.localWinding;
        boolean tempInvertNext = GData.globalInvertNext;
        boolean tempInvertNextFound = GData.globalInvertNextFound;
        boolean tempNegativeDeterminant = GData.globalNegativeDeterminant;
        GData.globalNegativeDeterminant = GData.globalNegativeDeterminant ^ negativeDeterminant;

        if (boundingBox.intersects(bounds) || boundingBox.contains(0, 0) || boundingBox.contains(bounds.width, bounds.height) || boundingBox.contains(bounds.width, 0)
                || boundingBox.contains(0, bounds.height) || bounds.contains(boundingBox.x, boundingBox.y) || bounds.contains(boundingBox.x, boundingBox.y + boundingBox.height)
                || bounds.contains(boundingBox.x + boundingBox.width, boundingBox.y) || bounds.contains(boundingBox.x + boundingBox.width, boundingBox.y + boundingBox.height)) {

            GL11.glPushMatrix();
            GL11.glMultMatrixf(matrix);

            if (c3d.isShowingLogo()) {
                if (filesWithLogo1.contains(shortName))
                    drawStudLogo1_GL20();
                else if (filesWithLogo2.contains(shortName))
                    drawStudLogo2_GL20();
            }

            GData data2draw = myGData;
            if (GData.accumClip > 0) {
                GData.accumClip++;
                while ((data2draw = data2draw.next) != null && !ViewIdleManager.pause[0].get())
                    data2draw.drawGL20_BFCuncertified(c3d);
                GData.accumClip--;
            } else {
                while ((data2draw = data2draw.next) != null && !ViewIdleManager.pause[0].get())
                    data2draw.drawGL20_BFCuncertified(c3d);
                if (GData.accumClip > 0)
                    GData.accumClip = 0;
            }

            GL11.glPopMatrix();

        }

        GData.localWinding = tempWinding;
        if (tempInvertNextFound)
            GData.globalInvertNext = !tempInvertNext;

        GData.globalNegativeDeterminant = tempNegativeDeterminant;

    }
}
 
Example 7
Source File: GData1.java    From ldparteditor with MIT License 4 votes vote down vote up
@Override
public void drawGL20_BFC_Textured(Composite3D c3d) {
    boolean tNext = GData.globalFoundTEXMAPNEXT;
    GData.globalFoundTEXMAPNEXT = false;
    if (!visible || !GData.globalDrawObjects)
        return;
    if (matrix != null) {

        final Rectangle bounds = c3d.getClientArea();
        final PerspectiveCalculator PC = c3d.getPerspectiveCalculator();

        Vector4f bbmin = new Vector4f();
        Vector4f bbmax = new Vector4f();

        Vector4f c1 = new Vector4f(boundingBoxMin);
        Vector4f c2 = new Vector4f(boundingBoxMin);
        Vector4f c3 = new Vector4f(boundingBoxMin);
        Vector4f c4 = new Vector4f(boundingBoxMin);
        Vector4f c5 = new Vector4f(boundingBoxMax);
        Vector4f c6 = new Vector4f(boundingBoxMax);
        Vector4f c7 = new Vector4f(boundingBoxMax);
        Vector4f c8 = new Vector4f(boundingBoxMax);

        c2.x = boundingBoxMax.x;
        c3.y = boundingBoxMax.y;
        c4.z = boundingBoxMax.z;

        c6.x = boundingBoxMin.x;
        c7.y = boundingBoxMin.y;
        c8.z = boundingBoxMin.z;

        c1.set(PC.getScreenCoordinatesFrom3D(c1.x, c1.y, c1.z));
        c2.set(PC.getScreenCoordinatesFrom3D(c2.x, c2.y, c2.z));
        c3.set(PC.getScreenCoordinatesFrom3D(c3.x, c3.y, c3.z));
        c4.set(PC.getScreenCoordinatesFrom3D(c4.x, c4.y, c4.z));
        c5.set(PC.getScreenCoordinatesFrom3D(c5.x, c5.y, c5.z));
        c6.set(PC.getScreenCoordinatesFrom3D(c6.x, c6.y, c6.z));
        c7.set(PC.getScreenCoordinatesFrom3D(c7.x, c7.y, c7.z));
        c8.set(PC.getScreenCoordinatesFrom3D(c8.x, c8.y, c8.z));

        bbmin.x = Math.min(c1.x, Math.min(c2.x, Math.min(c3.x, Math.min(c4.x, Math.min(c5.x, Math.min(c6.x, Math.min(c7.x, c8.x)))))));
        bbmax.x = Math.max(c1.x, Math.max(c2.x, Math.max(c3.x, Math.max(c4.x, Math.max(c5.x, Math.max(c6.x, Math.max(c7.x, c8.x)))))));

        bbmin.y = Math.min(c1.y, Math.min(c2.y, Math.min(c3.y, Math.min(c4.y, Math.min(c5.y, Math.min(c6.y, Math.min(c7.y, c8.y)))))));
        bbmax.y = Math.max(c1.y, Math.max(c2.y, Math.max(c3.y, Math.max(c4.y, Math.max(c5.y, Math.max(c6.y, Math.max(c7.y, c8.y)))))));

        Rectangle boundingBox = new Rectangle((int) bbmin.x, (int) bbmin.y, (int) (bbmax.x - bbmin.x), (int) (bbmax.y - bbmin.y));

        byte tempWinding = GData.localWinding;
        boolean tempInvertNext = GData.globalInvertNext;
        boolean tempInvertNextFound = GData.globalInvertNextFound;
        boolean tempNegativeDeterminant = GData.globalNegativeDeterminant;

        GData.globalInvertNextFound = false;
        GData.localWinding = BFC.NOCERTIFY;
        GData.globalNegativeDeterminant = GData.globalNegativeDeterminant ^ negativeDeterminant;

        if (boundingBox.intersects(bounds) || boundingBox.contains(0, 0) || boundingBox.contains(bounds.width, bounds.height) || boundingBox.contains(bounds.width, 0)
                || boundingBox.contains(0, bounds.height) || bounds.contains(boundingBox.x, boundingBox.y) || bounds.contains(boundingBox.x, boundingBox.y + boundingBox.height)
                || bounds.contains(boundingBox.x + boundingBox.width, boundingBox.y) || bounds.contains(boundingBox.x + boundingBox.width, boundingBox.y + boundingBox.height)) {

            GData.globalFoundTEXMAPStack.push(false);

            GData data2draw = myGData;

            if (GData.accumClip > 0) {
                GData.accumClip++;
                while ((data2draw = data2draw.next) != null && !ViewIdleManager.pause[0].get())
                    data2draw.drawGL20_BFC_Textured(c3d);
                GData.accumClip--;
            } else {
                while ((data2draw = data2draw.next) != null && !ViewIdleManager.pause[0].get()) {
                    data2draw.drawGL20_BFC_Textured(c3d);
                }
                if (GData.accumClip > 0)
                    GData.accumClip = 0;
            }

            if (GData.globalFoundTEXMAPStack.peek()) {
                GData.globalFoundTEXMAPStack.pop();
                GData.globalTextureStack.pop();
                GData.globalFoundTEXMAPStack.push(false);
                GData.globalDrawObjects = true;
            }
            GData.globalFoundTEXMAPStack.pop();

        }

        GData.localWinding = tempWinding;
        if (tempInvertNextFound)
            GData.globalInvertNext = !tempInvertNext;

        GData.globalNegativeDeterminant = tempNegativeDeterminant;
    }
    if (tNext) {
        GData.globalFoundTEXMAPStack.pop();
        GData.globalTextureStack.pop();
        GData.globalFoundTEXMAPStack.push(false);
        GData.globalFoundTEXMAPNEXT = false;
    }
}
 
Example 8
Source File: GData1.java    From ldparteditor with MIT License 4 votes vote down vote up
@Override
public void drawGL20_CoplanarityHeatmap(Composite3D c3d) {
    if (!visible)
        return;
    if (matrix != null) {

        final Rectangle bounds = c3d.getClientArea();
        final PerspectiveCalculator PC = c3d.getPerspectiveCalculator();

        Vector4f bbmin = new Vector4f();
        Vector4f bbmax = new Vector4f();

        Vector4f c1 = new Vector4f(boundingBoxMin);
        Vector4f c2 = new Vector4f(boundingBoxMin);
        Vector4f c3 = new Vector4f(boundingBoxMin);
        Vector4f c4 = new Vector4f(boundingBoxMin);
        Vector4f c5 = new Vector4f(boundingBoxMax);
        Vector4f c6 = new Vector4f(boundingBoxMax);
        Vector4f c7 = new Vector4f(boundingBoxMax);
        Vector4f c8 = new Vector4f(boundingBoxMax);

        c2.x = boundingBoxMax.x;
        c3.y = boundingBoxMax.y;
        c4.z = boundingBoxMax.z;

        c6.x = boundingBoxMin.x;
        c7.y = boundingBoxMin.y;
        c8.z = boundingBoxMin.z;

        c1.set(PC.getScreenCoordinatesFrom3D(c1.x, c1.y, c1.z));
        c2.set(PC.getScreenCoordinatesFrom3D(c2.x, c2.y, c2.z));
        c3.set(PC.getScreenCoordinatesFrom3D(c3.x, c3.y, c3.z));
        c4.set(PC.getScreenCoordinatesFrom3D(c4.x, c4.y, c4.z));
        c5.set(PC.getScreenCoordinatesFrom3D(c5.x, c5.y, c5.z));
        c6.set(PC.getScreenCoordinatesFrom3D(c6.x, c6.y, c6.z));
        c7.set(PC.getScreenCoordinatesFrom3D(c7.x, c7.y, c7.z));
        c8.set(PC.getScreenCoordinatesFrom3D(c8.x, c8.y, c8.z));

        bbmin.x = Math.min(c1.x, Math.min(c2.x, Math.min(c3.x, Math.min(c4.x, Math.min(c5.x, Math.min(c6.x, Math.min(c7.x, c8.x)))))));
        bbmax.x = Math.max(c1.x, Math.max(c2.x, Math.max(c3.x, Math.max(c4.x, Math.max(c5.x, Math.max(c6.x, Math.max(c7.x, c8.x)))))));

        bbmin.y = Math.min(c1.y, Math.min(c2.y, Math.min(c3.y, Math.min(c4.y, Math.min(c5.y, Math.min(c6.y, Math.min(c7.y, c8.y)))))));
        bbmax.y = Math.max(c1.y, Math.max(c2.y, Math.max(c3.y, Math.max(c4.y, Math.max(c5.y, Math.max(c6.y, Math.max(c7.y, c8.y)))))));

        Rectangle boundingBox = new Rectangle((int) bbmin.x, (int) bbmin.y, (int) (bbmax.x - bbmin.x), (int) (bbmax.y - bbmin.y));

        boolean tempNegativeDeterminant = GData.globalNegativeDeterminant;
        GData.globalNegativeDeterminant = GData.globalNegativeDeterminant ^ negativeDeterminant;

        if (boundingBox.intersects(bounds) || boundingBox.contains(0, 0) || boundingBox.contains(bounds.width, bounds.height) || boundingBox.contains(bounds.width, 0)
                || boundingBox.contains(0, bounds.height) || bounds.contains(boundingBox.x, boundingBox.y) || bounds.contains(boundingBox.x, boundingBox.y + boundingBox.height)
                || bounds.contains(boundingBox.x + boundingBox.width, boundingBox.y) || bounds.contains(boundingBox.x + boundingBox.width, boundingBox.y + boundingBox.height)) {

            GL11.glPushMatrix();
            GL11.glMultMatrixf(matrix);

            if (c3d.isShowingLogo()) {
                if (filesWithLogo1.contains(shortName))
                    drawStudLogo1_GL20();
                else if (filesWithLogo2.contains(shortName))
                    drawStudLogo2_GL20();
            }

            GData data2draw = myGData;
            if (GData.accumClip > 0) {
                GData.accumClip++;
                while ((data2draw = data2draw.next) != null && !ViewIdleManager.pause[0].get())
                    data2draw.drawGL20_CoplanarityHeatmap(c3d);
                GData.accumClip--;
            } else {
                while ((data2draw = data2draw.next) != null && !ViewIdleManager.pause[0].get())
                    data2draw.drawGL20_CoplanarityHeatmap(c3d);
                if (GData.accumClip > 0)
                    GData.accumClip = 0;
            }

            GL11.glPopMatrix();

        }

        GData.globalNegativeDeterminant = tempNegativeDeterminant;

    }
}
 
Example 9
Source File: GData1.java    From ldparteditor with MIT License 4 votes vote down vote up
@Override
public void drawGL20_Wireframe(Composite3D c3d) {
    if (!visible)
        return;
    if (matrix != null) {

        final Rectangle bounds = c3d.getClientArea();
        final PerspectiveCalculator PC = c3d.getPerspectiveCalculator();

        Vector4f bbmin = new Vector4f();
        Vector4f bbmax = new Vector4f();

        Vector4f c1 = new Vector4f(boundingBoxMin);
        Vector4f c2 = new Vector4f(boundingBoxMin);
        Vector4f c3 = new Vector4f(boundingBoxMin);
        Vector4f c4 = new Vector4f(boundingBoxMin);
        Vector4f c5 = new Vector4f(boundingBoxMax);
        Vector4f c6 = new Vector4f(boundingBoxMax);
        Vector4f c7 = new Vector4f(boundingBoxMax);
        Vector4f c8 = new Vector4f(boundingBoxMax);

        c2.x = boundingBoxMax.x;
        c3.y = boundingBoxMax.y;
        c4.z = boundingBoxMax.z;

        c6.x = boundingBoxMin.x;
        c7.y = boundingBoxMin.y;
        c8.z = boundingBoxMin.z;

        c1.set(PC.getScreenCoordinatesFrom3D(c1.x, c1.y, c1.z));
        c2.set(PC.getScreenCoordinatesFrom3D(c2.x, c2.y, c2.z));
        c3.set(PC.getScreenCoordinatesFrom3D(c3.x, c3.y, c3.z));
        c4.set(PC.getScreenCoordinatesFrom3D(c4.x, c4.y, c4.z));
        c5.set(PC.getScreenCoordinatesFrom3D(c5.x, c5.y, c5.z));
        c6.set(PC.getScreenCoordinatesFrom3D(c6.x, c6.y, c6.z));
        c7.set(PC.getScreenCoordinatesFrom3D(c7.x, c7.y, c7.z));
        c8.set(PC.getScreenCoordinatesFrom3D(c8.x, c8.y, c8.z));

        bbmin.x = Math.min(c1.x, Math.min(c2.x, Math.min(c3.x, Math.min(c4.x, Math.min(c5.x, Math.min(c6.x, Math.min(c7.x, c8.x)))))));
        bbmax.x = Math.max(c1.x, Math.max(c2.x, Math.max(c3.x, Math.max(c4.x, Math.max(c5.x, Math.max(c6.x, Math.max(c7.x, c8.x)))))));

        bbmin.y = Math.min(c1.y, Math.min(c2.y, Math.min(c3.y, Math.min(c4.y, Math.min(c5.y, Math.min(c6.y, Math.min(c7.y, c8.y)))))));
        bbmax.y = Math.max(c1.y, Math.max(c2.y, Math.max(c3.y, Math.max(c4.y, Math.max(c5.y, Math.max(c6.y, Math.max(c7.y, c8.y)))))));

        Rectangle boundingBox = new Rectangle((int) bbmin.x, (int) bbmin.y, (int) (bbmax.x - bbmin.x), (int) (bbmax.y - bbmin.y));

        boolean tempNegativeDeterminant = GData.globalNegativeDeterminant;
        GData.globalNegativeDeterminant = GData.globalNegativeDeterminant ^ negativeDeterminant;

        if (boundingBox.intersects(bounds) || boundingBox.contains(0, 0) || boundingBox.contains(bounds.width, bounds.height) || boundingBox.contains(bounds.width, 0)
                || boundingBox.contains(0, bounds.height) || bounds.contains(boundingBox.x, boundingBox.y) || bounds.contains(boundingBox.x, boundingBox.y + boundingBox.height)
                || bounds.contains(boundingBox.x + boundingBox.width, boundingBox.y) || bounds.contains(boundingBox.x + boundingBox.width, boundingBox.y + boundingBox.height)) {

            GL11.glPushMatrix();
            GL11.glMultMatrixf(matrix);

            if (c3d.isShowingLogo()) {
                if (filesWithLogo1.contains(shortName))
                    drawStudLogo1_GL20();
                else if (filesWithLogo2.contains(shortName))
                    drawStudLogo2_GL20();
            }

            GData data2draw = myGData;
            if (GData.accumClip > 0) {
                GData.accumClip++;
                while ((data2draw = data2draw.next) != null && !ViewIdleManager.pause[0].get())
                    data2draw.drawGL20_Wireframe(c3d);
                GData.accumClip--;
            } else {
                while ((data2draw = data2draw.next) != null && !ViewIdleManager.pause[0].get())
                    data2draw.drawGL20_Wireframe(c3d);
                if (GData.accumClip > 0)
                    GData.accumClip = 0;
            }

            GL11.glPopMatrix();

        }

        GData.globalNegativeDeterminant = tempNegativeDeterminant;

    }
}
 
Example 10
Source File: Sprite.java    From tribaltrouble with GNU General Public License v2.0 4 votes vote down vote up
private final void expandAnimation(AnimationInfo[] animations, float[][][] tmp_vertices, float[][][] tmp_normals, float[] initial_pose_vertices, float[] initial_pose_normals, byte[][] skin_names, float[][] skin_weights, BoundingBox[] bounding_boxes) {
		int num_bones = animations[0].getFrames()[0].length/12;
		Matrix4f[] frame_bones = new Matrix4f[num_bones];
		for (int bone = 0; bone < frame_bones.length; bone++)
			frame_bones[bone] = new Matrix4f();
		Vector4f v = new Vector4f();
		Vector4f n = new Vector4f();
		Vector4f temp = new Vector4f();
		FloatBuffer matrix_buffer = FloatBuffer.allocate(16);
		matrix_buffer.put(15, 1f);
		for (int anim = 0; anim < animations.length; anim++) {
			BoundingBox bounding_box = bounding_boxes[anim];
			int num_frames = animations[anim].getFrames().length;
			tmp_vertices[anim] = new float[num_frames][num_vertices*3];
			tmp_normals[anim] = new float[num_frames][num_vertices*3];
			for (int frame = 0; frame < num_frames; frame++) {
				float[] frame_animation = animations[anim].getFrames()[frame];
				for (int bone = 0; bone < num_bones; bone++) {
					matrix_buffer.clear();
					matrix_buffer.put(frame_animation, bone*12, 12);
					matrix_buffer.rewind();
					frame_bones[bone].loadTranspose(matrix_buffer);
				}
				float[] frame_normals = tmp_normals[anim][frame];
				float[] frame_vertices = tmp_vertices[anim][frame];
				float bmax_x = Float.NEGATIVE_INFINITY;
				float bmax_y = Float.NEGATIVE_INFINITY;
				float bmax_z = Float.NEGATIVE_INFINITY;
				float bmin_x = Float.POSITIVE_INFINITY;
				float bmin_y = Float.POSITIVE_INFINITY;
				float bmin_z = Float.POSITIVE_INFINITY;
				for (int vertex = 0; vertex < num_vertices; vertex++) {
					float x = initial_pose_vertices[vertex*3 + 0];
					float y = initial_pose_vertices[vertex*3 + 1];
					float z = initial_pose_vertices[vertex*3 + 2];
					float nx = initial_pose_normals[vertex*3 + 0];
					float ny = initial_pose_normals[vertex*3 + 1];
					float nz = initial_pose_normals[vertex*3 + 2];
					float result_x = 0, result_y = 0, result_z = 0, result_nx = 0, result_ny = 0, result_nz = 0;
					v.set(x, y, z, 1);
					n.set(nx, ny, nz, 0);
					byte[] vertex_skin_names = skin_names[vertex];
					float[] vertex_skin_weights = skin_weights[vertex];
					for (int bone = 0; bone < vertex_skin_names.length; bone++) {
						float weight = vertex_skin_weights[bone];
						Matrix4f bone_matrix = frame_bones[vertex_skin_names[bone]];
						Matrix4f.transform(bone_matrix, v, temp);
						result_x += temp.x*weight;
						result_y += temp.y*weight;
						result_z += temp.z*weight;
						// Assume matrix is only translation and scaling
						Matrix4f.transform(bone_matrix, n, temp);
						result_nx += temp.x*weight;
						result_ny += temp.y*weight;
						result_nz += temp.z*weight;
					}
					// Use Math.sqrt here for efficiency. Only used for normals (not gamestate affecting) anyway.
					float vec_len_inv = 1f/(float)Math.sqrt(result_nx*result_nx + result_ny*result_ny + result_nz*result_nz);
					result_nx *= vec_len_inv;
					result_ny *= vec_len_inv;
					result_nz *= vec_len_inv;
					frame_normals[vertex*3 + 0] = result_nx;
					frame_normals[vertex*3 + 1] = result_ny;
					frame_normals[vertex*3 + 2] = result_nz;

//result_x = x; result_y = y; result_z = z;
					if (result_x < bmin_x)
						bmin_x = result_x;
					else if (result_x > bmax_x)
						bmax_x = result_x;
					if (result_y < bmin_y)
						bmin_y = result_y;
					else if (result_y > bmax_y)
						bmax_y = result_y;
					if (result_z < bmin_z)
						bmin_z = result_z;
					else if (result_z > bmax_z)
						bmax_z = result_z;
					frame_vertices[vertex*3 + 0] = result_x;
					frame_vertices[vertex*3 + 1] = result_y;
					frame_vertices[vertex*3 + 2] = result_z;
				}
				bounding_box.checkBounds(bmin_x, bmax_x, bmin_y, bmax_y, bmin_z, bmax_z);
			}
		}
	}
 
Example 11
Source File: PerspectiveCalculator.java    From ldparteditor with MIT License 3 votes vote down vote up
/**
 * Transforms 3D space coordinates to screen coordinates
 *
 * @param x
 *            x-screen coordinate
 * @param y
 *            y-screen coordinate
 * @param z
 *            z-screen coordinate
 * @return vector position on screen
 */
public Vector4f getScreenCoordinatesFrom3D(float x, float y, float z) {
    Point cSize = c3d.getSize();
    Vector4f relPos = new Vector4f(x, y, z, 1f);
    Matrix4f.transform(c3d.getViewport(), relPos, relPos);
    float cursor_x = 0.5f * cSize.x - relPos.x * View.PIXEL_PER_LDU;
    float cursor_y = 0.5f * cSize.y + relPos.y * View.PIXEL_PER_LDU;
    relPos.set(cursor_x, cursor_y, 0f, 1f);
    return relPos;
}