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

The following examples show how to use org.lwjgl.util.vector.Matrix4f#load() . 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: CompositePrimitive.java    From ldparteditor with MIT License 6 votes vote down vote up
public void mouseDown(Event event) {
    reMapMouseEvent(event);
    mouse_button_pressed = event.button;
    old_mouse_position.set(event.x, event.y);
    switch (event.button) {
    case MouseButton.LEFT:
        setSelectedPrimitive(getFocusedPrimitive());
        break;
    case MouseButton.MIDDLE:
        Matrix4f.load(getRotation(), old_viewport_rotation);
        break;
    case MouseButton.RIGHT:
        Matrix4f.load(getTranslation(), old_viewport_translation);
        break;
    default:
    }
    openGL.drawScene(event.x, event.y);
    Editor3DWindow.getWindow().regainFocus();
}
 
Example 3
Source File: CompositePrimitive.java    From ldparteditor with MIT License 6 votes vote down vote up
private void adjustTranslate(float old, float zoom2) {
    float dx = 0;
    float dy = 0;
    dx = 0f / viewport_pixel_per_ldu;
    dy = 0f / viewport_pixel_per_ldu;
    Vector4f xAxis4f_translation = new Vector4f(dx, 0, 0, 1.0f);
    Vector4f yAxis4f_translation = new Vector4f(0, dy, 0, 1.0f);
    Vector3f xAxis3 = new Vector3f(xAxis4f_translation.x, xAxis4f_translation.y, xAxis4f_translation.z);
    Vector3f yAxis3 = new Vector3f(yAxis4f_translation.x, yAxis4f_translation.y, yAxis4f_translation.z);

    Matrix4f.load(old_viewport_translation, viewport_translation);
    Matrix4f.translate(xAxis3, old_viewport_translation, viewport_translation);
    Matrix4f.translate(yAxis3, viewport_translation, viewport_translation);

    viewport_translation.m30 = 0f;
    if (viewport_translation.m13 > 0f) viewport_translation.m13 = 0f;
    if (-viewport_translation.m31 > maxY) viewport_translation.m31 = -maxY;
}
 
Example 4
Source File: CompositePrimitive.java    From ldparteditor with MIT License 6 votes vote down vote up
public void scroll(boolean down) {

        float dy = 0;

        Matrix4f.load(getTranslation(), old_viewport_translation);

        if (down) {
            dy = -37f /  viewport_pixel_per_ldu;
        } else {
            dy = 37f /  viewport_pixel_per_ldu;
        }

        Vector4f yAxis4f_translation = new Vector4f(0, dy, 0, 1.0f);
        Vector3f yAxis3 = new Vector3f(yAxis4f_translation.x, yAxis4f_translation.y, yAxis4f_translation.z);
        Matrix4f.load(old_viewport_translation, viewport_translation);
        Matrix4f.translate(yAxis3, old_viewport_translation, viewport_translation);

        if (viewport_translation.m31 > 0f) viewport_translation.m31 = 0f;
        if (-viewport_translation.m31 > maxY) viewport_translation.m31 = -maxY;

        openGL.drawScene(-1, -1);
    }
 
Example 5
Source File: GUIRoot.java    From tribaltrouble with GNU General Public License v2.0 6 votes vote down vote up
protected final void displayChangedNotify(int width, int height) {
	//Reset The Current Viewport And Perspective Transformation
	setDim(width, height);
	if (width != 0) {
		float scale = getUnitsPerPixel(Globals.GUI_Z);
		Matrix4f m1 = new Matrix4f();
		m1.setIdentity();
		Matrix4f m2 = new Matrix4f();
		m2.setIdentity();
		Matrix4f m3 = new Matrix4f();
		m1.scale(new Vector3f(scale, scale, scale));
		m2.translate(new Vector3f(0f, 0f, -Globals.GUI_Z));
		Matrix4f.mul(m2, m1, m3);
		m2.load(m3);
		m3.setIdentity();
		m3.translate(new Vector3f(-width/2f, -height/2f, 0f));
		Matrix4f.mul(m2, m3, m1);
		m1.store(matrix_buf);
		matrix_buf.rewind();
	}
	for (int i = 0; i < delegate_stack.size(); i++) {
		((CameraDelegate)delegate_stack.get(i)).displayChanged(width, height);
	}
}
 
Example 6
Source File: MatrixUtil.java    From tectonicus with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public static void testLookAtMatrix(Vector3f eye, Vector3f center, Vector3f up)
{
	// Make a lookat matrix in opengl and pull it out into a Matrix4f
	GL11.glMatrixMode(GL11.GL_MODELVIEW);
	GL11.glLoadIdentity();
	GLU.gluLookAt(eye.x, eye.y, eye.z, center.x, center.y, center.z, up.x, up.y, up.z);
	
	FloatBuffer fromGlBuffer = BufferUtils.createFloatBuffer(16);
	GL11.glGetFloat(GL11.GL_MODELVIEW, fromGlBuffer);
	Matrix4f fromGl = new Matrix4f();
	fromGl.load(fromGlBuffer);
	
	Matrix4f manual = createLookAt(eye, center, up);
	
	compare(fromGl, manual);
}
 
