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

The following examples show how to use org.lwjgl.util.vector.Matrix4f#rotate() . 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: Trackball.java    From OpenModsLib with MIT License 6 votes vote down vote up
private Matrix4f getTransform(float mouseX, float mouseY) {
	Preconditions.checkNotNull(dragStart, "Draging not started");
	Vector3f current = calculateSpherePoint(mouseX, mouseY);

	float dot = Vector3f.dot(dragStart, current);
	if (Math.abs(dot - 1) < 0.0001) return lastTransform;

	Vector3f axis = Vector3f.cross(dragStart, current, null);

	try {
		axis.normalise();
	} catch (IllegalStateException e) { // Zero length vector
		return lastTransform;
	}

	float angle = 2 * (float)(Math.acos(dot));

	Matrix4f rotation = new Matrix4f();
	rotation.rotate(angle, axis);
	return Matrix4f.mul(rotation, lastTransform, null);

}
 
Example 2
Source File: FaceBakery.java    From The-5zig-Mod with MIT License 5 votes vote down vote up
private void a(Vector3f vector, boi blockPartRotation) {
	if (blockPartRotation != null) {
		Matrix4f var2 = this.a();
		Vector3f var3 = new Vector3f(0.0F, 0.0F, 0.0F);
		switch (blockPartRotation.b) {
			case a:
				Matrix4f.rotate(blockPartRotation.c * 0.017453292F, new Vector3f(1.0F, 0.0F, 0.0F), var2, var2);
				var3.set(0.0F, 1.0F, 1.0F);
				break;
			case b:
				Matrix4f.rotate(blockPartRotation.c * 0.017453292F, new Vector3f(0.0F, 1.0F, 0.0F), var2, var2);
				var3.set(1.0F, 0.0F, 1.0F);
				break;
			case c:
				Matrix4f.rotate(blockPartRotation.c * 0.017453292F, new Vector3f(0.0F, 0.0F, 1.0F), var2, var2);
				var3.set(1.0F, 1.0F, 0.0F);
		}

		if (blockPartRotation.d) {
			if (Math.abs(blockPartRotation.c) == 22.5F) {
				var3.scale(fieldA);
			} else {
				var3.scale(fieldB);
			}

			Vector3f.add(var3, new Vector3f(1.0F, 1.0F, 1.0F), var3);
		} else {
			var3.set(1.0F, 1.0F, 1.0F);
		}

		this.a(vector, new Vector3f(blockPartRotation.a), var2, var3);
	}
}
 
Example 3
Source File: MathUtils.java    From OpenModsLib with MIT License 5 votes vote down vote up
public static Matrix4f createEntityRotateMatrix(Entity entity) {
	double yaw = Math.toRadians(entity.rotationYaw - 180);
	double pitch = Math.toRadians(entity.rotationPitch);

	Matrix4f initial = new Matrix4f();
	initial.rotate((float)pitch, new Vector3f(1, 0, 0));
	initial.rotate((float)yaw, new Vector3f(0, 1, 0));
	return initial;
}
 
Example 4
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 5
Source File: Camera.java    From OpenGL-Animation with The Unlicense 5 votes vote down vote up
private void updateViewMatrix() {
	viewMatrix.setIdentity();
	Matrix4f.rotate((float) Math.toRadians(pitch.get()), new Vector3f(1, 0, 0), viewMatrix, viewMatrix);
	Matrix4f.rotate((float) Math.toRadians(yaw), new Vector3f(0, 1, 0), viewMatrix, viewMatrix);
	Vector3f negativeCameraPos = new Vector3f(-position.x, -position.y, -position.z);
	Matrix4f.translate(negativeCameraPos, viewMatrix, viewMatrix);
}
 
