blob: a2608f172857c2786584dac300ab299d6cccbf37 (
plain) (
blame)
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
|
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 = this.x / len;
target.y = this.y / len;
target.z = this.z / len;
return target;
}
}
|