Example 7
Source File: FontHelper.java    From ForbiddenMagic with Do What The F*ck You Want To Public License 6 votes vote down vote up
private static void set2DMode(FloatBuffer matrixData) {
    Minecraft mc = Minecraft.getMinecraft();
    ScaledResolution sr = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight);
    mc.entityRenderer.setupOverlayRendering();
    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glPushMatrix();
    //GL11.glLoadMatrix(matrixData);

    GL11.glLoadIdentity();
    GL11.glOrtho(0, mc.displayWidth, 0, mc.displayHeight, -1, 1);
    GL11.glMatrixMode(GL11.GL_MODELVIEW);
    GL11.glPushMatrix();
    GL11.glLoadIdentity();

    Matrix4f matrix = new Matrix4f();
    matrix.load(matrixData);
    GL11.glTranslatef(matrix.m30*sr.getScaleFactor(),-matrix.m31*sr.getScaleFactor(), 0f);

}
 
Example 8
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 9
Source File: MouseActions.java    From ldparteditor with MIT License 5 votes vote down vote up
public void translateViewport(float dx, float dy, Matrix4f viewport_translation, Matrix4f viewport_rotation,
        PerspectiveCalculator perspective) {
    Vector4f xAxis4f_translation = new Vector4f(dx, 0, 0, 1.0f);
    Vector4f yAxis4f_translation = new Vector4f(0, dy, 0, 1.0f);
    Matrix4f ovr_inverse2 = Matrix4f.invert(viewport_rotation, null);
    Matrix4f.transform(ovr_inverse2, xAxis4f_translation, xAxis4f_translation);
    Matrix4f.transform(ovr_inverse2, yAxis4f_translation, yAxis4f_translation);
    Vector3f xAxis3 = new Vector3f(xAxis4f_translation.x, xAxis4f_translation.y, xAxis4f_translation.z);
    Vector3f yAxis3 = new Vector3f(yAxis4f_translation.x, yAxis4f_translation.y, yAxis4f_translation.z);
    Matrix4f.load(old_viewport_translation, viewport_translation);
    Matrix4f.translate(xAxis3, old_viewport_translation, viewport_translation);
    Matrix4f.translate(yAxis3, viewport_translation, viewport_translation);
    perspective.calculateOriginData();
}
 
Example 10
Source File: KeyStateManager.java    From ldparteditor with MIT License 5 votes vote down vote up
private static void translateView(Composite3D c3d, float dx, float dy) {
    PerspectiveCalculator perspective = c3d.getPerspectiveCalculator();
    Matrix4f viewport_rotation = c3d.getRotation();
    Matrix4f viewport_translation = c3d.getTranslation();
    Matrix4f old_viewport_translation = new Matrix4f();
    Matrix4f.load(c3d.getTranslation(), old_viewport_translation);
    Vector4f xAxis4f_translation = new Vector4f(dx, 0, 0, 1.0f);
    Vector4f yAxis4f_translation = new Vector4f(0, dy, 0, 1.0f);
    Matrix4f ovr_inverse2 = Matrix4f.invert(viewport_rotation, null);
    Matrix4f.transform(ovr_inverse2, xAxis4f_translation, xAxis4f_translation);
    Matrix4f.transform(ovr_inverse2, yAxis4f_translation, yAxis4f_translation);
    Vector3f xAxis3 = new Vector3f(xAxis4f_translation.x, xAxis4f_translation.y, xAxis4f_translation.z);
    Vector3f yAxis3 = new Vector3f(yAxis4f_translation.x, yAxis4f_translation.y, yAxis4f_translation.z);
    Matrix4f.load(old_viewport_translation, viewport_translation);
    Matrix4f.translate(xAxis3, old_viewport_translation, viewport_translation);
    Matrix4f.translate(yAxis3, viewport_translation, viewport_translation);
    perspective.calculateOriginData();
    c3d.getVertexManager().getResetTimer().set(true);
    if (c3d.isSyncTranslation()) {
        float tx = c3d.getTranslation().m30;
        float ty = c3d.getTranslation().m31;
        float tz = c3d.getTranslation().m32;
        for (OpenGLRenderer renderer : Editor3DWindow.getRenders()) {
            Composite3D c3d2 = renderer.getC3D();
            if (!c3d2.isDisposed() && c3d != c3d2 && c3d.getLockableDatFileReference().equals(c3d2.getLockableDatFileReference())) {
                c3d2.getTranslation().m30 = tx;
                c3d2.getTranslation().m31 = ty;
                c3d2.getTranslation().m32 = tz;
                ((ScalableComposite) c3d2.getParent()).redrawScales();
                c3d2.getPerspectiveCalculator().initializeViewportPerspective();
            }
        }
    }
}
 