Example 6
Source File: Maths.java    From LowPolyWater with The Unlicense 5 votes vote down vote up
public static void updateViewMatrix(Matrix4f viewMatrix, float x, float y, float z, float pitch, float yaw){
	viewMatrix.setIdentity();
	Matrix4f.rotate((float) Math.toRadians(pitch), new Vector3f(1, 0, 0), viewMatrix, viewMatrix);
	Matrix4f.rotate((float) Math.toRadians(yaw), new Vector3f(0, 1, 0), viewMatrix, viewMatrix);
	Vector3f negativeCameraPos = new Vector3f(-x, -y, -z);
	Matrix4f.translate(negativeCameraPos, viewMatrix, viewMatrix);
}
 
Example 7
Source File: FaceBakery.java    From The-5zig-Mod with MIT License 5 votes vote down vote up
private void a(Vector3f vector, bvs blockPartRotation) {
	if (blockPartRotation != null) {
		Matrix4f var2 = this.a();
		Vector3f var3 = new Vector3f(0.0F, 0.0F, 0.0F);
		switch (blockPartRotation.b) {
			case a:
				Matrix4f.rotate(blockPartRotation.c * 0.017453292F, new Vector3f(1.0F, 0.0F, 0.0F), var2, var2);
				var3.set(0.0F, 1.0F, 1.0F);
				break;
			case b:
				Matrix4f.rotate(blockPartRotation.c * 0.017453292F, new Vector3f(0.0F, 1.0F, 0.0F), var2, var2);
				var3.set(1.0F, 0.0F, 1.0F);
				break;
			case c:
				Matrix4f.rotate(blockPartRotation.c * 0.017453292F, new Vector3f(0.0F, 0.0F, 1.0F), var2, var2);
				var3.set(1.0F, 1.0F, 0.0F);
		}

		if (blockPartRotation.d) {
			if (Math.abs(blockPartRotation.c) == 22.5F) {
				var3.scale(fieldA);
			} else {
				var3.scale(fieldB);
			}

			Vector3f.add(var3, new Vector3f(1.0F, 1.0F, 1.0F), var3);
		} else {
			var3.set(1.0F, 1.0F, 1.0F);
		}

		this.a(vector, new Vector3f(blockPartRotation.a), var2, var3);
	}
}
 
Example 8
Source File: FaceBakery.java    From The-5zig-Mod with MIT License 5 votes vote down vote up
private void a(Vector3f vector, bpb blockPartRotation) {
	if (blockPartRotation != null) {
		Matrix4f var2 = this.a();
		Vector3f var3 = new Vector3f(0.0F, 0.0F, 0.0F);
		switch (blockPartRotation.b) {
			case a:
				Matrix4f.rotate(blockPartRotation.c * 0.017453292F, new Vector3f(1.0F, 0.0F, 0.0F), var2, var2);
				var3.set(0.0F, 1.0F, 1.0F);
				break;
			case b:
				Matrix4f.rotate(blockPartRotation.c * 0.017453292F, new Vector3f(0.0F, 1.0F, 0.0F), var2, var2);
				var3.set(1.0F, 0.0F, 1.0F);
				break;
			case c:
				Matrix4f.rotate(blockPartRotation.c * 0.017453292F, new Vector3f(0.0F, 0.0F, 1.0F), var2, var2);
				var3.set(1.0F, 1.0F, 0.0F);
		}

		if (blockPartRotation.d) {
			if (Math.abs(blockPartRotation.c) == 22.5F) {
				var3.scale(fieldA);
			} else {
				var3.scale(fieldB);
			}

			Vector3f.add(var3, new Vector3f(1.0F, 1.0F, 1.0F), var3);
		} else {
			var3.set(1.0F, 1.0F, 1.0F);
		}

		this.a(vector, new Vector3f(blockPartRotation.a), var2, var3);
	}
}
 
