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
|
package net.tylermurphy.Minecraft.Util;
import org.joml.Vector2f;
import org.joml.Vector3f;
import org.joml.Matrix4f;
import net.tylermurphy.Minecraft.Scene.Camera;
public class Maths {
public static Matrix4f createTransformationMatrix(Vector2f translation, Vector2f scale) {
Matrix4f matrix = new Matrix4f();
matrix.identity();
matrix.translate(translation.x, translation.y, 0);
matrix.scale(new Vector3f(scale.x, scale.y, 1f));
return matrix;
}
public static Matrix4f createTransformationMatrix(Vector3f translation, float rx, float ry, float rz, float scale) {
Matrix4f matrix = new Matrix4f();
matrix.identity();
matrix.translate(translation);
matrix.rotate((float) Math.toRadians(rx), new Vector3f(1,0,0));
matrix.rotate((float) Math.toRadians(ry), new Vector3f(0,1,0));
matrix.rotate((float) Math.toRadians(rz), new Vector3f(0,0,1));
matrix.scale(scale);
return matrix;
}
public static Matrix4f createViewMatrix(Camera camera) {
Matrix4f viewMatrix = new Matrix4f();
viewMatrix.identity();
viewMatrix.rotate((float) Math.toRadians(camera.getPitch()), new Vector3f(1, 0, 0));
viewMatrix.rotate((float) Math.toRadians(camera.getYaw()), new Vector3f(0, 1, 0));
Vector3f cameraPos = camera.getPosition();
Vector3f negativeCameraPos = new Vector3f(-cameraPos.x,-cameraPos.y,-cameraPos.z);
viewMatrix.translate(negativeCameraPos);
return viewMatrix;
}
public static float barryCentric(Vector3f p1, Vector3f p2, Vector3f p3, Vector2f pos) {
float det = (p2.z - p3.z) * (p1.x - p3.x) + (p3.x - p2.x) * (p1.z - p3.z);
float l1 = ((p2.z - p3.z) * (pos.x - p3.x) + (p3.x - p2.x) * (pos.y - p3.z)) / det;
float l2 = ((p3.z - p1.z) * (pos.x - p3.x) + (p1.x - p3.x) * (pos.y - p3.z)) / det;
float l3 = 1.0f - l1 - l2;
return l1 * p1.y + l2 * p2.y + l3 * p3.y;
}
public static float getDistance(float x1, float z1, float x2, float z2) {
float x = (x2-x1) * (x2-x1);
float z = (z2-z1) * (z2-z1);
float answer = (float) Math.sqrt(x + z);
System.out.println(answer);
return answer;
}
public static float getDistance(Vector3f vec1, Vector3f vec2) {
float x = (vec1.x-vec2.x) * (vec1.x-vec2.x);
float z = (vec1.z-vec2.z) * (vec1.z-vec2.z);
float answer = (float) Math.sqrt(x + z);
return answer;
}
}
|