Example 11
Source File: MatrixUtil.java    From tectonicus with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static void testOrthoMatrix(final int left, final int right, final int bottom, final int top, final int near, final int far)
{
	// Make an ortho matrix in opengl and pull it out into a Matrix4f
	GL11.glMatrixMode(GL11.GL_MODELVIEW);
	GL11.glLoadIdentity();
	GL11.glOrtho(left, right, bottom, top, near, far);
	FloatBuffer fromGlBuffer = BufferUtils.createFloatBuffer(16);
	GL11.glGetFloat(GL11.GL_MODELVIEW, fromGlBuffer);
	Matrix4f fromGl = new Matrix4f();
	fromGl.load(fromGlBuffer);
	
	Matrix4f manual = createOrthoMatrix(left, right, bottom, top, near, far);
	
	compare(fromGl, manual);
}
 
Example 12
Source File: GLUProjection.java    From seppuku with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Updates the matrices. Needed whenever the viewport or one of the matrices has changed.
 *
 * @param viewport    Viewport
 * @param modelview   Modelview matrix
 * @param projection  Projection matrix
 * @param widthScale  (GUI Width) / (Display Width)
 * @param heightScale (GUI Height) / (Display Height)
 */
public void updateMatrices(IntBuffer viewport, FloatBuffer modelview, FloatBuffer projection, double widthScale, double heightScale) {
    this.viewport = viewport;
    this.modelview = modelview;
    this.projection = projection;
    this.widthScale = widthScale;
    this.heightScale = heightScale;

    //Get fov and display dimensions
    float fov = (float) Math.toDegrees(Math.atan(1.0D / this.projection.get(5)) * 2.0D);
    this.fovY = fov;
    this.displayWidth = this.viewport.get(2);
    this.displayHeight = this.viewport.get(3);
    this.fovX = (float) Math.toDegrees(2.0D * Math.atan((this.displayWidth / this.displayHeight) * Math.tan(Math.toRadians(this.fovY) / 2.0D)));
    //Getting modelview vectors
    Vector3D lv = new Vector3D(this.modelview.get(0), this.modelview.get(1), this.modelview.get(2));
    Vector3D uv = new Vector3D(this.modelview.get(4), this.modelview.get(5), this.modelview.get(6));
    Vector3D fv = new Vector3D(this.modelview.get(8), this.modelview.get(9), this.modelview.get(10));
    //Default axes
    Vector3D nuv = new Vector3D(0, 1.0D, 0);
    Vector3D nlv = new Vector3D(1.0D, 0, 0);
    //Calculate yaw and pitch from modelview
    double yaw = Math.toDegrees(Math.atan2(nlv.cross(lv).length(), nlv.dot(lv))) + 180.0D;
    if (fv.x < 0.0D) {
        yaw = 360.0D - yaw;
    }
    double pitch = 0.0D;
    if ((-fv.y > 0.0D && yaw >= 90.0D && yaw < 270.0D) || (fv.y > 0.0D && !(yaw >= 90.0D && yaw < 270.0D))) {
        pitch = Math.toDegrees(Math.atan2(nuv.cross(uv).length(), nuv.dot(uv)));
    } else {
        pitch = -Math.toDegrees(Math.atan2(nuv.cross(uv).length(), nuv.dot(uv)));
    }
    this.lookVec = this.getRotationVector(yaw, pitch);
    //Get modelview matrix and invert it
    Matrix4f modelviewMatrix = new Matrix4f();
    modelviewMatrix.load(this.modelview.asReadOnlyBuffer());
    modelviewMatrix.invert();
    //Get frustum position
    this.frustumPos = new Vector3D(modelviewMatrix.m30, modelviewMatrix.m31, modelviewMatrix.m32);
    this.frustum = this.getFrustum(this.frustumPos.x, this.frustumPos.y, this.frustumPos.z, yaw, pitch, fov, 1.0F, displayWidth / displayHeight);
    this.invFrustum = this.getFrustum(this.frustumPos.x, this.frustumPos.y, this.frustumPos.z, yaw - 180, -pitch, fov, 1.0F, displayWidth / displayHeight);
    //Set view vec
    this.viewVec = this.getRotationVector(yaw, pitch).normalized();
    //Calculate screen border angles
    this.bra = Math.toDegrees(Math.acos((displayHeight * heightScale) / Math.sqrt(displayWidth * widthScale * displayWidth * widthScale + displayHeight * heightScale * displayHeight * heightScale)));
    this.bla = 360 - this.bra;
    this.tra = this.bla - 180;
    this.tla = this.bra + 180;
    //Create screen border lines
    this.rb = new Line(this.displayWidth * this.widthScale, 0, 0, 0, 1, 0);
    this.tb = new Line(0, 0, 0, 1, 0, 0);
    this.lb = new Line(0, 0, 0, 0, 1, 0);
    this.bb = new Line(0, this.displayHeight * this.heightScale, 0, 1, 0, 0);
}
 
Example 13
Source File: MouseActions.java    From ldparteditor with MIT License 4 votes vote down vote up
public void prepareTranslateViewport() {
    Matrix4f.load(c3d.getTranslation(), old_viewport_translation);
}