Java Code Examples for org.lwjgl.util.vector.Matrix4f#transpose()

The following examples show how to use org.lwjgl.util.vector.Matrix4f#transpose() . 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: AnimationLoader.java    From OpenGL-Animation with The Unlicense 6 votes vote down vote up
private void processTransforms(String jointName, String[] rawData, KeyFrameData[] keyFrames, boolean root){
	FloatBuffer buffer = BufferUtils.createFloatBuffer(16);
	float[] matrixData = new float[16];
	for(int i=0;i<keyFrames.length;i++){
		for(int j=0;j<16;j++){
			matrixData[j] = Float.parseFloat(rawData[i*16 + j]);
		}
		buffer.clear();
		buffer.put(matrixData);
		buffer.flip();
		Matrix4f transform = new Matrix4f();
		transform.load(buffer);
		transform.transpose();
		if(root){
			//because up axis in Blender is different to up axis in game
			Matrix4f.mul(CORRECTION, transform, transform);
		}
		keyFrames[i].addJointTransform(new JointTransformData(jointName, transform));
	}
}
 
Example 2
Source File: SkeletonLoader.java    From OpenGL-Animation with The Unlicense 5 votes vote down vote up
private JointData extractMainJointData(XmlNode jointNode, boolean isRoot){
	String nameId = jointNode.getAttribute("id");
	int index = boneOrder.indexOf(nameId);
	String[] matrixData = jointNode.getChild("matrix").getData().split(" ");
	Matrix4f matrix = new Matrix4f();
	matrix.load(convertData(matrixData));
	matrix.transpose();
	if(isRoot){
		//because in Blender z is up, but in our game y is up.
		Matrix4f.mul(CORRECTION, matrix, matrix);
	}
	jointCount++;
	return new JointData(index, nameId, matrix);
}
 
Example 3
Source File: GDataCSG.java    From ldparteditor with MIT License 5 votes vote down vote up
public synchronized Matrix4f getLDrawMatrix() {
    Matrix4f oldMatrix = new Matrix4f(matrix);
    Matrix4f.transpose(oldMatrix, oldMatrix);
    oldMatrix.m30 = oldMatrix.m03;
    oldMatrix.m31 = oldMatrix.m13;
    oldMatrix.m32 = oldMatrix.m23;
    oldMatrix.m03 = 0f;
    oldMatrix.m13 = 0f;
    oldMatrix.m23 = 0f;
    return oldMatrix;
}
 
