-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTransformation.java
More file actions
59 lines (50 loc) · 1.89 KB
/
Copy pathTransformation.java
File metadata and controls
59 lines (50 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
ahbejarano
Transformation helper class.
*/
package geetransit.minecraft05.engine;
import org.joml.Matrix4f;
import org.joml.Vector3f;
import org.joml.Quaternionf;
public class Transformation {
private final Matrix4f projectionMatrix;
private final Matrix4f modelViewMatrix;
private final Matrix4f orthoProjectionMatrix;
private final Matrix4f orthoProjModelMatrix;
private final Matrix4f modelMatrix;
public Transformation() {
this.projectionMatrix = new Matrix4f();
this.modelViewMatrix = new Matrix4f();
this.orthoProjectionMatrix = new Matrix4f();
this.orthoProjModelMatrix = new Matrix4f();
this.modelMatrix = new Matrix4f();
}
public Matrix4f getProjectionMatrix(Window window, Camera camera) {
return this.projectionMatrix.setPerspective(
-camera.getFov(), (float) window.getWidth() / window.getHeight(),
camera.getNear(), camera.getFar()
);
}
public Matrix4f getModelMatrix(Item item) {
return this.modelMatrix.translationRotateScale(item.getPosition(), item.getRotation(), item.getScale());
}
public Matrix4f getModelViewMatrix(Item item, Matrix4f viewMatrix) {
return viewMatrix.mulAffine(this.getModelMatrix(item), this.modelViewMatrix);
}
public Matrix4f getOrthoProjectionMatrix(Window window) {
return this.orthoProjectionMatrix.setOrtho2D(0, window.getWidth(), window.getHeight(), 0);
}
// these 2 are different?
public Matrix4f newGetOrthoProjModelMatrix(Item item, Matrix4f orthoMatrix) {
return orthoMatrix.mulOrthoAffine(this.getModelMatrix(item), this.orthoProjModelMatrix);
}
public Matrix4f getOrthoProjModelMatrix(Item item, Matrix4f orthoMatrix) {
return this.orthoProjModelMatrix
.set(orthoMatrix)
.translate(item.getPosition())
.rotateX((float) Math.toRadians(-item.getRotation().x))
.rotateY((float) Math.toRadians(-item.getRotation().y))
.rotateZ((float) Math.toRadians(-item.getRotation().z))
.scale(item.getScale());
}
}