1
0
Fork 0
This repository has been archived on 2024-04-23. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
Global-Gam-Jam-2017/src/globalgamejam/math/Vector3f.java
2017-01-20 19:38:35 +01:00

110 lines
1.6 KiB
Java

package globalgamejam.math;
import java.util.*;
/**
* Class created by MrDev023 (Florian RICHER) on 14/01/2017
*/
public class Vector3f {
public float x,y,z;
public Vector3f(){
x = 0;
y = 0;
z = 0;
}
public Vector3f(float x,float y,float z){
this.x = x;
this.y = y;
this.z = z;
}
public Vector3f(Vector2f vec,float z){
this(vec.x,vec.y,z);
}
public Vector3f(Vector2f vec){
this(vec.x,vec.y,0);
}
public Vector3f(Vector3f vec){
this(vec.x,vec.y,vec.z);
}
public float getX() {
return x;
}
public void setX(float x) {
this.x = x;
}
public float getY() {
return y;
}
public void setY(float y) {
this.y = y;
}
public float getZ() {
return z;
}
public void setZ(float z) {
this.z = z;
}
public float length(){
return Mathf.sqrt(x * x + y * y + z * z);
}
public Vector3f lookAt(Vector3f d){
Vector3f rot = new Vector3f();
float x1 = d.x - x;
float y1 = d.y - y;
float z1 = d.z - z;
return rot;
}
public Vector3f normalize(){
float length = length();
x /= length;
y /= length;
z /= length;
return this;
}
public Vector3f mul(float m){
x *= m;
y *= m;
z *= m;
return this;
}
public String toString(){
StringJoiner st = new StringJoiner(",","vec3(",")");
st.add("" + x);
st.add("" + y);
st.add("" + z);
return st.toString();
}
public Vector3f toRadians() {
x = Mathf.toRadians(x);
y = Mathf.toRadians(y);
z = Mathf.toRadians(z);
return this;
}
public Vector3f toDegrees() {
x = Mathf.toDegrees(x);
y = Mathf.toDegrees(y);
z = Mathf.toDegrees(z);
return this;
}
}