Example 4
Source File: GDataCSG.java    From ldparteditor with MIT License 4 votes vote down vote up
@Override
public synchronized String transformAndColourReplace(String colour2, Matrix matrix) {
    boolean notChoosen = true;
    String t = null;
    switch (type) {
    case CSG.QUAD:
        if (notChoosen) {
            t = " CSG_QUAD "; //$NON-NLS-1$
            notChoosen = false;
        }
    case CSG.CIRCLE:
        if (notChoosen) {
            t = " CSG_CIRCLE "; //$NON-NLS-1$
            notChoosen = false;
        }
    case CSG.ELLIPSOID:
        if (notChoosen) {
            t = " CSG_ELLIPSOID "; //$NON-NLS-1$
            notChoosen = false;
        }
    case CSG.CUBOID:
        if (notChoosen) {
            t = " CSG_CUBOID "; //$NON-NLS-1$
            notChoosen = false;
        }
    case CSG.CYLINDER:
        if (notChoosen) {
            t = " CSG_CYLINDER "; //$NON-NLS-1$
            notChoosen = false;
        }
    case CSG.MESH:
        if (notChoosen) {
            t = " CSG_MESH "; //$NON-NLS-1$
            notChoosen = false;
        }
    case CSG.EXTRUDE:
        if (notChoosen) {
            t = " CSG_EXTRUDE "; //$NON-NLS-1$
            notChoosen = false;
        }
    case CSG.TRANSFORM:
        if (notChoosen) {
            t = " CSG_TRANSFORM "; //$NON-NLS-1$
            notChoosen = false;
        }
    case CSG.CONE:
        if (notChoosen) {
            t = " CSG_CONE "; //$NON-NLS-1$
            notChoosen = false;
        }
        StringBuilder colourBuilder = new StringBuilder();
        if (colour == null) {
            colourBuilder.append(16);
        } else if (colour.getColourNumber() == -1) {
            colourBuilder.append("0x2"); //$NON-NLS-1$
            colourBuilder.append(MathHelper.toHex((int) (255f * colour.getR())).toUpperCase());
            colourBuilder.append(MathHelper.toHex((int) (255f * colour.getG())).toUpperCase());
            colourBuilder.append(MathHelper.toHex((int) (255f * colour.getB())).toUpperCase());
        } else {
            colourBuilder.append(colour.getColourNumber());
        }
        Matrix4f newMatrix = new Matrix4f(this.matrix);
        Matrix4f newMatrix2 = new Matrix4f(matrix.getMatrix4f());
        Matrix4f.transpose(newMatrix, newMatrix);
        newMatrix.m30 = newMatrix.m03;
        newMatrix.m31 = newMatrix.m13;
        newMatrix.m32 = newMatrix.m23;
        newMatrix.m03 = 0f;
        newMatrix.m13 = 0f;
        newMatrix.m23 = 0f;
        Matrix4f.mul(newMatrix2, newMatrix, newMatrix);
        String col = colourBuilder.toString();
        if (col.equals(colour2))
            col = "16"; //$NON-NLS-1$
        String tag = ref1.substring(0, ref1.lastIndexOf("#>")); //$NON-NLS-1$
        return "0 !LPE" + t + tag + " " + col + " " + MathHelper.matrixToString(newMatrix); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    default:
        return text;
    }
}
 
Example 5
Source File: GDataCSG.java    From ldparteditor with MIT License 4 votes vote down vote up
public synchronized String transform(Matrix4f m) {
    boolean notChoosen = true;
    String t = null;
    switch (type) {
    case CSG.QUAD:
        if (notChoosen) {
            t = " CSG_QUAD "; //$NON-NLS-1$
            notChoosen = false;
        }
    case CSG.CIRCLE:
        if (notChoosen) {
            t = " CSG_CIRCLE "; //$NON-NLS-1$
            notChoosen = false;
        }
    case CSG.ELLIPSOID:
        if (notChoosen) {
            t = " CSG_ELLIPSOID "; //$NON-NLS-1$
            notChoosen = false;
        }
    case CSG.CUBOID:
        if (notChoosen) {
            t = " CSG_CUBOID "; //$NON-NLS-1$
            notChoosen = false;
        }
    case CSG.CYLINDER:
        if (notChoosen) {
            t = " CSG_CYLINDER "; //$NON-NLS-1$
            notChoosen = false;
        }
    case CSG.MESH:
        if (notChoosen) {
            t = " CSG_MESH "; //$NON-NLS-1$
            notChoosen = false;
        }
    case CSG.EXTRUDE:
        if (notChoosen) {
            t = " CSG_EXTRUDE "; //$NON-NLS-1$
            notChoosen = false;
        }
    case CSG.TRANSFORM:
        if (notChoosen) {
            t = " CSG_TRANSFORM "; //$NON-NLS-1$
            notChoosen = false;
        }
    case CSG.CONE:
        if (notChoosen) {
            t = " CSG_CONE "; //$NON-NLS-1$
            notChoosen = false;
        }
        StringBuilder colourBuilder = new StringBuilder();
        if (colour == null) {
            colourBuilder.append(16);
        } else if (colour.getColourNumber() == -1) {
            colourBuilder.append("0x2"); //$NON-NLS-1$
            colourBuilder.append(MathHelper.toHex((int) (255f * colour.getR())).toUpperCase());
            colourBuilder.append(MathHelper.toHex((int) (255f * colour.getG())).toUpperCase());
            colourBuilder.append(MathHelper.toHex((int) (255f * colour.getB())).toUpperCase());
        } else {
            colourBuilder.append(colour.getColourNumber());
        }

        Matrix4f oldMatrix = new Matrix4f(matrix);

        oldMatrix.m30 = oldMatrix.m30 / 1000f;
        oldMatrix.m31 = oldMatrix.m31 / 1000f;
        oldMatrix.m32 = oldMatrix.m32 / 1000f;

        Matrix4f.transpose(oldMatrix, oldMatrix);
        oldMatrix.m30 = oldMatrix.m03;
        oldMatrix.m31 = oldMatrix.m13;
        oldMatrix.m32 = oldMatrix.m23;
        oldMatrix.m03 = 0f;
        oldMatrix.m13 = 0f;
        oldMatrix.m23 = 0f;

        Matrix accurateLocalMatrix = new Matrix(oldMatrix);
        Matrix transformation = new Matrix(m);
        transformation = transformation.transpose();
        BigDecimal tx = accurateLocalMatrix.M30.add(BigDecimal.ZERO);
        BigDecimal ty = accurateLocalMatrix.M31.add(BigDecimal.ZERO);
        BigDecimal tz = accurateLocalMatrix.M32.add(BigDecimal.ZERO);
        accurateLocalMatrix = accurateLocalMatrix.translate(new BigDecimal[] { tx.negate(), ty.negate(), tz.negate() });
        accurateLocalMatrix = Matrix.mul(transformation, accurateLocalMatrix);
        accurateLocalMatrix = accurateLocalMatrix.translate(new BigDecimal[] { tx, ty, tz });

        String tag = ref1.substring(0, ref1.lastIndexOf("#>")); //$NON-NLS-1$
        if (type == CSG.TRANSFORM) {
            tag = tag + " " + ref2.substring(0, ref2.lastIndexOf("#>")); //$NON-NLS-1$ //$NON-NLS-2$
            accurateLocalMatrix = accurateLocalMatrix.transpose();
            accurateLocalMatrix = accurateLocalMatrix.transposeXYZ();
        }
        return "0 !LPE" + t + tag + " " + colourBuilder.toString() + accurateLocalMatrix.toLDrawString(); //$NON-NLS-1$ //$NON-NLS-2$
    default:
        return text;
    }
}
 
