diff options
| author | 2024-06-14 20:29:43 -0500 | |
|---|---|---|
| committer | 2024-06-14 20:29:43 -0500 | |
| commit | 2113ae54df2da867f553df3a9ee457c0a3856a33 (patch) | |
| tree | 7d76e281893c155918e9bbf368509155bb4dfd9a /src/main/java/dev/figboot/cuberender/math/Vector3f.java | |
initial commit
Diffstat (limited to 'src/main/java/dev/figboot/cuberender/math/Vector3f.java')
| -rw-r--r-- | src/main/java/dev/figboot/cuberender/math/Vector3f.java | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/main/java/dev/figboot/cuberender/math/Vector3f.java b/src/main/java/dev/figboot/cuberender/math/Vector3f.java new file mode 100644 index 0000000..40720e8 --- /dev/null +++ b/src/main/java/dev/figboot/cuberender/math/Vector3f.java @@ -0,0 +1,42 @@ +package dev.figboot.cuberender.math; + +import lombok.AllArgsConstructor; + +@AllArgsConstructor +public class Vector3f { + public float x, y, z; + + public Vector3f() { + this(0, 0, 0); + } + + public Vector3f(Vector3f vector) { + this.x = vector.x; + this.y = vector.y; + this.z = vector.z; + } + + public float dot(Vector3f vector) { + return this.x * vector.x + this.y * vector.y + this.z * vector.z; + } + + public float lengthSquared() { + return this.x * this.x + this.y * this.y + this.z * this.z; + } + + public float length() { + return (float)Math.sqrt(lengthSquared()); + } + + public Vector3f normalize() { + return normalize(this); + } + + public Vector3f normalize(Vector3f target) { + float len = length(); + target.x /= len; + target.y /= len; + target.z /= len; + return target; + } +} |