Example 9
Source File: FaceBakery.java    From The-5zig-Mod with MIT License 5 votes vote down vote up
private void a(Vector3f vector, bpb blockPartRotation) {
	if (blockPartRotation != null) {
		Matrix4f var2 = this.a();
		Vector3f var3 = new Vector3f(0.0F, 0.0F, 0.0F);
		switch (blockPartRotation.b) {
			case a:
				Matrix4f.rotate(blockPartRotation.c * 0.017453292F, new Vector3f(1.0F, 0.0F, 0.0F), var2, var2);
				var3.set(0.0F, 1.0F, 1.0F);
				break;
			case b:
				Matrix4f.rotate(blockPartRotation.c * 0.017453292F, new Vector3f(0.0F, 1.0F, 0.0F), var2, var2);
				var3.set(1.0F, 0.0F, 1.0F);
				break;
			case c:
				Matrix4f.rotate(blockPartRotation.c * 0.017453292F, new Vector3f(0.0F, 0.0F, 1.0F), var2, var2);
				var3.set(1.0F, 1.0F, 0.0F);
		}

		if (blockPartRotation.d) {
			if (Math.abs(blockPartRotation.c) == 22.5F) {
				var3.scale(fieldA);
			} else {
				var3.scale(fieldB);
			}

			Vector3f.add(var3, new Vector3f(1.0F, 1.0F, 1.0F), var3);
		} else {
			var3.set(1.0F, 1.0F, 1.0F);
		}

		this.a(vector, new Vector3f(blockPartRotation.a), var2, var3);
	}
}
 
Example 10
Source File: FaceBakery.java    From The-5zig-Mod with MIT License 5 votes vote down vote up
private void a(Vector3f vector, bre blockPartRotation) {
	if (blockPartRotation != null) {
		Matrix4f var2 = this.a();
		Vector3f var3 = new Vector3f(0.0F, 0.0F, 0.0F);
		switch (blockPartRotation.b) {
			case a:
				Matrix4f.rotate(blockPartRotation.c * 0.017453292F, new Vector3f(1.0F, 0.0F, 0.0F), var2, var2);
				var3.set(0.0F, 1.0F, 1.0F);
				break;
			case b:
				Matrix4f.rotate(blockPartRotation.c * 0.017453292F, new Vector3f(0.0F, 1.0F, 0.0F), var2, var2);
				var3.set(1.0F, 0.0F, 1.0F);
				break;
			case c:
				Matrix4f.rotate(blockPartRotation.c * 0.017453292F, new Vector3f(0.0F, 0.0F, 1.0F), var2, var2);
				var3.set(1.0F, 1.0F, 0.0F);
		}

		if (blockPartRotation.d) {
			if (Math.abs(blockPartRotation.c) == 22.5F) {
				var3.scale(fieldA);
			} else {
				var3.scale(fieldB);
			}

			Vector3f.add(var3, new Vector3f(1.0F, 1.0F, 1.0F), var3);
		} else {
			var3.set(1.0F, 1.0F, 1.0F);
		}

		this.a(vector, new Vector3f(blockPartRotation.a), var2, var3);
	}
}
 
Example 11
Source File: FaceBakery.java    From The-5zig-Mod with MIT License 5 votes vote down vote up
private void a(Vector3f vector, bgj var1) {
	if (var1 != null) {
		Matrix4f var2 = this.a();
		Vector3f var3 = new Vector3f(0.0F, 0.0F, 0.0F);
		switch (var1.b) {
			case a:
				Matrix4f.rotate(var1.c * 0.017453292F, new Vector3f(1.0F, 0.0F, 0.0F), var2, var2);
				var3.set(0.0F, 1.0F, 1.0F);
				break;
			case b:
				Matrix4f.rotate(var1.c * 0.017453292F, new Vector3f(0.0F, 1.0F, 0.0F), var2, var2);
				var3.set(1.0F, 0.0F, 1.0F);
				break;
			case c:
				Matrix4f.rotate(var1.c * 0.017453292F, new Vector3f(0.0F, 0.0F, 1.0F), var2, var2);
				var3.set(1.0F, 1.0F, 0.0F);
		}

		if (var1.d) {
			if (Math.abs(var1.c) == 22.5F) {
				var3.scale(fieldA);
			} else {
				var3.scale(fieldB);
			}

			Vector3f.add(var3, new Vector3f(1.0F, 1.0F, 1.0F), var3);
		} else {
			var3.set(1.0F, 1.0F, 1.0F);
		}

		this.a(vector, new Vector3f(var1.a), var2, var3);
	}
}
 
