package VectorMath;
import java.lang.Math;
/**
*
* @author Jonathan Coleman
*/
public class Vector3
{
private float[] data = new float[3];
public Vector3(){}
public Vector3(float x, float y, float z){
data[0] = x;
data[1] = y;
data[2] = z;
}
public Vector3(Vector3 v){
data[0] = v.x();
data[1] = v.y();
data[2] = v.z();
}
//Operations
public void add(Vector3 v){
data[0] += v.x();
data[1] += v.y();
data[2] += v.z();
}
public void subtract(Vector3 v){
data[0] -= v.x();
data[1] -= v.y();
data[2] -= v.z();
}
public void multiplyScalar(float scalar){
data[0] *= scalar;
data[1] *= scalar;
data[2] *= scalar;
}
public void divideScalar(float scalar){
data[0] /= scalar;
data[1] /= scalar;
data[2] /= scalar;
}
public Vector3 normalize(){
float length;
length = (float) Math.sqrt((data[0]*data[0]) +
(data[1]*data[1]) + (data[2]*data[2]));
Vector3 normalized = new Vector3(x()/length, y()/length, z()/length);
return normalized;
}
//getters
public float x()
{
return data[0];
}
public float y()
{
return data[1];
}
public float z()
{
return data[2];
}
}