diff options
Diffstat (limited to 'src/jogl/classes/com')
7 files changed, 135 insertions, 41 deletions
diff --git a/src/jogl/classes/com/jogamp/graph/curve/Region.java b/src/jogl/classes/com/jogamp/graph/curve/Region.java index bb0ed09d1..15a0d6bff 100644 --- a/src/jogl/classes/com/jogamp/graph/curve/Region.java +++ b/src/jogl/classes/com/jogamp/graph/curve/Region.java @@ -48,7 +48,7 @@ public abstract class Region { /** Debug flag for region impl (graph.curve) */ public static final boolean DEBUG = Debug.debug("graph.curve"); - public static final boolean DEBUG_INSTANCE = Debug.debug("graph.curve.instance"); + public static final boolean DEBUG_INSTANCE = Debug.debug("graph.curve.Instance"); /** * Rendering-Mode bit for {@link Region#getRenderModes() Region} and {@link com.jogamp.graph.curve.opengl.RegionRenderer#getRenderModes() RegionRenderer}. diff --git a/src/jogl/classes/com/jogamp/graph/curve/opengl/RegionRenderer.java b/src/jogl/classes/com/jogamp/graph/curve/opengl/RegionRenderer.java index bc9052dbe..8233d4262 100644 --- a/src/jogl/classes/com/jogamp/graph/curve/opengl/RegionRenderer.java +++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/RegionRenderer.java @@ -121,20 +121,22 @@ public abstract class RegionRenderer { return new jogamp.graph.curve.opengl.RegionRendererImpl01(rs, renderModes, enableCallback, disableCallback); } - protected final int renderModes; - protected final RenderState rs; + private final int renderModes; + private final RenderState rs; - protected final GLCallback enableCallback; - protected final GLCallback disableCallback; + private final GLCallback enableCallback; + private final GLCallback disableCallback; - protected int vp_width; - protected int vp_height; - protected boolean initialized; + private int vp_width; + private int vp_height; + private boolean initialized; private boolean vboSupported = false; public final boolean isInitialized() { return initialized; } + /** Return width of current viewport */ public final int getWidth() { return vp_width; } + /** Return height of current viewport */ public final int getHeight() { return vp_height; } public final float getWeight() { return rs.getWeight().floatValue(); } diff --git a/src/jogl/classes/com/jogamp/graph/geom/SVertex.java b/src/jogl/classes/com/jogamp/graph/geom/SVertex.java index beac908d4..d13607d71 100644 --- a/src/jogl/classes/com/jogamp/graph/geom/SVertex.java +++ b/src/jogl/classes/com/jogamp/graph/geom/SVertex.java @@ -36,9 +36,9 @@ import com.jogamp.opengl.math.VectorUtil; */ public class SVertex implements Vertex { private int id; - protected final float[] coord = new float[3]; protected boolean onCurve; - private final float[] texCoord = new float[2]; + protected final float[] coord = new float[3]; + private final float[] texCoord = new float[3]; static final Factory factory = new Factory(); @@ -78,13 +78,13 @@ public class SVertex implements Vertex { this.id = src.getId(); System.arraycopy(src.getCoord(), 0, coord, 0, 3); setOnCurve(src.isOnCurve()); - System.arraycopy(src.getTexCoord(), 0, texCoord, 0, 2); + System.arraycopy(src.getTexCoord(), 0, texCoord, 0, 3); } public SVertex(final int id, final boolean onCurve, final float[] texCoordsBuffer) { this.id = id; this.onCurve = onCurve; - System.arraycopy(texCoordsBuffer, 0, texCoord, 0, 2); + System.arraycopy(texCoordsBuffer, 0, texCoord, 0, 3); } public SVertex(final float x, final float y, final float z, final boolean onCurve) { @@ -102,7 +102,7 @@ public class SVertex implements Vertex { public SVertex(float[] coordsBuffer, float[] texCoordsBuffer, boolean onCurve) { this.id = Integer.MAX_VALUE; System.arraycopy(coordsBuffer, 0, coord, 0, 3); - System.arraycopy(texCoordsBuffer, 0, texCoord, 0, 2); + System.arraycopy(texCoordsBuffer, 0, texCoord, 0, 3); setOnCurve(onCurve); } @@ -189,7 +189,7 @@ public class SVertex implements Vertex { final Vertex v = (Vertex) obj; return this == v || isOnCurve() == v.isOnCurve() && - VectorUtil.isVec2Equal(getTexCoord(), 0, v.getTexCoord(), 0, FloatUtil.EPSILON) && + VectorUtil.isVec3Equal(getTexCoord(), 0, v.getTexCoord(), 0, FloatUtil.EPSILON) && VectorUtil.isVec3Equal(getCoord(), 0, v.getCoord(), 0, FloatUtil.EPSILON) ; } @@ -199,9 +199,10 @@ public class SVertex implements Vertex { } @Override - public final void setTexCoord(float s, float t) { + public final void setTexCoord(float s, float t, float p) { texCoord[0] = s; texCoord[1] = t; + texCoord[2] = p; } @Override @@ -221,6 +222,6 @@ public class SVertex implements Vertex { public String toString() { return "[ID: " + id + ", onCurve: " + onCurve + ": p " + coord[0] + ", " + coord[1] + ", " + coord[2] + - ", t " + texCoord[0] + ", " + texCoord[1] + "]"; + ", t " + texCoord[0] + ", " + texCoord[1] + ", " + texCoord[2] + "]"; } } diff --git a/src/jogl/classes/com/jogamp/graph/geom/Triangle.java b/src/jogl/classes/com/jogamp/graph/geom/Triangle.java index de629dfc4..33e53f3ed 100644 --- a/src/jogl/classes/com/jogamp/graph/geom/Triangle.java +++ b/src/jogl/classes/com/jogamp/graph/geom/Triangle.java @@ -27,6 +27,8 @@ */ package com.jogamp.graph.geom; +import com.jogamp.opengl.math.VectorUtil; + import jogamp.graph.geom.plane.AffineTransform; public class Triangle { @@ -35,31 +37,29 @@ public class Triangle { private boolean[] boundaryVertices = null; private int id; - public Triangle(Vertex v1, Vertex v2, Vertex v3) { + public Triangle(final Vertex v1, final Vertex v2, final Vertex v3, final boolean[] boundaryVertices) { id = Integer.MAX_VALUE; vertices[0] = v1; vertices[1] = v2; vertices[2] = v3; + this.boundaryVertices = boundaryVertices; } - public Triangle(Triangle src) { + public Triangle(final Triangle src) { id = src.id; vertices[0] = src.vertices[0].clone(); vertices[1] = src.vertices[1].clone(); vertices[2] = src.vertices[2].clone(); System.arraycopy(src.boundaryEdges, 0, boundaryEdges, 0, 3); - boundaryVertices = src.boundaryVertices; + boundaryVertices = new boolean[3]; + System.arraycopy(src.boundaryVertices, 0, boundaryVertices, 0, 3); } private Triangle(final int id, final boolean[] boundaryEdges, final boolean[] boundaryVertices){ this.id = id; System.arraycopy(boundaryEdges, 0, this.boundaryEdges, 0, 3); - this.boundaryVertices = boundaryVertices; - /** - if( null != boundaryVertices ) { - this.boundaryVertices = new boolean[3]; - System.arraycopy(boundaryVertices, 0, this.boundaryVertices, 0, 3); - } */ + this.boundaryVertices = new boolean[3]; + System.arraycopy(boundaryVertices, 0, this.boundaryVertices, 0, 3); } /** @@ -73,6 +73,22 @@ public class Triangle { return tri; } + /** + * Returns true if all vertices are on-curve, otherwise false. + */ + public final boolean isOnCurve() { + return vertices[0].isOnCurve() && vertices[1].isOnCurve() && vertices[2].isOnCurve(); + } + + /** + * Returns true if all vertices are lines, i.e. zero tex-coord, otherwise false. + */ + public final boolean isLine() { + return VectorUtil.isVec2Zero(vertices[0].getTexCoord(), 0) && + VectorUtil.isVec2Zero(vertices[1].getTexCoord(), 0) && + VectorUtil.isVec2Zero(vertices[2].getTexCoord(), 0) ; + } + public int getId() { return id; } @@ -108,6 +124,9 @@ public class Triangle { @Override public String toString() { - return "Tri ID: " + id + "\n\t" + vertices[0] + "\n\t" + vertices[1] + "\n\t" + vertices[2]; + return "Tri ID: " + id + ", onCurve "+isOnCurve()+"\n\t" + + vertices[0] + ", bound "+boundaryVertices[0]+"\n\t" + + vertices[1] + ", bound "+boundaryVertices[1]+"\n\t" + + vertices[2] + ", bound "+boundaryVertices[2]; } } diff --git a/src/jogl/classes/com/jogamp/graph/geom/Vertex.java b/src/jogl/classes/com/jogamp/graph/geom/Vertex.java index fc9590ae7..e9c8dd193 100644 --- a/src/jogl/classes/com/jogamp/graph/geom/Vertex.java +++ b/src/jogl/classes/com/jogamp/graph/geom/Vertex.java @@ -69,7 +69,7 @@ public interface Vertex extends Vert3fImmutable, Cloneable { float[] getTexCoord(); - void setTexCoord(float s, float t); + void setTexCoord(float s, float t, float p); /** * @see System#arraycopy(Object, int, Object, int, int) for thrown IndexOutOfBoundsException diff --git a/src/jogl/classes/com/jogamp/opengl/math/Quaternion.java b/src/jogl/classes/com/jogamp/opengl/math/Quaternion.java index cc2a3a1cc..345224788 100644 --- a/src/jogl/classes/com/jogamp/opengl/math/Quaternion.java +++ b/src/jogl/classes/com/jogamp/opengl/math/Quaternion.java @@ -649,7 +649,7 @@ public class Quaternion { * @return this quaternion for chaining. */ public final Quaternion setFromVectors(final float[] v1, final float[] v2, final float[] tmpPivotVec, final float[] tmpNormalVec) { - final float factor = VectorUtil.vec3Length(v1) * VectorUtil.vec3Length(v2); + final float factor = VectorUtil.vec3Norm(v1) * VectorUtil.vec3Norm(v2); if ( FloatUtil.isZero(factor, FloatUtil.EPSILON ) ) { return setIdentity(); } else { @@ -658,7 +658,7 @@ public class Quaternion { VectorUtil.crossVec3(tmpPivotVec, v1, v2); - if ( dot < 0.0f && FloatUtil.isZero( VectorUtil.vec3Length(tmpPivotVec), FloatUtil.EPSILON ) ) { + if ( dot < 0.0f && FloatUtil.isZero( VectorUtil.vec3Norm(tmpPivotVec), FloatUtil.EPSILON ) ) { // Vectors parallel and opposite direction, therefore a rotation of 180 degrees about any vector // perpendicular to this vector will rotate vector a onto vector b. // @@ -704,7 +704,7 @@ public class Quaternion { * @return this quaternion for chaining. */ public final Quaternion setFromNormalVectors(final float[] v1, final float[] v2, final float[] tmpPivotVec) { - final float factor = VectorUtil.vec3Length(v1) * VectorUtil.vec3Length(v2); + final float factor = VectorUtil.vec3Norm(v1) * VectorUtil.vec3Norm(v2); if ( FloatUtil.isZero(factor, FloatUtil.EPSILON ) ) { return setIdentity(); } else { @@ -713,7 +713,7 @@ public class Quaternion { VectorUtil.crossVec3(tmpPivotVec, v1, v2); - if ( dot < 0.0f && FloatUtil.isZero( VectorUtil.vec3Length(tmpPivotVec), FloatUtil.EPSILON ) ) { + if ( dot < 0.0f && FloatUtil.isZero( VectorUtil.vec3Norm(tmpPivotVec), FloatUtil.EPSILON ) ) { // Vectors parallel and opposite direction, therefore a rotation of 180 degrees about any vector // perpendicular to this vector will rotate vector a onto vector b. // diff --git a/src/jogl/classes/com/jogamp/opengl/math/VectorUtil.java b/src/jogl/classes/com/jogamp/opengl/math/VectorUtil.java index 9c6da7e24..7fa6f2d60 100644 --- a/src/jogl/classes/com/jogamp/opengl/math/VectorUtil.java +++ b/src/jogl/classes/com/jogamp/opengl/math/VectorUtil.java @@ -45,6 +45,20 @@ public class VectorUtil { } /** + * Copies a vector of length 2 + * @param dst output vector + * @param dstOffset offset of dst in array + * @param src input vector + * @param srcOffset offset of src in array + * @return copied output vector for chaining + */ + public static float[] copyVec2(final float[] dst, int dstOffset, final float[] src, int srcOffset) + { + System.arraycopy(src, srcOffset, dst, dstOffset, 2); + return dst; + } + + /** * Copies a vector of length 3 * @param dst output vector * @param dstOffset offset of dst in array @@ -121,6 +135,13 @@ public class VectorUtil { /** * Return true if vector is zero, no {@link FloatUtil#EPSILON} is taken into consideration. */ + public static boolean isVec2Zero(final float[] vec, final int vecOffset) { + return 0f == vec[0+vecOffset] && 0f == vec[1+vecOffset]; + } + + /** + * Return true if vector is zero, no {@link FloatUtil#EPSILON} is taken into consideration. + */ public static boolean isVec3Zero(final float[] vec, final int vecOffset) { return 0f == vec[0+vecOffset] && 0f == vec[1+vecOffset] && 0f == vec[2+vecOffset]; } @@ -131,11 +152,32 @@ public class VectorUtil { * Implementation uses {@link FloatUtil#isZero(float, float)}, see API doc for details. * </p> */ + public static boolean isVec2Zero(final float[] vec, final int vecOffset, final float epsilon) { + return isZero(vec[0+vecOffset], vec[1+vecOffset], epsilon); + } + + /** + * Return true if vector is zero, i.e. it's absolute components < <code>epsilon</code>. + * <p> + * Implementation uses {@link FloatUtil#isZero(float, float)}, see API doc for details. + * </p> + */ public static boolean isVec3Zero(final float[] vec, final int vecOffset, final float epsilon) { return isZero(vec[0+vecOffset], vec[1+vecOffset], vec[2+vecOffset], epsilon); } /** + * Return true if all two vector components are zero, i.e. it's their absolute value < <code>epsilon</code>. + * <p> + * Implementation uses {@link FloatUtil#isZero(float, float)}, see API doc for details. + * </p> + */ + public static boolean isZero(final float x, final float y, final float epsilon) { + return FloatUtil.isZero(x, epsilon) && + FloatUtil.isZero(y, epsilon) ; + } + + /** * Return true if all three vector components are zero, i.e. it's their absolute value < <code>epsilon</code>. * <p> * Implementation uses {@link FloatUtil#isZero(float, float)}, see API doc for details. @@ -174,22 +216,39 @@ public class VectorUtil { * @param vec2 vector 2 * @return the dot product as float */ - public static float vec3Dot(final float[] vec1, final float[] vec2) - { + public static float vec3Dot(final float[] vec1, final float[] vec2) { return vec1[0]*vec2[0] + vec1[1]*vec2[1] + vec1[2]*vec2[2]; } /** - * Compute the squared length of a vector, a.k.a the squared <i>norm</i> + * Compute the cos of the angle between to vectors + * @param vec1 vector 1 + * @param vec2 vector 2 + */ + public static float vec3CosAngle(final float[] vec1, final float[] vec2) { + return vec3Dot(vec1, vec2) / ( vec3Norm(vec1) * vec3Norm(vec2) ) ; + } + + /** + * Compute the angle between to vectors in radians + * @param vec1 vector 1 + * @param vec2 vector 2 + */ + public static float vec3Angle(final float[] vec1, final float[] vec2) { + return FloatUtil.acos(vec3CosAngle(vec1, vec2)); + } + + /** + * Compute the squared length of a vector, a.k.a the squared <i>norm</i> or squared <i>magnitude</i> */ - public static float vec3LengthSquare(final float[] vec) { + public static float vec3NormSquare(final float[] vec) { return vec[0]*vec[0] + vec[1]*vec[1] + vec[2]*vec[2]; } /** - * Compute the length of a vector, a.k.a the <i>norm</i> + * Compute the length of a vector, a.k.a the <i>norm</i> or <i>magnitude</i> */ - public static float vec3Length(final float[] vec) { - return FloatUtil.sqrt(vec3LengthSquare(vec)); + public static float vec3Norm(final float[] vec) { + return FloatUtil.sqrt(vec3NormSquare(vec)); } /** @@ -200,7 +259,7 @@ public class VectorUtil { * @return result vector for chaining */ public static float[] normalizeVec3(final float[] result, final float[] vector) { - final float lengthSq = vec3LengthSquare(vector); + final float lengthSq = vec3NormSquare(vector); if ( FloatUtil.isZero(lengthSq, FloatUtil.EPSILON) ) { result[0] = 0f; result[1] = 0f; @@ -220,7 +279,7 @@ public class VectorUtil { * @return normalized output vector */ public static float[] normalizeVec3(final float[] vector) { - final float lengthSq = vec3LengthSquare(vector); + final float lengthSq = vec3NormSquare(vector); if ( FloatUtil.isZero(lengthSq, FloatUtil.EPSILON) ) { vector[0] = 0f; vector[1] = 0f; @@ -279,6 +338,19 @@ public class VectorUtil { /** * Subtracts two vectors, result = v1 - v2 + * @param result float[2] result vector, may be either v1 or v2 (in-place) + * @param v1 vector 1 + * @param v2 vector 2 + * @return result vector for chaining + */ + public static float[] subVec2(final float[] result, final float[] v1, final float[] v2) { + result[0] = v1[0] - v2[0]; + result[1] = v1[1] - v2[1]; + return result; + } + + /** + * Subtracts two vectors, result = v1 - v2 * @param result float[3] result vector, may be either v1 or v2 (in-place) * @param v1 vector 1 * @param v2 vector 2 @@ -342,7 +414,7 @@ public class VectorUtil { * @return midpoint */ public static float mid(final float p1, final float p2) { - return (p1+p2)/2.0f; + return (p1+p2)*0.5f; } /** |