Example 12
Source File: FaceBakery.java    From The-5zig-Mod with MIT License 5 votes vote down vote up
private void a(Vector3f vector, bvq blockPartRotation) {
	if (blockPartRotation != null) {
		Matrix4f var2 = this.a();
		Vector3f var3 = new Vector3f(0.0F, 0.0F, 0.0F);
		switch (blockPartRotation.b) {
			case a:
				Matrix4f.rotate(blockPartRotation.c * 0.017453292F, new Vector3f(1.0F, 0.0F, 0.0F), var2, var2);
				var3.set(0.0F, 1.0F, 1.0F);
				break;
			case b:
				Matrix4f.rotate(blockPartRotation.c * 0.017453292F, new Vector3f(0.0F, 1.0F, 0.0F), var2, var2);
				var3.set(1.0F, 0.0F, 1.0F);
				break;
			case c:
				Matrix4f.rotate(blockPartRotation.c * 0.017453292F, new Vector3f(0.0F, 0.0F, 1.0F), var2, var2);
				var3.set(1.0F, 1.0F, 0.0F);
		}

		if (blockPartRotation.d) {
			if (Math.abs(blockPartRotation.c) == 22.5F) {
				var3.scale(fieldA);
			} else {
				var3.scale(fieldB);
			}

			Vector3f.add(var3, new Vector3f(1.0F, 1.0F, 1.0F), var3);
		} else {
			var3.set(1.0F, 1.0F, 1.0F);
		}

		this.a(vector, new Vector3f(blockPartRotation.a), var2, var3);
	}
}
 
Example 13
Source File: FaceBakery.java    From The-5zig-Mod with MIT License 5 votes vote down vote up
private void a(Vector3f vector, brg blockPartRotation) {
	if (blockPartRotation != null) {
		Matrix4f var2 = this.a();
		Vector3f var3 = new Vector3f(0.0F, 0.0F, 0.0F);
		switch (blockPartRotation.b) {
			case a:
				Matrix4f.rotate(blockPartRotation.c * 0.017453292F, new Vector3f(1.0F, 0.0F, 0.0F), var2, var2);
				var3.set(0.0F, 1.0F, 1.0F);
				break;
			case b:
				Matrix4f.rotate(blockPartRotation.c * 0.017453292F, new Vector3f(0.0F, 1.0F, 0.0F), var2, var2);
				var3.set(1.0F, 0.0F, 1.0F);
				break;
			case c:
				Matrix4f.rotate(blockPartRotation.c * 0.017453292F, new Vector3f(0.0F, 0.0F, 1.0F), var2, var2);
				var3.set(1.0F, 1.0F, 0.0F);
		}

		if (blockPartRotation.d) {
			if (Math.abs(blockPartRotation.c) == 22.5F) {
				var3.scale(fieldA);
			} else {
				var3.scale(fieldB);
			}

			Vector3f.add(var3, new Vector3f(1.0F, 1.0F, 1.0F), var3);
		} else {
			var3.set(1.0F, 1.0F, 1.0F);
		}

		this.a(vector, new Vector3f(blockPartRotation.a), var2, var3);
	}
}
 
