aboutsummaryrefslogtreecommitdiffstats
path: root/src/jogl/classes/com/jogamp/opengl
diff options
context:
space:
mode:
Diffstat (limited to 'src/jogl/classes/com/jogamp/opengl')
-rw-r--r--src/jogl/classes/com/jogamp/opengl/math/Quaternion.java54
-rw-r--r--src/jogl/classes/com/jogamp/opengl/math/VectorUtil.java52
2 files changed, 53 insertions, 53 deletions
diff --git a/src/jogl/classes/com/jogamp/opengl/math/Quaternion.java b/src/jogl/classes/com/jogamp/opengl/math/Quaternion.java
index 409176101..d5ffe2da4 100644
--- a/src/jogl/classes/com/jogamp/opengl/math/Quaternion.java
+++ b/src/jogl/classes/com/jogamp/opengl/math/Quaternion.java
@@ -55,8 +55,8 @@ public class Quaternion {
* @param vector2
*/
public Quaternion(float[] vector1, float[] vector2) {
- float theta = FloatUtil.acos(VectorUtil.dot(vector1, vector2));
- float[] cross = VectorUtil.cross(vector1, vector2);
+ final float theta = FloatUtil.acos(VectorUtil.dot(vector1, vector2));
+ final float[] cross = VectorUtil.cross(vector1, vector2);
fromAxis(cross, theta);
}
@@ -77,9 +77,9 @@ public class Quaternion {
* @param angle rotation angle (rads)
*/
public void fromAxis(float[] vector, float angle) {
- float halfangle = angle * 0.5f;
- float sin = FloatUtil.sin(halfangle);
- float[] nv = VectorUtil.normalize(vector);
+ final float halfangle = angle * 0.5f;
+ final float sin = FloatUtil.sin(halfangle);
+ final float[] nv = VectorUtil.normalize(vector);
x = (nv[0] * sin);
y = (nv[1] * sin);
z = (nv[2] * sin);
@@ -92,8 +92,8 @@ public class Quaternion {
* @return new float[4] with ,theta,Rx,Ry,Rz
*/
public float[] toAxis() {
- float[] vec = new float[4];
- float scale = FloatUtil.sqrt(x * x + y * y + z * z);
+ final float[] vec = new float[4];
+ final float scale = FloatUtil.sqrt(x * x + y * y + z * z);
vec[0] = FloatUtil.acos(w) * 2.0f;
vec[1] = x / scale;
vec[2] = y / scale;
@@ -172,11 +172,11 @@ public class Quaternion {
* @param q a quaternion to multiply with
*/
public void mult(Quaternion q) {
- float w1 = w * q.w - x * q.x - y * q.y - z * q.z;
+ final float w1 = w * q.w - x * q.x - y * q.y - z * q.z;
- float x1 = w * q.x + x * q.w + y * q.z - z * q.y;
- float y1 = w * q.y - x * q.z + y * q.w + z * q.x;
- float z1 = w * q.z + x * q.y - y * q.x + z * q.w;
+ final float x1 = w * q.x + x * q.w + y * q.z - z * q.y;
+ final float y1 = w * q.y - x * q.z + y * q.w + z * q.x;
+ final float z1 = w * q.z + x * q.y - y * q.x + z * q.w;
w = w1;
x = x1;
@@ -202,11 +202,11 @@ public class Quaternion {
* @return rotated vector
*/
public float[] mult(float[] vector) {
- // TODO : optimalize
- float[] res = new float[3];
- Quaternion a = new Quaternion(vector[0], vector[1], vector[2], 0.0f);
- Quaternion b = new Quaternion(this);
- Quaternion c = new Quaternion(this);
+ // TODO : optimize
+ final float[] res = new float[3];
+ final Quaternion a = new Quaternion(vector[0], vector[1], vector[2], 0.0f);
+ final Quaternion b = new Quaternion(this);
+ final Quaternion c = new Quaternion(this);
b.inverse();
a.mult(b);
c.mult(a);
@@ -220,11 +220,11 @@ public class Quaternion {
* Normalize a quaternion required if to be used as a rotational quaternion
*/
public void normalize() {
- float norme = (float) FloatUtil.sqrt(w * w + x * x + y * y + z * z);
+ final float norme = (float) FloatUtil.sqrt(w * w + x * x + y * y + z * z);
if (norme == 0.0f) {
setIdentity();
} else {
- float recip = 1.0f / norme;
+ final float recip = 1.0f / norme;
w *= recip;
x *= recip;
@@ -237,9 +237,9 @@ public class Quaternion {
* Invert the quaternion If rotational, will produce a the inverse rotation
*/
public void inverse() {
- float norm = w * w + x * x + y * y + z * z;
+ final float norm = w * w + x * x + y * y + z * z;
- float recip = 1.0f / norm;
+ final float recip = 1.0f / norm;
w *= recip;
x = -1 * x * recip;
@@ -254,7 +254,7 @@ public class Quaternion {
* @return new float[16] column matrix 4x4
*/
public float[] toMatrix() {
- float[] matrix = new float[16];
+ final float[] matrix = new float[16];
matrix[0] = 1.0f - 2 * y * y - 2 * z * z;
matrix[1] = 2 * x * y + 2 * w * z;
matrix[2] = 2 * x * z - 2 * w * y;
@@ -365,28 +365,28 @@ public class Quaternion {
* @param m 3x3 column matrix
*/
public void setFromMatrix(float[] m) {
- float T = m[0] + m[4] + m[8] + 1;
+ final float T = m[0] + m[4] + m[8] + 1;
if (T > 0) {
- float S = 0.5f / (float) FloatUtil.sqrt(T);
+ final float S = 0.5f / (float) FloatUtil.sqrt(T);
w = 0.25f / S;
x = (m[5] - m[7]) * S;
y = (m[6] - m[2]) * S;
z = (m[1] - m[3]) * S;
} else {
if ((m[0] > m[4]) & (m[0] > m[8])) {
- float S = FloatUtil.sqrt(1.0f + m[0] - m[4] - m[8]) * 2f; // S=4*qx
+ final float S = FloatUtil.sqrt(1.0f + m[0] - m[4] - m[8]) * 2f; // S=4*qx
w = (m[7] - m[5]) / S;
x = 0.25f * S;
y = (m[3] + m[1]) / S;
z = (m[6] + m[2]) / S;
} else if (m[4] > m[8]) {
- float S = FloatUtil.sqrt(1.0f + m[4] - m[0] - m[8]) * 2f; // S=4*qy
+ final float S = FloatUtil.sqrt(1.0f + m[4] - m[0] - m[8]) * 2f; // S=4*qy
w = (m[6] - m[2]) / S;
x = (m[3] + m[1]) / S;
y = 0.25f * S;
z = (m[7] + m[5]) / S;
} else {
- float S = FloatUtil.sqrt(1.0f + m[8] - m[0] - m[4]) * 2f; // S=4*qz
+ final float S = FloatUtil.sqrt(1.0f + m[8] - m[0] - m[4]) * 2f; // S=4*qz
w = (m[3] - m[1]) / S;
x = (m[6] + m[2]) / S;
y = (m[7] + m[5]) / S;
@@ -403,7 +403,7 @@ public class Quaternion {
* @return true if representing a rotational matrix, false otherwise
*/
public boolean isRotationMatrix(float[] m) {
- double epsilon = 0.01; // margin to allow for rounding errors
+ final double epsilon = 0.01; // margin to allow for rounding errors
if (FloatUtil.abs(m[0] * m[3] + m[3] * m[4] + m[6] * m[7]) > epsilon)
return false;
if (FloatUtil.abs(m[0] * m[2] + m[3] * m[5] + m[6] * m[8]) > epsilon)
diff --git a/src/jogl/classes/com/jogamp/opengl/math/VectorUtil.java b/src/jogl/classes/com/jogamp/opengl/math/VectorUtil.java
index 5a75d016a..0033afeaa 100644
--- a/src/jogl/classes/com/jogamp/opengl/math/VectorUtil.java
+++ b/src/jogl/classes/com/jogamp/opengl/math/VectorUtil.java
@@ -292,21 +292,21 @@ public class VectorUtil {
*/
public static boolean vertexInTriangle(float[] a, float[] b, float[] c, float[] p){
// Compute vectors
- float[] ac = computeVector(a, c); //v0
- float[] ab = computeVector(a, b); //v1
- float[] ap = computeVector(a, p); //v2
+ final float[] ac = computeVector(a, c); //v0
+ final float[] ab = computeVector(a, b); //v1
+ final float[] ap = computeVector(a, p); //v2
// Compute dot products
- float dot00 = dot(ac, ac);
- float dot01 = dot(ac, ab);
- float dot02 = dot(ac, ap);
- float dot11 = dot(ab, ab);
- float dot12 = dot(ab, ap);
+ final float dot00 = dot(ac, ac);
+ final float dot01 = dot(ac, ab);
+ final float dot02 = dot(ac, ap);
+ final float dot11 = dot(ab, ab);
+ final float dot12 = dot(ab, ap);
// Compute barycentric coordinates
- float invDenom = 1 / (dot00 * dot11 - dot01 * dot01);
- float u = (dot11 * dot02 - dot01 * dot12) * invDenom;
- float v = (dot00 * dot12 - dot01 * dot02) * invDenom;
+ final float invDenom = 1 / (dot00 * dot11 - dot01 * dot01);
+ final float u = (dot11 * dot02 - dot01 * dot12) * invDenom;
+ final float v = (dot00 * dot12 - dot01 * dot02) * invDenom;
// Check if point is in triangle
return (u >= 0) && (v >= 0) && (u + v < 1);
@@ -337,12 +337,12 @@ public class VectorUtil {
* @return positive area if ccw else negative area value
*/
public static float area(ArrayList<? extends Vert2fImmutable> vertices) {
- int n = vertices.size();
+ final int n = vertices.size();
float area = 0.0f;
for (int p = n - 1, q = 0; q < n; p = q++)
{
- float[] pCoord = vertices.get(p).getCoord();
- float[] qCoord = vertices.get(q).getCoord();
+ final float[] pCoord = vertices.get(p).getCoord();
+ final float[] qCoord = vertices.get(q).getCoord();
area += pCoord[0] * qCoord[1] - qCoord[0] * pCoord[1];
}
return area;
@@ -366,18 +366,18 @@ public class VectorUtil {
* returns null
*/
public static float[] seg2SegIntersection(Vert2fImmutable a, Vert2fImmutable b, Vert2fImmutable c, Vert2fImmutable d) {
- float determinant = (a.getX()-b.getX())*(c.getY()-d.getY()) - (a.getY()-b.getY())*(c.getX()-d.getX());
+ final float determinant = (a.getX()-b.getX())*(c.getY()-d.getY()) - (a.getY()-b.getY())*(c.getX()-d.getX());
if (determinant == 0)
return null;
- float alpha = (a.getX()*b.getY()-a.getY()*b.getX());
- float beta = (c.getX()*d.getY()-c.getY()*d.getY());
- float xi = ((c.getX()-d.getX())*alpha-(a.getX()-b.getX())*beta)/determinant;
- float yi = ((c.getY()-d.getY())*alpha-(a.getY()-b.getY())*beta)/determinant;
+ final float alpha = (a.getX()*b.getY()-a.getY()*b.getX());
+ final float beta = (c.getX()*d.getY()-c.getY()*d.getY());
+ final float xi = ((c.getX()-d.getX())*alpha-(a.getX()-b.getX())*beta)/determinant;
+ final float yi = ((c.getY()-d.getY())*alpha-(a.getY()-b.getY())*beta)/determinant;
- float gamma = (xi - a.getX())/(b.getX() - a.getX());
- float gamma1 = (xi - c.getX())/(d.getX() - c.getX());
+ final float gamma = (xi - a.getX())/(b.getX() - a.getX());
+ final float gamma1 = (xi - c.getX())/(d.getX() - c.getX());
if(gamma <= 0 || gamma >= 1) return null;
if(gamma1 <= 0 || gamma1 >= 1) return null;
@@ -393,15 +393,15 @@ public class VectorUtil {
* returns null
*/
public static float[] line2lineIntersection(Vert2fImmutable a, Vert2fImmutable b, Vert2fImmutable c, Vert2fImmutable d) {
- float determinant = (a.getX()-b.getX())*(c.getY()-d.getY()) - (a.getY()-b.getY())*(c.getX()-d.getX());
+ final float determinant = (a.getX()-b.getX())*(c.getY()-d.getY()) - (a.getY()-b.getY())*(c.getX()-d.getX());
if (determinant == 0)
return null;
- float alpha = (a.getX()*b.getY()-a.getY()*b.getX());
- float beta = (c.getX()*d.getY()-c.getY()*d.getY());
- float xi = ((c.getX()-d.getX())*alpha-(a.getX()-b.getX())*beta)/determinant;
- float yi = ((c.getY()-d.getY())*alpha-(a.getY()-b.getY())*beta)/determinant;
+ final float alpha = (a.getX()*b.getY()-a.getY()*b.getX());
+ final float beta = (c.getX()*d.getY()-c.getY()*d.getY());
+ final float xi = ((c.getX()-d.getX())*alpha-(a.getX()-b.getX())*beta)/determinant;
+ final float yi = ((c.getY()-d.getY())*alpha-(a.getY()-b.getY())*beta)/determinant;
return new float[]{xi,yi,0};
}