If you think the Android project fun-gl listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package com.jcxavier.android.opengl.math;
//fromwww.java2s.com/**
* Created on 11/03/2014.
*
* @author Joo Xavier <jcxavier@jcxavier.com>
*/publicfinalclass Vector3 implements IVector<Vector3> {
publicfloat x;
publicfloat y;
publicfloat z;
public Vector3() {
x = 0;
y = 0;
z = 0;
}
public Vector3(finalfloat x, finalfloat y, finalfloat z) {
set(x, y, z);
}
public Vector3(final Vector3 v) {
set(v);
}
@Override
public Vector3 set(final Vector3 v) {
x = v.x;
y = v.y;
z = v.z;
returnthis;
}
public Vector3 set(finalfloat x, finalfloat y, finalfloat z) {
this.x = x;
this.y = y;
this.z = z;
returnthis;
}
@Override
public Vector3 add(final Vector3 v) {
return set(x + v.x, y + v.y, z + v.z);
}
@Override
public Vector3 sub(final Vector3 v) {
return set(x - v.x, y - v.y, z - v.z);
}
@Override
public Vector3 negate() {
return set(-x, -y, -z);
}
/**
* Constructs a new vector containing the sum of two given vectors.
*
* @param vectorLeft the left-hand side vector
* @param vectorRight the right-hand side vector
* @return a new vector with the result of the sum
*/publicstatic Vector3 add(Vector3 vectorLeft, Vector3 vectorRight) {
Vector3 v = new Vector3(vectorLeft);
v.add(vectorRight);
return v;
}
/**
* Constructs a new vector containing the subtraction of two given vectors.
*
* @param vectorLeft the left-hand side vector
* @param vectorRight the right-hand side vector
* @return a new vector with the result of the subtraction
*/publicstatic Vector3 subtract(Vector3 vectorLeft, Vector3 vectorRight) {
Vector3 v = new Vector3(vectorLeft);
v.sub(vectorRight);
return v;
}
/**
* Constructs a new negated vector (i.e. with all its components negated).
*
* @param v the original vector
* @return a new vector
*/publicstatic Vector3 negate(final Vector3 v) {
returnnew Vector3(-v.x, -v.y, -v.z);
}
}