Example 6
Source File: GDataCSG.java    From ldparteditor with MIT License 4 votes vote down vote up
public synchronized String colourReplace(String colour2) {
    boolean notChoosen = true;
    String t = null;
    switch (type) {
    case CSG.QUAD:
        if (notChoosen) {
            t = " CSG_QUAD "; //$NON-NLS-1$
            notChoosen = false;
        }
    case CSG.CIRCLE:
        if (notChoosen) {
            t = " CSG_CIRCLE "; //$NON-NLS-1$
            notChoosen = false;
        }
    case CSG.ELLIPSOID:
        if (notChoosen) {
            t = " CSG_ELLIPSOID "; //$NON-NLS-1$
            notChoosen = false;
        }
    case CSG.CUBOID:
        if (notChoosen) {
            t = " CSG_CUBOID "; //$NON-NLS-1$
            notChoosen = false;
        }
    case CSG.CYLINDER:
        if (notChoosen) {
            t = " CSG_CYLINDER "; //$NON-NLS-1$
            notChoosen = false;
        }
    case CSG.MESH:
        if (notChoosen) {
            t = " CSG_MESH "; //$NON-NLS-1$
            notChoosen = false;
        }
    case CSG.EXTRUDE:
        if (notChoosen) {
            t = " CSG_EXTRUDE "; //$NON-NLS-1$
            notChoosen = false;
        }
    case CSG.TRANSFORM:
        if (notChoosen) {
            t = " CSG_TRANSFORM "; //$NON-NLS-1$
            notChoosen = false;
        }
    case CSG.CONE:
        if (notChoosen) {
            t = " CSG_CONE "; //$NON-NLS-1$
            notChoosen = false;
        }
        Matrix4f newMatrix = new Matrix4f(this.matrix);
        Matrix4f.transpose(newMatrix, newMatrix);
        newMatrix.m30 = newMatrix.m03;
        newMatrix.m31 = newMatrix.m13;
        newMatrix.m32 = newMatrix.m23;
        newMatrix.m03 = 0f;
        newMatrix.m13 = 0f;
        newMatrix.m23 = 0f;
        String col = colour2;
        String tag = ref1.substring(0, ref1.lastIndexOf("#>")); //$NON-NLS-1$
        if (type == CSG.TRANSFORM) {
            tag = tag + " " + ref2.substring(0, ref2.lastIndexOf("#>")); //$NON-NLS-1$ //$NON-NLS-2$
        }
        return "0 !LPE" + t + tag + " " + col + " " + MathHelper.matrixToString(newMatrix); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    default:
        return text;
    }
}
 