Example 14
Source File: FaceBakery.java    From The-5zig-Mod with MIT License 5 votes vote down vote up
private void a(Vector3f vector, bof blockPartRotation) {
	if (blockPartRotation != null) {
		Matrix4f var2 = this.a();
		Vector3f var3 = new Vector3f(0.0F, 0.0F, 0.0F);
		switch (blockPartRotation.b) {
			case a:
				Matrix4f.rotate(blockPartRotation.c * 0.017453292F, new Vector3f(1.0F, 0.0F, 0.0F), var2, var2);
				var3.set(0.0F, 1.0F, 1.0F);
				break;
			case b:
				Matrix4f.rotate(blockPartRotation.c * 0.017453292F, new Vector3f(0.0F, 1.0F, 0.0F), var2, var2);
				var3.set(1.0F, 0.0F, 1.0F);
				break;
			case c:
				Matrix4f.rotate(blockPartRotation.c * 0.017453292F, new Vector3f(0.0F, 0.0F, 1.0F), var2, var2);
				var3.set(1.0F, 1.0F, 0.0F);
		}

		if (blockPartRotation.d) {
			if (Math.abs(blockPartRotation.c) == 22.5F) {
				var3.scale(fieldA);
			} else {
				var3.scale(fieldB);
			}

			Vector3f.add(var3, new Vector3f(1.0F, 1.0F, 1.0F), var3);
		} else {
			var3.set(1.0F, 1.0F, 1.0F);
		}

		this.a(vector, new Vector3f(blockPartRotation.a), var2, var3);
	}
}
 
Example 15
Source File: FaceBakery.java    From The-5zig-Mod with MIT License 5 votes vote down vote up
private void a(Vector3f vector, bgj var1) {
	if (var1 != null) {
		Matrix4f var2 = this.a();
		Vector3f var3 = new Vector3f(0.0F, 0.0F, 0.0F);
		switch (var1.b) {
			case a:
				Matrix4f.rotate(var1.c * 0.017453292F, new Vector3f(1.0F, 0.0F, 0.0F), var2, var2);
				var3.set(0.0F, 1.0F, 1.0F);
				break;
			case b:
				Matrix4f.rotate(var1.c * 0.017453292F, new Vector3f(0.0F, 1.0F, 0.0F), var2, var2);
				var3.set(1.0F, 0.0F, 1.0F);
				break;
			case c:
				Matrix4f.rotate(var1.c * 0.017453292F, new Vector3f(0.0F, 0.0F, 1.0F), var2, var2);
				var3.set(1.0F, 1.0F, 0.0F);
		}

		if (var1.d) {
			if (Math.abs(var1.c) == 22.5F) {
				var3.scale(fieldA);
			} else {
				var3.scale(fieldB);
			}

			Vector3f.add(var3, new Vector3f(1.0F, 1.0F, 1.0F), var3);
		} else {
			var3.set(1.0F, 1.0F, 1.0F);
		}

		this.a(vector, new Vector3f(var1.a), var2, var3);
	}
}
 
