diff options
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; + } +} |