Example 7
Source File: GDataCSG.java    From ldparteditor with MIT License 4 votes vote down vote up
public synchronized String getRoundedString(int coordsDecimalPlaces, int matrixDecimalPlaces, final boolean onX,  final boolean onY,  final boolean onZ) {
    boolean notChoosen = true;
    String t = null;
    switch (type) {
    case CSG.QUAD:
        if (notChoosen) {
            t = " CSG_QUAD "; //$NON-NLS-1$
            notChoosen = false;
        }
    case CSG.CIRCLE:
        if (notChoosen) {
            t = " CSG_CIRCLE "; //$NON-NLS-1$
            notChoosen = false;
        }
    case CSG.ELLIPSOID:
        if (notChoosen) {
            t = " CSG_ELLIPSOID "; //$NON-NLS-1$
            notChoosen = false;
        }
    case CSG.CUBOID:
        if (notChoosen) {
            t = " CSG_CUBOID "; //$NON-NLS-1$
            notChoosen = false;
        }
    case CSG.CYLINDER:
        if (notChoosen) {
            t = " CSG_CYLINDER "; //$NON-NLS-1$
            notChoosen = false;
        }
    case CSG.MESH:
        if (notChoosen) {
            t = " CSG_MESH "; //$NON-NLS-1$
            notChoosen = false;
        }
    case CSG.EXTRUDE:
        if (notChoosen) {
            t = " CSG_EXTRUDE "; //$NON-NLS-1$
            notChoosen = false;
        }
    case CSG.TRANSFORM:
        if (notChoosen) {
            t = " CSG_TRANSFORM "; //$NON-NLS-1$
            notChoosen = false;
        }
    case CSG.CONE:
        if (notChoosen) {
            t = " CSG_CONE "; //$NON-NLS-1$
            notChoosen = false;
        }
        StringBuilder colourBuilder = new StringBuilder();
        if (colour == null) {
            colourBuilder.append(16);
        } else if (colour.getColourNumber() == -1) {
            colourBuilder.append("0x2"); //$NON-NLS-1$
            colourBuilder.append(MathHelper.toHex((int) (255f * colour.getR())).toUpperCase());
            colourBuilder.append(MathHelper.toHex((int) (255f * colour.getG())).toUpperCase());
            colourBuilder.append(MathHelper.toHex((int) (255f * colour.getB())).toUpperCase());
        } else {
            colourBuilder.append(colour.getColourNumber());
        }

        Matrix4f newMatrix = new Matrix4f(this.matrix);
        Matrix4f.transpose(newMatrix, newMatrix);
        newMatrix.m30 = newMatrix.m03;
        newMatrix.m31 = newMatrix.m13;
        newMatrix.m32 = newMatrix.m23;
        newMatrix.m03 = 0f;
        newMatrix.m13 = 0f;
        newMatrix.m23 = 0f;
        String tag = ref1.substring(0, ref1.lastIndexOf("#>")); //$NON-NLS-1$
        if (type == CSG.TRANSFORM) {
            tag = tag + " " + ref2.substring(0, ref2.lastIndexOf("#>")); //$NON-NLS-1$ //$NON-NLS-2$
        }
        return "0 !LPE" + t + tag + " " + colourBuilder.toString() + " " + MathHelper.matrixToString(newMatrix, coordsDecimalPlaces, matrixDecimalPlaces, onX, onY, onZ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    }
    return null;
}