Example 16
Source File: GDataPNG.java    From ldparteditor with MIT License 4 votes vote down vote up
public GDataPNG(String text, Vertex offset, BigDecimal angleA, BigDecimal angleB, BigDecimal angleC, Vertex scale, String texturePath, GData1 parent) {
    super(parent);
    this.text = text;
    this.texturePath = texturePath;
    this.texture = new GTexture(TexType.PLANAR, texturePath, null, 0, new Vector3f(), new Vector3f(), new Vector3f(), 0, 0);
    this.offset = offset;
    this.scale = scale;
    this.angleA = angleA;
    this.angleB = angleB;
    this.angleC = angleC;

    {
        Matrix4f tMatrix2 = new Matrix4f();
        tMatrix2.setIdentity();
        tMatrix = tMatrix2.scale(new Vector3f(scale.x, scale.y, scale.z));
    }

    Matrix4f dMatrix = new Matrix4f();
    dMatrix.setIdentity();

    Vector4f direction = new Vector4f(0f, 0f, -1f, 1f);
    // Matrix4f.rotate((float) (angleC.doubleValue() / 180.0 * Math.PI), new Vector3f(0f, 0f, 1f), dMatrix, dMatrix);
    Matrix4f.rotate((float) (angleB.doubleValue() / 180.0 * Math.PI), new Vector3f(1f, 0f, 0f), dMatrix, dMatrix);
    Matrix4f.rotate((float) (angleA.doubleValue() / 180.0 * Math.PI), new Vector3f(0f, 1f, 0f), dMatrix, dMatrix);

    Matrix4f.transform(dMatrix, direction, direction);
    direction.w = 0f;
    direction.normalise();
    direction.w = 1f;
    this.direction = direction;

    dMatrix.setIdentity();

    Matrix4f.rotate((float) (angleC.doubleValue() / 180.0 * Math.PI), new Vector3f(0f, 0f, 1f), dMatrix, dMatrix);
    Matrix4f.rotate((float) (angleB.doubleValue() / 180.0 * Math.PI), new Vector3f(1f, 0f, 0f), dMatrix, dMatrix);
    Matrix4f.rotate((float) (angleA.doubleValue() / 180.0 * Math.PI), new Vector3f(0f, 1f, 0f), dMatrix, dMatrix);

    Matrix4f.mul(dMatrix, tMatrix, tMatrix);

    Vector4f vx = Matrix4f.transform(dMatrix, new Vector4f(offset.x, 0f, 0f, 1f), null);
    Vector4f vy = Matrix4f.transform(dMatrix, new Vector4f(0f, offset.y, 0f, 1f), null);
    Vector4f vz = Matrix4f.transform(dMatrix, new Vector4f(0f, 0f, offset.z, 1f), null);
    tMatrix.m30 = vx.x;
    tMatrix.m31 = vx.y;
    tMatrix.m32 = vx.z;
    tMatrix.m30 += vy.x;
    tMatrix.m31 += vy.y;
    tMatrix.m32 += vy.z;
    tMatrix.m30 += vz.x;
    tMatrix.m31 += vz.y;
    tMatrix.m32 += vz.z;

    matrix = BufferUtils.createFloatBuffer(16);
    tMatrix.store(matrix);

    matrix.position(0);
}
 
Example 17
Source File: SubMesh.java    From tectonicus with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private static Matrix4f createTransform(Rotation horizontalRotation, final float horizontalAngleDeg,
										Rotation verticalRotation, final float verticalAngleDeg)
{
	if (horizontalRotation == Rotation.None && verticalRotation == Rotation.None)
		return null;
	
	float horizontalAngleInRads = horizontalAngleDeg / 360.0f * 2.0f * (float)Math.PI;
	if (horizontalRotation == Rotation.AntiClockwise)
		horizontalAngleInRads *= -1.0f;
	
	float verticalAngleInRads = verticalAngleDeg / 360.0f * 2.0f * (float)Math.PI;
	if (verticalRotation == Rotation.AntiClockwise)
		verticalAngleInRads *= -1.0f;
	
	Matrix4f trans0 = new Matrix4f();
	trans0.translate(new Vector3f(+0.5f, +0.5f, +0.5f));
	
	Matrix4f horizontalRotate = new Matrix4f();
	horizontalRotate.rotate(horizontalAngleInRads, new Vector3f(0, 1, 0));
	
	Matrix4f verticalRotate = new Matrix4f();
	verticalRotate.rotate(verticalAngleInRads, new Vector3f(0, 0, 1));
	
	Matrix4f trans1 = new Matrix4f();
	trans1.translate(new Vector3f(-0.5f, -0.5f, -0.5f));
	
	Matrix4f combinedRotate = new Matrix4f();
	Matrix4f.mul(horizontalRotate, verticalRotate, combinedRotate);
	
	Matrix4f working = new Matrix4f();
	Matrix4f.mul(trans0, combinedRotate, working);
	
	Matrix4f actual = new Matrix4f();
	Matrix4f.mul(working, trans1, actual);
	
	
	
/*	Matrix4f working = new Matrix4f();
	Matrix4f.mul(trans0, rotate, working);
	
	Matrix4f actual = new Matrix4f();
	Matrix4f.mul(working, trans1, actual);
*/
	
	return actual;
}