Repository navigation
Expand file tree
/
Copy pathTransform.java
More file actions
113 lines (79 loc) · 3.44 KB
/
Copy pathTransform.java
File metadata and controls
113 lines (79 loc) · 3.44 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
public class Transform {
private static Camera camera;
// These act as "bounds" in a sense:
private static float zNear;
private static float zFar;
private static float width;
private static float height;
private static float fov;
private Vector3F translation;
private Vector3F rotation;
private Vector3F scaling;
private Vector3F shearFactor;
public Transform(){
translation = new Vector3F(0, 0, 0);
rotation = new Vector3F(0, 0, 0);
scaling = new Vector3F(1, 1, 1); // Default scalars
}
public Matrix4F getTransformation(){
Matrix4F translationMatrix = new Matrix4F().makeTranslation(this.translation.getX(), this.translation.getY(), this.translation.getZ());
Matrix4F rotationMatrix = new Matrix4F().makeRotation(this.rotation.getX(), this.rotation.getY(), this.rotation.getZ());
Matrix4F scalingMatrix = new Matrix4F().makeScaling(this.scaling.getX(), this.scaling.getY(), this.scaling.getZ());
return translationMatrix.mul(rotationMatrix.mul(scalingMatrix));
}
public Matrix4F getProjectedTransformation(){
Matrix4F transformation = getTransformation();
Matrix4F projection = new Matrix4F().makeProjection(fov, width, height, zNear, zFar);
// Deals with rotating the current screen to make it fit with the current camera details
Matrix4F cameraRotationMatrix = new Matrix4F().makeCameraMatrix(camera.getForward(), camera.getUp());
// These are negative because we want the world to move in the opposite direction of the camera's movement.
Matrix4F cameraTranslation = new Matrix4F().makeTranslation(-camera.getPosition().getX(), -camera.getPosition().getY(), -camera.getPosition().getZ());
// Matrix4F shearMatrix = new Matrix4F().makeShearMatrix(new Vector3F(10, 0, 0));
return projection.mul(cameraRotationMatrix.mul(cameraTranslation.mul(transformation)));
}
public static void setProjection(float fov, float width, float height, float zNear, float zFar){
Transform.fov = fov;
Transform.width = width;
Transform.height = height;
Transform.zNear = zNear;
Transform.zFar = zFar;
}
public Vector3F getTranslation() {
return translation;
}
public void setTranslation(Vector3F translation) {
this.translation = translation;
}
public void setTranslation(float x, float y, float z) {
this.translation = new Vector3F(x, y, z);
}
public Vector3F getRotation() {
return rotation;
}
public void setRotation(Vector3F rotation) {
this.rotation = rotation;
}
public void setRotation(float x, float y, float z) {
this.rotation = new Vector3F(x, y, z);
}
public Vector3F getScaling() {
return scaling;
}
public void setScaling(Vector3F scaling) {
this.scaling = scaling;
}
public void setScaling(float x, float y, float z) {
this.scaling = new Vector3F(x, y, z);
}
public Vector3F getShearFactor() { return shearFactor;
}
public void setShearFactor(float x, float y, float z) {
this.shearFactor = new Vector3F(x, y, z);
}
public static Camera getCamera() {
return camera;
}
public static void setCamera(Camera camera) {
Transform.camera = camera;
}
}