aboutsummaryrefslogtreecommitdiffstats
path: root/src/jogl/classes/com/jogamp/graph
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2014-02-23 14:51:06 +0100
committerSven Gothel <[email protected]>2014-02-23 14:51:06 +0100
commit3352601e0860584509adf2b76f993d03893ded4b (patch)
tree974fccc8c0eb2f5ad9d4ffd741dfc35869ed67b5 /src/jogl/classes/com/jogamp/graph
parentf51933f0ebe9ae030c26c066e59a728ce08b8559 (diff)
parentc67de337a8aaf52e36104c3f13e273aa19d21f1f (diff)
Merge branch 'master' into stash_glyphcache
Conflicts: make/scripts/tests.sh src/jogl/classes/com/jogamp/graph/curve/OutlineShape.java src/jogl/classes/com/jogamp/graph/curve/Region.java src/jogl/classes/com/jogamp/graph/curve/opengl/GLRegion.java src/jogl/classes/com/jogamp/graph/curve/opengl/RegionRenderer.java src/jogl/classes/com/jogamp/graph/curve/opengl/Renderer.java src/jogl/classes/com/jogamp/graph/curve/opengl/TextRenderer.java src/jogl/classes/com/jogamp/graph/font/Font.java src/jogl/classes/com/jogamp/opengl/math/VectorUtil.java src/jogl/classes/jogamp/graph/curve/text/GlyphShape.java src/jogl/classes/jogamp/graph/curve/text/GlyphString.java src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java src/jogl/classes/jogamp/graph/font/typecast/TypecastGlyph.java src/jogl/classes/jogamp/graph/font/typecast/TypecastRenderer.java
Diffstat (limited to 'src/jogl/classes/com/jogamp/graph')
-rw-r--r--[-rwxr-xr-x]src/jogl/classes/com/jogamp/graph/curve/OutlineShape.java146
-rw-r--r--src/jogl/classes/com/jogamp/graph/curve/Region.java42
-rw-r--r--[-rwxr-xr-x]src/jogl/classes/com/jogamp/graph/curve/opengl/GLRegion.java30
-rw-r--r--src/jogl/classes/com/jogamp/graph/curve/opengl/RegionRenderer.java22
-rw-r--r--src/jogl/classes/com/jogamp/graph/curve/opengl/RenderState.java43
-rw-r--r--src/jogl/classes/com/jogamp/graph/curve/opengl/Renderer.java131
-rw-r--r--src/jogl/classes/com/jogamp/graph/curve/tess/Triangulation.java2
-rw-r--r--src/jogl/classes/com/jogamp/graph/curve/tess/Triangulator.java12
-rw-r--r--src/jogl/classes/com/jogamp/graph/font/Font.java39
-rw-r--r--src/jogl/classes/com/jogamp/graph/font/FontFactory.java47
-rw-r--r--src/jogl/classes/com/jogamp/graph/font/FontSet.java16
-rw-r--r--src/jogl/classes/com/jogamp/graph/geom/AABBox.java327
-rw-r--r--src/jogl/classes/com/jogamp/graph/geom/Outline.java42
-rw-r--r--src/jogl/classes/com/jogamp/graph/geom/Triangle.java11
-rw-r--r--src/jogl/classes/com/jogamp/graph/geom/Vertex.java33
-rw-r--r--src/jogl/classes/com/jogamp/graph/geom/opengl/SVertex.java67
-rwxr-xr-xsrc/jogl/classes/com/jogamp/graph/math/Quaternion.java382
-rwxr-xr-xsrc/jogl/classes/com/jogamp/graph/math/VectorUtil.java544
18 files changed, 366 insertions, 1570 deletions
diff --git a/src/jogl/classes/com/jogamp/graph/curve/OutlineShape.java b/src/jogl/classes/com/jogamp/graph/curve/OutlineShape.java
index 5b0d985ad..c8d5a9db6 100755..100644
--- a/src/jogl/classes/com/jogamp/graph/curve/OutlineShape.java
+++ b/src/jogl/classes/com/jogamp/graph/curve/OutlineShape.java
@@ -32,23 +32,23 @@ import java.util.Collections;
import com.jogamp.graph.curve.tess.Triangulation;
import com.jogamp.graph.curve.tess.Triangulator;
-import com.jogamp.graph.geom.AABBox;
import com.jogamp.graph.geom.Outline;
import com.jogamp.graph.geom.Triangle;
import com.jogamp.graph.geom.Vertex;
-import com.jogamp.graph.math.VectorUtil;
+import com.jogamp.opengl.math.VectorUtil;
+import com.jogamp.opengl.math.geom.AABBox;
/** A Generic shape objects which is defined by a list of Outlines.
* This Shape can be transformed to Triangulations.
* The list of triangles generated are render-able by a Region object.
- * The triangulation produced by this Shape will define the
+ * The triangulation produced by this Shape will define the
* closed region defined by the outlines.
- *
+ *
* One or more OutlineShape Object can be associated to a region
* this is left as a high-level representation of the Objects. For
* optimizations, flexibility requirements for future features.
- *
+ *
* <br><br>
* Example to creating an Outline Shape:
* <pre>
@@ -60,18 +60,18 @@ import com.jogamp.graph.math.VectorUtil;
addVertex(...)
addVertex(...)
* </pre>
- *
- * The above will create two outlines each with three vertices. By adding these two outlines to
+ *
+ * The above will create two outlines each with three vertices. By adding these two outlines to
* the OutlineShape, we are stating that the combination of the two outlines represent the shape.
* <br>
- *
- * To specify that the shape is curved at a region, the on-curve flag should be set to false
+ *
+ * To specify that the shape is curved at a region, the on-curve flag should be set to false
* for the vertex that is in the middle of the curved region (if the curved region is defined by 3
* vertices (quadratic curve).
* <br>
- * In case the curved region is defined by 4 or more vertices the middle vertices should both have
+ * In case the curved region is defined by 4 or more vertices the middle vertices should both have
* the on-curve flag set to false.
- *
+ *
* <br>Example: <br>
* <pre>
addVertex(0,0, true);
@@ -79,16 +79,16 @@ import com.jogamp.graph.math.VectorUtil;
addVertex(1,1, false);
addVertex(1,0, true);
* </pre>
- *
- * The above snippet defines a cubic nurbs curve where (0,1 and 1,1)
+ *
+ * The above snippet defines a cubic nurbs curve where (0,1 and 1,1)
* do not belong to the final rendered shape.
- *
+ *
* <i>Implementation Notes:</i><br>
* <ul>
* <li> The first vertex of any outline belonging to the shape should be on-curve</li>
* <li> Intersections between off-curved parts of the outline is not handled</li>
* </ul>
- *
+ *
* @see Outline
* @see Region
*/
@@ -104,21 +104,21 @@ public class OutlineShape implements Comparable<OutlineShape> {
VerticesState(int state){
this.state = state;
}
- }
+ }
public static final int DIRTY_BOUNDS = 1 << 0;
private final Vertex.Factory<? extends Vertex> vertexFactory;
private VerticesState outlineState;
- /** The list of {@link Outline}s that are part of this
+ /** The list of {@link Outline}s that are part of this
* outline shape.
*/
/* pp */ ArrayList<Outline> outlines;
- private AABBox bbox;
+ private final AABBox bbox;
/** dirty bits DIRTY_BOUNDS */
- private int dirtyBits;
+ private int dirtyBits;
/** Create a new Outline based Shape
*/
@@ -128,7 +128,7 @@ public class OutlineShape implements Comparable<OutlineShape> {
this.outlines.add(new Outline());
this.outlineState = VerticesState.UNDEFINED;
this.bbox = new AABBox();
- this.dirtyBits = 0;
+ this.dirtyBits = 0;
}
/** Clears all data and reset all states as if this instance was newly created */
@@ -137,7 +137,7 @@ public class OutlineShape implements Comparable<OutlineShape> {
outlines.add(new Outline());
outlineState = VerticesState.UNDEFINED;
bbox.reset();
- dirtyBits = 0;
+ dirtyBits = 0;
}
/** Returns the associated vertex factory of this outline shape
@@ -149,10 +149,10 @@ public class OutlineShape implements Comparable<OutlineShape> {
return outlines.size();
}
- /** Add a new empty {@link Outline}
+ /** Add a new empty {@link Outline}
* to the end of this shape's outline list.
* <p>If the {@link #getLastOutline()} is empty already, no new one will be added.</p>
- *
+ *
* After a call to this function all new vertices added
* will belong to the new outline
*/
@@ -164,26 +164,26 @@ public class OutlineShape implements Comparable<OutlineShape> {
/** Appends the {@link Outline} element to the end,
* ensuring a clean tail.
- *
+ *
* <p>A clean tail is ensured, no double empty Outlines are produced
* and a pre-existing empty outline will be replaced with the given one. </p>
- *
+ *
* @param outline Outline object to be added
- * @throws NullPointerException if the {@link Outline} element is null
+ * @throws NullPointerException if the {@link Outline} element is null
*/
public void addOutline(Outline outline) throws NullPointerException {
addOutline(outlines.size(), outline);
}
/** Insert the {@link Outline} element at the given {@code position}.
- *
+ *
* <p>If the {@code position} indicates the end of this list,
* a clean tail is ensured, no double empty Outlines are produced
* and a pre-existing empty outline will be replaced with the given one. </p>
- *
+ *
* @param position of the added Outline
* @param outline Outline object to be added
- * @throws NullPointerException if the {@link Outline} element is null
+ * @throws NullPointerException if the {@link Outline} element is null
* @throws IndexOutOfBoundsException if position is out of range (position < 0 || position > getOutlineNumber())
*/
public void addOutline(int position, Outline outline) throws NullPointerException, IndexOutOfBoundsException {
@@ -213,7 +213,7 @@ public class OutlineShape implements Comparable<OutlineShape> {
* using {@link #addOutline(Outline)} for each element.
* <p>Closes the current last outline via {@link #closeLastOutline()} before adding the new ones.</p>
* @param outlineShape OutlineShape elements to be added.
- * @throws NullPointerException if the {@link OutlineShape} is null
+ * @throws NullPointerException if the {@link OutlineShape} is null
* @throws IndexOutOfBoundsException if position is out of range (position < 0 || position > getOutlineNumber())
*/
public void addOutlineShape(OutlineShape outlineShape) throws NullPointerException {
@@ -228,10 +228,10 @@ public class OutlineShape implements Comparable<OutlineShape> {
/** Replaces the {@link Outline} element at the given {@code position}.
* <p>Sets the bounding box dirty, hence a next call to {@link #getBounds()} will validate it.</p>
- *
+ *
* @param position of the replaced Outline
- * @param outline replacement Outline object
- * @throws NullPointerException if the {@link Outline} element is null
+ * @param outline replacement Outline object
+ * @throws NullPointerException if the {@link Outline} element is null
* @throws IndexOutOfBoundsException if position is out of range (position < 0 || position >= getOutlineNumber())
*/
public void setOutline(int position, Outline outline) throws NullPointerException, IndexOutOfBoundsException {
@@ -244,7 +244,7 @@ public class OutlineShape implements Comparable<OutlineShape> {
/** Removes the {@link Outline} element at the given {@code position}.
* <p>Sets the bounding box dirty, hence a next call to {@link #getBounds()} will validate it.</p>
- *
+ *
* @param position of the to be removed Outline
* @throws IndexOutOfBoundsException if position is out of range (position < 0 || position >= getOutlineNumber())
*/
@@ -261,15 +261,15 @@ public class OutlineShape implements Comparable<OutlineShape> {
return outlines.get(outlines.size()-1);
}
- /** @return the {@code Outline} at {@code position}
+ /** @return the {@code Outline} at {@code position}
* @throws IndexOutOfBoundsException if position is out of range (position < 0 || position >= getOutlineNumber())
*/
public Outline getOutline(int position) throws IndexOutOfBoundsException {
return outlines.get(position);
- }
+ }
/** Adds a vertex to the last open outline in the
- * shape.
+ * shape.
* @param v the vertex to be added to the OutlineShape
*/
public final void addVertex(Vertex v) {
@@ -280,9 +280,9 @@ public class OutlineShape implements Comparable<OutlineShape> {
}
}
- /** Adds a vertex to the last open outline in the shape.
- * at {@code position}
- * @param position indx at which the vertex will be added
+ /** Adds a vertex to the last open outline in the shape.
+ * at {@code position}
+ * @param position indx at which the vertex will be added
* @param v the vertex to be added to the OutlineShape
*/
public final void addVertex(int position, Vertex v) {
@@ -295,7 +295,7 @@ public class OutlineShape implements Comparable<OutlineShape> {
/** Add a 2D {@link Vertex} to the last outline by defining the coordniate attribute
* of the vertex. The 2D vertex will be represented as Z=0.
- *
+ *
* @param x the x coordinate
* @param y the y coordniate
* @param onCurve flag if this vertex is on the final curve or defines a curved region
@@ -317,10 +317,10 @@ public class OutlineShape implements Comparable<OutlineShape> {
addVertex(vertexFactory.create(x, y, z, onCurve));
}
- /** Add a vertex to the last outline by passing a float array and specifying the
- * offset and length in which. The attributes of the vertex are located.
+ /** Add a vertex to the last outline by passing a float array and specifying the
+ * offset and length in which. The attributes of the vertex are located.
* The attributes should be continuous (stride = 0).
- * Attributes which value are not set (when length less than 3)
+ * Attributes which value are not set (when length less than 3)
* are set implicitly to zero.
* @param coordsBuffer the coordinate array where the vertex attributes are to be picked from
* @param offset the offset in the buffer to the x coordinate
@@ -330,11 +330,11 @@ public class OutlineShape implements Comparable<OutlineShape> {
*/
public final void addVertex(float[] coordsBuffer, int offset, int length, boolean onCurve) {
addVertex(vertexFactory.create(coordsBuffer, offset, length, onCurve));
- }
+ }
/** Closes the last outline in the shape.
* <p>If last vertex is not equal to first vertex.
- * A new temp vertex is added at the end which
+ * A new temp vertex is added at the end which
* is equal to the first.</p>
*/
public void closeLastOutline() {
@@ -351,7 +351,7 @@ public class OutlineShape implements Comparable<OutlineShape> {
/** Ensure the outlines represent
* the specified destinationType.
* and removes all overlaps in boundary triangles
- * @param destinationType the target outline's vertices state. Currently only
+ * @param destinationType the target outline's vertices state. Currently only
* {@link OutlineShape.VerticesState#QUADRATIC_NURBS} are supported.
*/
public void transformOutlines(VerticesState destinationType) {
@@ -371,7 +371,7 @@ public class OutlineShape implements Comparable<OutlineShape> {
float[] v2 = VectorUtil.mid(v1, v3);
//drop off-curve vertex to image on the curve
- b.setCoord(v2, 0, 3);
+ b.setCoord(v2, 0, 3);
b.setOnCurve(true);
outline.addVertex(index, vertexFactory.create(v1, 0, 3, false));
@@ -379,19 +379,19 @@ public class OutlineShape implements Comparable<OutlineShape> {
}
/** Check overlaps between curved triangles
- * first check if any vertex in triangle a is in triangle b
+ * first check if any vertex in triangle a is in triangle b
* second check if edges of triangle a intersect segments of triangle b
* if any of the two tests is true we divide current triangle
* and add the other to the list of overlaps
- *
+ *
* Loop until overlap array is empty. (check only in first pass)
*/
- private void checkOverlaps() {
+ private void checkOverlaps() {
ArrayList<Vertex> overlaps = new ArrayList<Vertex>(3);
int count = getOutlineNumber();
boolean firstpass = true;
do {
- for (int cc = 0; cc < count; cc++) {
+ for (int cc = 0; cc < count; cc++) {
final Outline outline = getOutline(cc);
int vertexCount = outline.getVertexCount();
for(int i=0; i < outline.getVertexCount(); i++) {
@@ -430,10 +430,10 @@ public class OutlineShape implements Comparable<OutlineShape> {
private final float[] tempVecAC = new float[3];
private final float[] tempVecAB = new float[3];
private final float[] tempVecAP = new float[3];
-
+
private Vertex checkTriOverlaps(Vertex a, Vertex b, Vertex c) {
int count = getOutlineNumber();
- for (int cc = 0; cc < count; cc++) {
+ for (int cc = 0; cc < count; cc++) {
final Outline outline = getOutline(cc);
int vertexCount = outline.getVertexCount();
for(int i=0; i < vertexCount; i++) {
@@ -466,7 +466,7 @@ public class OutlineShape implements Comparable<OutlineShape> {
private void transformOutlines2Quadratic() {
int count = getOutlineNumber();
- for (int cc = 0; cc < count; cc++) {
+ for (int cc = 0; cc < count; cc++) {
final Outline outline = getOutline(cc);
int vertexCount = outline.getVertexCount();
@@ -474,13 +474,13 @@ public class OutlineShape implements Comparable<OutlineShape> {
final Vertex currentVertex = outline.getVertex(i);
final Vertex nextVertex = outline.getVertex((i+1)%vertexCount);
if ( !currentVertex.isOnCurve() && !nextVertex.isOnCurve() ) {
- final float[] newCoords = VectorUtil.mid(currentVertex.getCoord(),
+ final float[] newCoords = VectorUtil.mid(currentVertex.getCoord(),
nextVertex.getCoord());
final Vertex v = vertexFactory.create(newCoords, 0, 3, true);
i++;
vertexCount++;
outline.addVertex(i, v);
- }
+ }
}
if(vertexCount <= 0) {
outlines.remove(outline);
@@ -490,7 +490,7 @@ public class OutlineShape implements Comparable<OutlineShape> {
}
if( vertexCount > 0 ) {
- if(VectorUtil.checkEquality(outline.getVertex(0).getCoord(),
+ if(VectorUtil.checkEquality(outline.getVertex(0).getCoord(),
outline.getLastVertex().getCoord())) {
outline.removeVertex(vertexCount-1);
}
@@ -511,7 +511,7 @@ public class OutlineShape implements Comparable<OutlineShape> {
}
}
- /** @return the list of concatenated vertices associated with all
+ /** @return the list of concatenated vertices associated with all
* {@code Outline}s of this object
*/
public ArrayList<Vertex> getVertices() {
@@ -554,9 +554,10 @@ public class OutlineShape implements Comparable<OutlineShape> {
}
/** Compare two outline shapes with Bounding Box area
- * as criteria.
+ * as criteria.
* @see java.lang.Comparable#compareTo(java.lang.Object)
*/
+ @Override
public final int compareTo(OutlineShape outline) {
float size = getBounds().getSize();
float newSize = outline.getBounds().getSize();
@@ -582,20 +583,21 @@ public class OutlineShape implements Comparable<OutlineShape> {
validateBoundingBox();
}
return bbox;
- }
+ }
/**
* @param obj the Object to compare this OutlineShape with
- * @return true if {@code obj} is an OutlineShape, not null,
- * same outlineState, equal bounds and equal outlines in the same order
+ * @return true if {@code obj} is an OutlineShape, not null,
+ * same outlineState, equal bounds and equal outlines in the same order
*/
+ @Override
public boolean equals(Object obj) {
if( obj == this) {
return true;
}
if( null == obj || !(obj instanceof OutlineShape) ) {
return false;
- }
+ }
final OutlineShape o = (OutlineShape) obj;
if(getOutlineState() != o.getOutlineState()) {
return false;
@@ -613,20 +615,4 @@ public class OutlineShape implements Comparable<OutlineShape> {
}
return true;
}
-
- /**
- * @return deep clone of this OutlineShape w/o Region
- */
- public OutlineShape clone() {
- OutlineShape o;
- try {
- o = (OutlineShape) super.clone();
- } catch (CloneNotSupportedException e) { throw new InternalError(); }
- o.bbox = bbox.clone();
- o.outlines = new ArrayList<Outline>(outlines.size());
- for(int i=0; i<outlines.size(); i++) {
- o.outlines.add(outlines.get(i).clone());
- }
- return o;
- }
}
diff --git a/src/jogl/classes/com/jogamp/graph/curve/Region.java b/src/jogl/classes/com/jogamp/graph/curve/Region.java
index f7f51758b..e36e37c26 100644
--- a/src/jogl/classes/com/jogamp/graph/curve/Region.java
+++ b/src/jogl/classes/com/jogamp/graph/curve/Region.java
@@ -34,13 +34,13 @@ import jogamp.graph.curve.opengl.RegionFactory;
import jogamp.opengl.Debug;
import com.jogamp.graph.curve.opengl.GLRegion;
-import com.jogamp.graph.geom.AABBox;
import com.jogamp.graph.geom.Triangle;
import com.jogamp.graph.geom.Vertex;
+import com.jogamp.opengl.math.geom.AABBox;
/** Abstract Outline shape GL representation define the method an OutlineShape(s)
* is bound and rendered.
- *
+ *
* @see GLRegion */
public abstract class Region {
@@ -73,7 +73,7 @@ public abstract class Region {
}
/** Check if render mode capable of non uniform weights
- *
+ *
* @param renderModes
* bit-field of modes, e.g.
* {@link Region#VARIABLE_CURVE_WEIGHT_BIT},
@@ -93,7 +93,7 @@ public abstract class Region {
return region;
}
- /**
+ /**
* Create a {@link Region} defining this {@link OutlineShape}
* @return the resulting Region.
*/
@@ -101,28 +101,28 @@ public abstract class Region {
final Region region = RegionFactory.create(renderModes);
region.addOutlineShape(outlineShape);
return region;
- }
-
+ }
+
protected Region(int regionRenderModes) {
this.renderModes = regionRenderModes;
}
/** Get current Models
- *
+ *
* @return bit-field of render modes */
public final int getRenderModes() {
return renderModes;
}
/** Check if current Region is using VBAA
- *
+ *
* @return true if capable of two pass rendering - VBAA */
public boolean isVBAA() {
return Region.isVBAA(renderModes);
}
/** Check if current instance uses non uniform weights
- *
+ *
* @return true if capable of nonuniform weights */
public boolean isNonUniformWeight() {
return Region.isNonUniformWeight(renderModes);
@@ -130,7 +130,7 @@ public abstract class Region {
/** Get the current number of vertices associated with this region. This
* number is not necessary equal to the OGL bound number of vertices.
- *
+ *
* @return vertices count */
public final int getNumVertices() {
return numVertices;
@@ -138,10 +138,10 @@ public abstract class Region {
/** Adds a {@link Triangle} object to the Region This triangle will be bound
* to OGL objects on the next call to {@code update}
- *
+ *
* @param tri
* a triangle object
- *
+ *
* @see update(GL2ES2) */
public void addTriangle(Triangle tri) {
triangles.add(tri);
@@ -150,10 +150,10 @@ public abstract class Region {
/** Adds a list of {@link Triangle} objects to the Region These triangles are
* to be binded to OGL objects on the next call to {@code update}
- *
+ *
* @param tris
* a list of triangle objects
- *
+ *
* @see update(GL2ES2) */
public void addTriangles(List<Triangle> tris) {
triangles.addAll(tris);
@@ -162,10 +162,10 @@ public abstract class Region {
/** Adds a {@link Vertex} object to the Region This vertex will be bound to
* OGL objects on the next call to {@code update}
- *
+ *
* @param vert
* a vertex objects
- *
+ *
* @see update(GL2ES2) */
public void addVertex(Vertex vert) {
vertices.add(vert);
@@ -175,10 +175,10 @@ public abstract class Region {
/** Adds a list of {@link Vertex} objects to the Region These vertices are to
* be binded to OGL objects on the next call to {@code update}
- *
+ *
* @param verts
* a list of vertex objects
- *
+ *
* @see update(GL2ES2) */
public void addVertices(List<Vertex> verts) {
vertices.addAll(verts);
@@ -202,7 +202,7 @@ public abstract class Region {
}
setDirty(true);
}
-
+
public void addOutlineShapes(List<OutlineShape> shapes) {
for (int i = 0; i < shapes.size(); i++) {
addOutlineShape(shapes.get(i));
@@ -217,9 +217,9 @@ public abstract class Region {
/** Check if this region is dirty. A region is marked dirty when new
* Vertices, Triangles, and or Lines are added after a call to update()
- *
+ *
* @return true if region is Dirty, false otherwise
- *
+ *
* @see update(GL2ES2) */
public final boolean isDirty() {
return dirty;
diff --git a/src/jogl/classes/com/jogamp/graph/curve/opengl/GLRegion.java b/src/jogl/classes/com/jogamp/graph/curve/opengl/GLRegion.java
index e046c91cb..d63e02a9c 100755..100644
--- a/src/jogl/classes/com/jogamp/graph/curve/opengl/GLRegion.java
+++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/GLRegion.java
@@ -37,16 +37,16 @@ import com.jogamp.graph.curve.Region;
/** A GLRegion is the OGL binding of one or more OutlineShapes
* Defined by its vertices and generated triangles. The Region
- * defines the final shape of the OutlineShape(s), which shall produced a shaded
+ * defines the final shape of the OutlineShape(s), which shall produced a shaded
* region on the screen.
- *
- * Implementations of the GLRegion shall take care of the OGL
+ *
+ * Implementations of the GLRegion shall take care of the OGL
* binding of the depending on its context, profile.
- *
+ *
* @see Region, RegionFactory, OutlineShape
*/
-public abstract class GLRegion extends Region {
-
+public abstract class GLRegion extends Region {
+
/** Create an ogl {@link GLRegion} defining the list of {@link OutlineShape}.
* Combining the Shapes into single buffers.
* @return the resulting Region inclusive the generated region
@@ -55,31 +55,31 @@ public abstract class GLRegion extends Region {
return (GLRegion) Region.create(outlineShapes, renderModes);
}
- /**
+ /**
* Create an ogl {@link Region} defining this {@link OutlineShape}
* @return the resulting Region.
*/
public static GLRegion create(OutlineShape outlineShape, int renderModes) {
return (GLRegion) Region.create(outlineShape, renderModes);
- }
-
+ }
+
protected GLRegion(int renderModes) {
super(renderModes);
}
-
+
/** Updates a graph region by updating the ogl related
* objects for use in rendering if {@link #isDirty()}.
- * <p>Allocates the ogl related data and initializes it the 1st time.<p>
+ * <p>Allocates the ogl related data and initializes it the 1st time.<p>
* <p>Called by {@link #draw(GL2ES2, RenderState, int, int, int)}.</p>
* @param rs TODO
*/
protected abstract void update(GL2ES2 gl, RenderState rs);
-
+
/** Delete and clean the associated OGL
* objects
*/
public abstract void destroy(GL2ES2 gl, RenderState rs);
-
+
/** Renders the associated OGL objects specifying
* current width/hight of window for multi pass rendering
* of the region.
@@ -87,13 +87,13 @@ public abstract class GLRegion extends Region {
* @param rs the RenderState to be used
* @param vp_width current screen width
* @param vp_height current screen height
- * @param texWidth desired texture width for multipass-rendering.
+ * @param texWidth desired texture width for multipass-rendering.
* The actual used texture-width is written back when mp rendering is enabled, otherwise the store is untouched.
*/
public final void draw(GL2ES2 gl, RenderState rs, int vp_width, int vp_height, int[/*1*/] texWidth) {
update(gl, rs);
drawImpl(gl, rs, vp_width, vp_height, texWidth);
}
-
+
protected abstract void drawImpl(GL2ES2 gl, RenderState rs, int vp_width, int vp_height, int[/*1*/] texWidth);
}
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 4b7c12fea..faaf72a99 100644
--- a/src/jogl/classes/com/jogamp/graph/curve/opengl/RegionRenderer.java
+++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/RegionRenderer.java
@@ -35,25 +35,25 @@ import com.jogamp.graph.curve.Region;
public abstract class RegionRenderer extends Renderer {
- /**
+ /**
* Create a Hardware accelerated Region Renderer.
- * @param rs the used {@link RenderState}
- * @param renderModes bit-field of modes, e.g. {@link Region#VARIABLE_CURVE_WEIGHT_BIT}, {@link Region#VBAA_RENDERING_BIT}
+ * @param rs the used {@link RenderState}
+ * @param renderModes bit-field of modes, e.g. {@link Region#VARIABLE_CURVE_WEIGHT_BIT}, {@link Region#VBAA_RENDERING_BIT}
* @return an instance of Region Renderer
*/
public static RegionRenderer create(RenderState rs, int renderModes) {
return new jogamp.graph.curve.opengl.RegionRendererImpl01(rs, renderModes);
}
-
+
protected RegionRenderer(RenderState rs, int renderModes) {
super(rs, renderModes);
}
-
-
+
+
/** Render an {@link OutlineShape} in 3D space at the position provided
* the triangles of the shapes will be generated, if not yet generated
* @param region the OutlineShape to Render.
- * @param texWidth desired texture width for multipass-rendering.
+ * @param texWidth desired texture width for multipass-rendering.
* The actual used texture-width is written back when mp rendering is enabled, otherwise the store is untouched.
* @throws Exception if HwRegionRenderer not initialized
*/
@@ -64,10 +64,10 @@ public abstract class RegionRenderer extends Renderer {
if( !areRenderModesCompatible(region) ) {
throw new GLException("Incompatible render modes, : region modes "+region.getRenderModes()+
" doesn't contain renderer modes "+this.getRenderModes());
- }
+ }
drawImpl(gl, region, texWidth);
}
-
+
/**
* Usually just dispatched the draw call to the Region's draw implementation,
* e.g. {@link com.jogamp.graph.curve.opengl.GLRegion#draw(GL2ES2, RenderState, int, int, int[]) GLRegion#draw(GL2ES2, RenderState, int, int, int[])}.
@@ -78,6 +78,6 @@ public abstract class RegionRenderer extends Renderer {
protected void destroyImpl(GL2ES2 gl) {
// nop
}
-
-
+
+
}
diff --git a/src/jogl/classes/com/jogamp/graph/curve/opengl/RenderState.java b/src/jogl/classes/com/jogamp/graph/curve/opengl/RenderState.java
index eb07142a3..9b0f32ef6 100644
--- a/src/jogl/classes/com/jogamp/graph/curve/opengl/RenderState.java
+++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/RenderState.java
@@ -40,50 +40,50 @@ import com.jogamp.opengl.util.glsl.ShaderState;
public abstract class RenderState {
private static final String thisKey = "jogamp.graph.curve.RenderState" ;
-
+
public static RenderState createRenderState(ShaderState st, Vertex.Factory<? extends Vertex> pointFactory) {
- return new RenderStateImpl(st, pointFactory);
+ return new RenderStateImpl(st, pointFactory, null);
}
public static RenderState createRenderState(ShaderState st, Vertex.Factory<? extends Vertex> pointFactory, PMVMatrix pmvMatrix) {
return new RenderStateImpl(st, pointFactory, pmvMatrix);
}
-
+
public static final RenderState getRenderState(GL2ES2 gl) {
return (RenderState) gl.getContext().getAttachedObject(thisKey);
}
-
+
protected final ShaderState st;
protected final Vertex.Factory<? extends Vertex> vertexFactory;
protected final PMVMatrix pmvMatrix;
- protected final GLUniformData gcu_PMVMatrix;
-
+ protected final GLUniformData gcu_PMVMatrix;
+
protected RenderState(ShaderState st, Vertex.Factory<? extends Vertex> vertexFactory, PMVMatrix pmvMatrix) {
this.st = st;
this.vertexFactory = vertexFactory;
- this.pmvMatrix = pmvMatrix;
- this.gcu_PMVMatrix = new GLUniformData(UniformNames.gcu_PMVMatrix, 4, 4, pmvMatrix.glGetPMvMatrixf());
- st.ownUniform(gcu_PMVMatrix);
+ this.pmvMatrix = null != pmvMatrix ? pmvMatrix : new PMVMatrix();
+ this.gcu_PMVMatrix = new GLUniformData(UniformNames.gcu_PMVMatrix, 4, 4, this.pmvMatrix.glGetPMvMatrixf());
+ st.ownUniform(gcu_PMVMatrix);
}
-
+
public final ShaderState getShaderState() { return st; }
public final Vertex.Factory<? extends Vertex> getVertexFactory() { return vertexFactory; }
public final PMVMatrix pmvMatrix() { return pmvMatrix; }
public final GLUniformData getPMVMatrix() { return gcu_PMVMatrix; }
-
+
public void destroy(GL2ES2 gl) {
st.destroy(gl);
}
-
+
public abstract GLUniformData getWeight();
public abstract GLUniformData getAlpha();
public abstract GLUniformData getColorStatic();
// public abstract GLUniformData getStrength();
-
+
public final RenderState attachTo(GL2ES2 gl) {
return (RenderState) gl.getContext().attachObject(thisKey, this);
}
-
+
public final boolean detachFrom(GL2ES2 gl) {
RenderState _rs = (RenderState) gl.getContext().getAttachedObject(thisKey);
if(_rs == this) {
@@ -91,21 +91,22 @@ public abstract class RenderState {
return true;
}
return false;
- }
-
- public StringBuilder toString(StringBuilder sb) {
+ }
+
+ public StringBuilder toString(StringBuilder sb, boolean alsoUnlocated) {
if(null==sb) {
sb = new StringBuilder();
}
sb.append("RenderState[");
- st.toString(sb).append(Platform.getNewline());
+ st.toString(sb, alsoUnlocated).append(Platform.getNewline());
sb.append("]");
return sb;
}
-
+
+ @Override
public String toString() {
- return toString(null).toString();
- }
+ return toString(null, false).toString();
+ }
}
diff --git a/src/jogl/classes/com/jogamp/graph/curve/opengl/Renderer.java b/src/jogl/classes/com/jogamp/graph/curve/opengl/Renderer.java
index c9cb13ad4..31e4f0b8f 100644
--- a/src/jogl/classes/com/jogamp/graph/curve/opengl/Renderer.java
+++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/Renderer.java
@@ -33,6 +33,7 @@ import javax.media.opengl.GL2ES2;
import javax.media.opengl.GLException;
import javax.media.opengl.fixedfunc.GLMatrixFunc;
+import com.jogamp.opengl.util.glsl.ShaderCode;
import com.jogamp.opengl.util.glsl.ShaderState;
import com.jogamp.opengl.util.PMVMatrix;
@@ -51,8 +52,8 @@ public abstract class Renderer {
protected int vp_height;
protected boolean initialized;
protected final RenderState rs;
- private boolean vboSupported = false;
-
+ private boolean vboSupported = false;
+
public final boolean isInitialized() { return initialized; }
public final int getWidth() { return vp_width; }
@@ -61,29 +62,29 @@ public abstract class Renderer {
public float getWeight() { return rs.getWeight().floatValue(); }
public float getAlpha() { return rs.getAlpha().floatValue(); }
public final PMVMatrix getMatrix() { return rs.pmvMatrix(); }
-
+
/**
* Implementation shall load, compile and link the shader program and leave it active.
* @param gl referencing the current GLContext to which the ShaderState is bound to
* @return
*/
protected abstract boolean initShaderProgram(GL2ES2 gl);
-
+
protected abstract void destroyImpl(GL2ES2 gl);
-
+
/**
- * @param rs the used {@link RenderState}
+ * @param rs the used {@link RenderState}
* @param renderModes bit-field of modes
*/
protected Renderer(RenderState rs, int renderModes) {
this.rs = rs;
this.renderModes = renderModes;
}
-
+
public final int getRenderModes() {
return renderModes;
}
-
+
public boolean usesVariableCurveWeight() { return Region.isNonUniformWeight(renderModes); }
/**
@@ -92,17 +93,17 @@ public abstract class Renderer {
*/
public final boolean areRenderModesCompatible(Region region) {
final int cleanRenderModes = getRenderModes() & ( Region.VARIABLE_CURVE_WEIGHT_BIT );
- return cleanRenderModes == ( region.getRenderModes() & cleanRenderModes );
+ return cleanRenderModes == ( region.getRenderModes() & cleanRenderModes );
}
-
+
public final boolean isVBOSupported() { return vboSupported; }
-
- /**
+
+ /**
* Initialize shader and bindings for GPU based rendering bound to the given GL object's GLContext
* if not initialized yet.
* <p>Leaves the renderer enabled, ie ShaderState.</p>
* <p>Shall be called by a {@code draw()} method, e.g. {@link RegionRenderer#draw(GL2ES2, Region, int)}</p>
- *
+ *
* @param gl referencing the current GLContext to which the ShaderState is bound to
* @throws GLException if initialization failed
*/
@@ -116,46 +117,48 @@ public abstract class Renderer {
gl.isFunctionAvailable("glDrawElements") &&
gl.isFunctionAvailable("glVertexAttribPointer") &&
gl.isFunctionAvailable("glDeleteBuffers");
-
+
if(DEBUG) {
System.err.println("TextRendererImpl01: VBO Supported = " + isVBOSupported());
}
-
+
if(!vboSupported){
throw new GLException("VBO not supported");
}
-
+
rs.attachTo(gl);
-
+
gl.glEnable(GL2ES2.GL_BLEND);
gl.glBlendFunc(GL2ES2.GL_SRC_ALPHA, GL2ES2.GL_ONE_MINUS_SRC_ALPHA); // FIXME: alpha blending stage ?
-
+
initialized = initShaderProgram(gl);
if(!initialized) {
throw new GLException("Shader initialization failed");
}
-
+
if(!rs.getShaderState().uniform(gl, rs.getPMVMatrix())) {
throw new GLException("Error setting PMVMatrix in shader: "+rs.getShaderState());
}
-
- if(!rs.getShaderState().uniform(gl, rs.getWeight())) {
- throw new GLException("Error setting weight in shader: "+rs.getShaderState());
+
+ if( Region.isNonUniformWeight( getRenderModes() ) ) {
+ if(!rs.getShaderState().uniform(gl, rs.getWeight())) {
+ throw new GLException("Error setting weight in shader: "+rs.getShaderState());
+ }
}
-
+
if(!rs.getShaderState().uniform(gl, rs.getAlpha())) {
throw new GLException("Error setting global alpha in shader: "+rs.getShaderState());
- }
-
+ }
+
if(!rs.getShaderState().uniform(gl, rs.getColorStatic())) {
throw new GLException("Error setting global color in shader: "+rs.getShaderState());
- }
+ }
}
- public final void flushCache(GL2ES2 gl) {
+ public final void flushCache(GL2ES2 gl) {
// FIXME: REMOVE !
}
-
+
public void destroy(GL2ES2 gl) {
if(!initialized){
if(DEBUG_INSTANCE) {
@@ -166,13 +169,13 @@ public abstract class Renderer {
rs.getShaderState().useProgram(gl, false);
destroyImpl(gl);
rs.destroy(gl);
- initialized = false;
+ initialized = false;
}
-
+
public final RenderState getRenderState() { return rs; }
public final ShaderState getShaderState() { return rs.getShaderState(); }
-
- public final void enable(GL2ES2 gl, boolean enable) {
+
+ public final void enable(GL2ES2 gl, boolean enable) {
rs.getShaderState().useProgram(gl, enable);
}
@@ -181,11 +184,11 @@ public abstract class Renderer {
throw new IllegalArgumentException("Weight out of range");
}
rs.getWeight().setData(v);
- if(null != gl && rs.getShaderState().inUse()) {
+ if(null != gl && rs.getShaderState().inUse() && Region.isNonUniformWeight( getRenderModes() ) ) {
rs.getShaderState().uniform(gl, rs.getWeight());
}
}
-
+
public void setAlpha(GL2ES2 gl, float alpha_t) {
rs.getAlpha().setData(alpha_t);
if(null != gl && rs.getShaderState().inUse()) {
@@ -196,11 +199,11 @@ public abstract class Renderer {
public void getColorStatic(GL2ES2 gl, float[] rgb) {
FloatBuffer fb = (FloatBuffer) rs.getColorStatic().getBuffer();
- rgb[0] = fb.get(0);
- rgb[1] = fb.get(1);
- rgb[2] = fb.get(2);
+ rgb[0] = fb.get(0);
+ rgb[1] = fb.get(1);
+ rgb[2] = fb.get(2);
}
-
+
public void setColorStatic(GL2ES2 gl, float r, float g, float b){
FloatBuffer fb = (FloatBuffer) rs.getColorStatic().getBuffer();
fb.put(0, r);
@@ -210,7 +213,7 @@ public abstract class Renderer {
rs.getShaderState().uniform(gl, rs.getColorStatic());
}
}
-
+
public void rotate(GL2ES2 gl, float angle, float x, float y, float z) {
rs.pmvMatrix().glRotatef(angle, x, y, z);
updateMatrix(gl);
@@ -220,7 +223,7 @@ public abstract class Renderer {
rs.pmvMatrix().glTranslatef(x, y, z);
updateMatrix(gl);
}
-
+
public void scale(GL2ES2 gl, float x, float y, float z) {
rs.pmvMatrix().glScalef(x, y, z);
updateMatrix(gl);
@@ -238,6 +241,14 @@ public abstract class Renderer {
}
}
+ /** No PMVMatrix operation is performed here. PMVMatrix will be updated if gl is not null. */
+ public boolean reshapeNotify(GL2ES2 gl, int width, int height) {
+ this.vp_width = width;
+ this.vp_height = height;
+ updateMatrix(gl);
+ return true;
+ }
+
public boolean reshapePerspective(GL2ES2 gl, float angle, int width, int height, float near, float far) {
this.vp_width = width;
this.vp_height = height;
@@ -258,24 +269,34 @@ public abstract class Renderer {
p.glLoadIdentity();
p.glOrthof(0, width, 0, height, near, far);
updateMatrix(gl);
- return true;
+ return true;
}
- protected String getVertexShaderName(GL2ES2 gl) {
- return "curverenderer01" + getShaderGLVersionSuffix(gl);
+ protected String getVertexShaderName() {
+ return "curverenderer" + getImplVersion();
}
-
- protected String getFragmentShaderName(GL2ES2 gl) {
- final String type = "01" ; // Region.isNonUniformWeight(renderModes) ? "02" : "01" ;
- final String pass = Region.isVBAA(renderModes) ? "b" : "a" ;
- return "curverenderer" + type + pass + getShaderGLVersionSuffix(gl);
+
+ protected String getFragmentShaderName() {
+ final String version = getImplVersion();
+ final String pass = Region.isVBAA(renderModes) ? "-2pass" : "-1pass" ;
+ final String weight = Region.isNonUniformWeight(renderModes) ? "-weight" : "" ;
+ return "curverenderer" + version + pass + weight;
}
-
- protected String getShaderGLVersionSuffix(GL2ES2 gl) {
- if(gl.isGLES2()) {
- return "-es2";
+
+ // FIXME: Really required to have sampler2D def. precision ? If not, we can drop getFragmentShaderPrecision(..) and use default ShaderCode ..
+ public static final String es2_precision_fp = "\nprecision mediump float;\nprecision mediump int;\nprecision mediump sampler2D;\n";
+
+ protected String getFragmentShaderPrecision(GL2ES2 gl) {
+ if( gl.isGLES() ) {
+ return es2_precision_fp;
+ }
+ if( ShaderCode.requiresGL3DefaultPrecision(gl) ) {
+ return ShaderCode.gl3_default_precision_fp;
}
- return "-gl2";
- }
-
+ return null;
+ }
+
+ protected String getImplVersion() {
+ return "01";
+ }
} \ No newline at end of file
diff --git a/src/jogl/classes/com/jogamp/graph/curve/tess/Triangulation.java b/src/jogl/classes/com/jogamp/graph/curve/tess/Triangulation.java
index 7728efcaf..ae2849536 100644
--- a/src/jogl/classes/com/jogamp/graph/curve/tess/Triangulation.java
+++ b/src/jogl/classes/com/jogamp/graph/curve/tess/Triangulation.java
@@ -33,7 +33,7 @@ import jogamp.graph.curve.tess.CDTriangulator2D;
public class Triangulation {
/** Create a new instance of a triangulation.
- * Currently only a modified version of Constraint Delaunay
+ * Currently only a modified version of Constraint Delaunay
* is implemented.
* @return instance of a triangulator
* @see Triangulator
diff --git a/src/jogl/classes/com/jogamp/graph/curve/tess/Triangulator.java b/src/jogl/classes/com/jogamp/graph/curve/tess/Triangulator.java
index 1ffaccebc..4e8c400e0 100644
--- a/src/jogl/classes/com/jogamp/graph/curve/tess/Triangulator.java
+++ b/src/jogl/classes/com/jogamp/graph/curve/tess/Triangulator.java
@@ -36,32 +36,32 @@ import com.jogamp.graph.geom.Triangle;
/** Interface to the triangulation algorithms provided
* A triangulation of 2D outlines where you can
* provides an easy one or more outlines to be triangulated
- *
+ *
* example usage:
* addCurve(o1);
* addCurve(o2);
* addCurve(o3);
* generate();
* reset();
- *
+ *
* @see Outline
* @see Triangulation
*/
public interface Triangulator {
-
+
/** Add a curve to the list of Outlines
* describing the shape
* @param outline a bounding {@link Outline}
*/
public void addCurve(Outline outline);
-
- /** Generate the triangulation of the provided
+
+ /** Generate the triangulation of the provided
* List of {@link Outline}s
* @return an arraylist of {@link Triangle}s resembling the
* final shape.
*/
public ArrayList<Triangle> generate();
-
+
/** Reset the triangulation to initial state
* Clearing cached data
*/
diff --git a/src/jogl/classes/com/jogamp/graph/font/Font.java b/src/jogl/classes/com/jogamp/graph/font/Font.java
index 97510bcd0..6c0041de9 100644
--- a/src/jogl/classes/com/jogamp/graph/font/Font.java
+++ b/src/jogl/classes/com/jogamp/graph/font/Font.java
@@ -30,16 +30,16 @@ package com.jogamp.graph.font;
import java.util.List;
import com.jogamp.graph.curve.OutlineShape;
-import com.jogamp.graph.geom.AABBox;
import com.jogamp.graph.geom.Vertex;
import com.jogamp.graph.geom.Vertex.Factory;
+import com.jogamp.opengl.math.geom.AABBox;
/**
* Interface wrapper for font implementation.
- *
+ *
* TrueType Font Specification:
* http://developer.apple.com/fonts/ttrefman/rm06/Chap6.html
- *
+ *
* TrueType Font Table Introduction:
* http://scripts.sil.org/cms/scripts/page.php?item_id=IWS-Chapter08
*/
@@ -55,22 +55,22 @@ public interface Font {
public static final int NAME_VERSION = 5;
public static final int NAME_MANUFACTURER = 8;
public static final int NAME_DESIGNER = 9;
-
-
+
+
/**
* Metrics for font
- *
+ *
* Depending on the font's direction, horizontal or vertical,
* the following tables shall be used:
- *
+ *
* Vertical http://developer.apple.com/fonts/TTRefMan/RM06/Chap6vhea.html
* Horizontal http://developer.apple.com/fonts/TTRefMan/RM06/Chap6hhea.html
*/
- public interface Metrics {
+ public interface Metrics {
float getAscent(float pixelSize);
float getDescent(float pixelSize);
float getLineGap(float pixelSize);
- float getMaxExtend(float pixelSize);
+ float getMaxExtend(float pixelSize);
float getScale(float pixelSize);
AABBox getBBox(float pixelSize);
}
@@ -79,12 +79,12 @@ public interface Font {
* Glyph for font
*/
public interface Glyph {
- // reserved special glyph IDs
+ // reserved special glyph IDs
// http://scripts.sil.org/cms/scripts/page.php?item_id=IWS-Chapter08#ba57949e
public static final int ID_UNKNOWN = 0;
public static final int ID_CR = 2;
public static final int ID_SPACE = 3;
-
+
public Font getFont();
public char getSymbol();
public short getID();
@@ -97,24 +97,24 @@ public interface Font {
public String getName(int nameIndex);
public StringBuilder getName(StringBuilder string, int nameIndex);
-
+
/** Shall return the family and subfamily name, separated a dash.
* <p>{@link #getName(StringBuilder, int)} w/ {@link #NAME_FAMILY} and {@link #NAME_SUBFAMILY}</p>
* <p>Example: "{@code Ubuntu-Regular}"</p> */
public StringBuilder getFullFamilyName(StringBuilder buffer);
-
+
public StringBuilder getAllNames(StringBuilder string, String separator);
-
+
public float getAdvanceWidth(int i, float pixelSize);
public Metrics getMetrics();
public Glyph getGlyph(char symbol);
public int getNumGlyphs();
-
+
public float getStringWidth(CharSequence string, float pixelSize);
public float getStringHeight(CharSequence string, float pixelSize);
public AABBox getStringBounds(CharSequence string, float pixelSize);
-
- public boolean isPrintableChar( char c );
+
+ public boolean isPrintableChar( char c );
/**
* @param glyph source of the created OutlineShape
@@ -122,7 +122,7 @@ public interface Font {
* @return OutlineShape of the glyph
*/
public OutlineShape getOutlineShape(Glyph glyph, Factory<? extends Vertex> vertexFactory);
-
+
/**
* @param shapes optional storage of OutlineShapes passed by user, new shapes are appended
* @param string source of the created OutlineShapes
@@ -131,7 +131,8 @@ public interface Font {
* @return List of OutlineShapes, one OutlineShape per character
*/
public List<OutlineShape> getOutlineShapes(List<OutlineShape> shapes, CharSequence string, float pixelSize, Factory<? extends Vertex> vertexFactory);
-
+
/** Shall return {@link #getFullFamilyName()} */
+ @Override
public String toString();
} \ No newline at end of file
diff --git a/src/jogl/classes/com/jogamp/graph/font/FontFactory.java b/src/jogl/classes/com/jogamp/graph/font/FontFactory.java
index 33d487355..884662e6e 100644
--- a/src/jogl/classes/com/jogamp/graph/font/FontFactory.java
+++ b/src/jogl/classes/com/jogamp/graph/font/FontFactory.java
@@ -33,19 +33,29 @@ import java.net.URLConnection;
import com.jogamp.common.util.PropertyAccess;
import com.jogamp.common.util.ReflectionUtil;
-import com.jogamp.common.util.SecurityUtil;
import jogamp.graph.font.FontConstructor;
import jogamp.graph.font.JavaFontLoader;
import jogamp.graph.font.UbuntuFontLoader;
+/**
+ * The optional property <i>jogamp.graph.font.ctor</i>
+ * allows user to specify the {@link FontConstructor} implementation.
+ * <p>
+ * Default {@link FontConstructor} is {@link jogamp.graph.font.typecast.TypecastFontConstructor},
+ * i.e. using our internal <i>typecast</i> branch.
+ * </p>
+ */
public class FontFactory {
+ private static final String FontConstructorPropKey = "jogamp.graph.font.ctor";
+ private static final String DefaultFontConstructor = "jogamp.graph.font.typecast.TypecastFontConstructor";
+
/** Ubuntu is the default font family */
public static final int UBUNTU = 0;
-
+
/** Java fonts are optional */
public static final int JAVA = 1;
-
+
private static final FontConstructor fontConstr;
static {
@@ -53,18 +63,18 @@ public class FontFactory {
* For example:
* "jogamp.graph.font.typecast.TypecastFontFactory" (default)
* "jogamp.graph.font.ttf.TTFFontImpl"
- */
- String fontImplName = PropertyAccess.getProperty("FontImpl", true, SecurityUtil.getCommonAccessControlContext(FontFactory.class));
+ */
+ String fontImplName = PropertyAccess.getProperty(FontConstructorPropKey, true);
if(null == fontImplName) {
- fontImplName = "jogamp.graph.font.typecast.TypecastFontConstructor";
+ fontImplName = DefaultFontConstructor;
}
fontConstr = (FontConstructor) ReflectionUtil.createInstance(fontImplName, FontFactory.class.getClassLoader());
}
-
+
public static final FontSet getDefault() {
return get(UBUNTU);
}
-
+
public static final FontSet get(int font) {
switch (font) {
case JAVA:
@@ -73,20 +83,23 @@ public class FontFactory {
return UbuntuFontLoader.get();
}
}
-
+
public static final Font get(File file) throws IOException {
return fontConstr.create(file);
}
public static final Font get(final URLConnection conn) throws IOException {
return fontConstr.create(conn);
- }
-
+ }
+
public static boolean isPrintableChar( char c ) {
- Character.UnicodeBlock block = Character.UnicodeBlock.of( c );
- return (!Character.isISOControl(c)) &&
- c != 0 &&
- block != null &&
- block != Character.UnicodeBlock.SPECIALS;
- }
+ if( Character.isWhitespace(c) ) {
+ return true;
+ }
+ if( 0 == c || Character.isISOControl(c) ) {
+ return false;
+ }
+ final Character.UnicodeBlock block = Character.UnicodeBlock.of( c );
+ return block != null && block != Character.UnicodeBlock.SPECIALS;
+ }
}
diff --git a/src/jogl/classes/com/jogamp/graph/font/FontSet.java b/src/jogl/classes/com/jogamp/graph/font/FontSet.java
index d376922ab..17b8b2136 100644
--- a/src/jogl/classes/com/jogamp/graph/font/FontSet.java
+++ b/src/jogl/classes/com/jogamp/graph/font/FontSet.java
@@ -34,29 +34,29 @@ public interface FontSet {
/** Font family REGULAR **/
public static final int FAMILY_REGULAR = 0;
-
+
/** Font family LIGHT **/
public static final int FAMILY_LIGHT = 1;
-
+
/** Font family MEDIUM **/
public static final int FAMILY_MEDIUM = 2;
-
+
/** Font family CONDENSED **/
public static final int FAMILY_CONDENSED = 3;
-
+
/** Font family MONO **/
public static final int FAMILY_MONOSPACED = 4;
-
+
/** SERIF style/family bit flag. Fallback to Sans Serif. */
public static final int STYLE_SERIF = 1 << 1;
-
+
/** BOLD style bit flag */
public static final int STYLE_BOLD = 1 << 2;
-
+
/** ITALIC style bit flag */
public static final int STYLE_ITALIC = 1 << 3;
Font getDefault() throws IOException ;
-
+
Font get(int family, int stylebits) throws IOException ;
}
diff --git a/src/jogl/classes/com/jogamp/graph/geom/AABBox.java b/src/jogl/classes/com/jogamp/graph/geom/AABBox.java
deleted file mode 100644
index 834b1a9e4..000000000
--- a/src/jogl/classes/com/jogamp/graph/geom/AABBox.java
+++ /dev/null
@@ -1,327 +0,0 @@
-/**
- * Copyright 2010 JogAmp Community. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are
- * permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice, this list of
- * conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright notice, this list
- * of conditions and the following disclaimer in the documentation and/or other materials
- * provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
- * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * The views and conclusions contained in the software and documentation are those of the
- * authors and should not be interpreted as representing official policies, either expressed
- * or implied, of JogAmp Community.
- */
-package com.jogamp.graph.geom;
-
-import com.jogamp.graph.math.VectorUtil;
-
-/**
- * Axis Aligned Bounding Box. Defined by two 3D coordinates (low and high)
- * The low being the the lower left corner of the box, and the high being the upper
- * right corner of the box.
- *
- */
-public class AABBox implements Cloneable {
- private float[] low = new float[3];
- private float[] high = new float[3];
- private float[] center = new float[3];
-
- /** Create a Axis Aligned bounding box (AABBox)
- * where the low and and high MAX float Values.
- */
- public AABBox() {
- reset();
- }
-
- /** Create an AABBox specifying the coordinates
- * of the low and high
- * @param lx min x-coordinate
- * @param ly min y-coordnate
- * @param lz min z-coordinate
- * @param hx max x-coordinate
- * @param hy max y-coordinate
- * @param hz max z-coordinate
- */
- public AABBox(float lx, float ly, float lz,
- float hx, float hy, float hz)
- {
- reset();
- resize(lx, ly, lz);
- resize(hx, hy, hz);
-
- computeCenter();
- }
-
- /** Create a AABBox defining the low and high
- * @param low min xyz-coordinates
- * @param high max xyz-coordinates
- */
- public AABBox(float[] low, float[] high) {
- reset();
- resize(low[0],low[1],low[2]);
- resize(high[0],high[1],high[2]);
-
- computeCenter();
- }
-
- /** resets this box to the inverse low/high, allowing the next {@link #resize(float, float, float)} command to hit. */
- public final void reset() {
- setLow(Float.MAX_VALUE,Float.MAX_VALUE,Float.MAX_VALUE);
- setHigh(-1*Float.MAX_VALUE,-1*Float.MAX_VALUE,-1*Float.MAX_VALUE);
- center[0] = 0f;
- center[1] = 0f;
- center[2] = 0f;
- }
-
- /** Get the max xyz-coordinates
- * @return a float array containing the max xyz coordinates
- */
- public final float[] getHigh() {
- return high;
- }
-
- private final void setHigh(float hx, float hy, float hz) {
- this.high[0] = hx;
- this.high[1] = hy;
- this.high[2] = hz;
- }
-
- /** Get the min xyz-coordinates
- * @return a float array containing the min xyz coordinates
- */
- public final float[] getLow() {
- return low;
- }
-
- private final void setLow(float lx, float ly, float lz) {
- this.low[0] = lx;
- this.low[1] = ly;
- this.low[2] = lz;
- }
-
- /** Resize the AABBox to encapsulate another AABox
- * @param newBox AABBox to be encapsulated in
- */
- public final void resize(AABBox newBox) {
- float[] newLow = newBox.getLow();
- float[] newHigh = newBox.getHigh();
-
- /** test low */
- if (newLow[0] < low[0])
- low[0] = newLow[0];
- if (newLow[1] < low[1])
- low[1] = newLow[1];
- if (newLow[2] < low[2])
- low[2] = newLow[2];
-
- /** test high */
- if (newHigh[0] > high[0])
- high[0] = newHigh[0];
- if (newHigh[1] > high[1])
- high[1] = newHigh[1];
- if (newHigh[2] > high[2])
- high[2] = newHigh[2];
-
- computeCenter();
- }
-
- private final void computeCenter() {
- center[0] = (high[0] + low[0])/2;
- center[1] = (high[1] + low[1])/2;
- center[2] = (high[2] + low[2])/2;
- }
-
- /** Resize the AABBox to encapsulate the passed
- * xyz-coordinates.
- * @param x x-axis coordinate value
- * @param y y-axis coordinate value
- * @param z z-axis coordinate value
- */
- public final void resize(float x, float y, float z) {
- /** test low */
- if (x < low[0])
- low[0] = x;
- if (y < low[1])
- low[1] = y;
- if (z < low[2])
- low[2] = z;
-
- /** test high */
- if (x > high[0])
- high[0] = x;
- if (y > high[1])
- high[1] = y;
- if (z > high[2])
- high[2] = z;
-
- computeCenter();
- }
-
- /** Resize the AABBox to encapsulate the passed
- * xyz-coordinates.
- * @param xyz xyz-axis coordinate values
- * @param offset of the array
- */
- public final void resize(float[] xyz, int offset) {
- resize(xyz[0+offset], xyz[1+offset], xyz[2+offset]);
- }
-
- /** Check if the x & y coordinates are bounded/contained
- * by this AABBox
- * @param x x-axis coordinate value
- * @param y y-axis coordinate value
- * @return true if x belong to (low.x, high.x) and
- * y belong to (low.y, high.y)
- */
- public final boolean contains(float x, float y) {
- if(x<low[0] || x>high[0]){
- return false;
- }
- if(y<low[1]|| y>high[1]){
- return false;
- }
- return true;
- }
-
- /** Check if the xyz coordinates are bounded/contained
- * by this AABBox.
- * @param x x-axis coordinate value
- * @param y y-axis coordinate value
- * @param z z-axis coordinate value
- * @return true if x belong to (low.x, high.x) and
- * y belong to (low.y, high.y) and z belong to (low.z, high.z)
- */
- public final boolean contains(float x, float y, float z) {
- if(x<low[0] || x>high[0]){
- return false;
- }
- if(y<low[1]|| y>high[1]){
- return false;
- }
- if(z<low[2] || z>high[2]){
- return false;
- }
- return true;
- }
-
- /** Check if there is a common region between this AABBox and the passed
- * 2D region irrespective of z range
- * @param x lower left x-coord
- * @param y lower left y-coord
- * @param w width
- * @param h hight
- * @return true if this AABBox might have a common region with this 2D region
- */
- public final boolean intersects(float x, float y, float w, float h) {
- if (w <= 0 || h <= 0) {
- return false;
- }
-
- final float _w = getWidth();
- final float _h = getHeight();
- if (_w <= 0 || _h <= 0) {
- return false;
- }
-
- final float x0 = getMinX();
- final float y0 = getMinY();
- return (x + w > x0 &&
- y + h > y0 &&
- x < x0 + _w &&
- y < y0 + _h);
- }
-
-
- /** Get the size of the Box where the size is represented by the
- * length of the vector between low and high.
- * @return a float representing the size of the AABBox
- */
- public final float getSize() {
- return VectorUtil.computeLength(low, high);
- }
-
- /**Get the Center of the AABBox
- * @return the xyz-coordinates of the center of the AABBox
- */
- public final float[] getCenter() {
- return center;
- }
-
- /** Scale the AABBox by a constant
- * @param size a constant float value
- */
- public final void scale(float size) {
- float[] diffH = new float[3];
- diffH[0] = high[0] - center[0];
- diffH[1] = high[1] - center[1];
- diffH[2] = high[2] - center[2];
-
- diffH = VectorUtil.scale(diffH, size);
-
- float[] diffL = new float[3];
- diffL[0] = low[0] - center[0];
- diffL[1] = low[1] - center[1];
- diffL[2] = low[2] - center[2];
-
- diffL = VectorUtil.scale(diffL, size);
-
- high = VectorUtil.vectorAdd(center, diffH);
- low = VectorUtil.vectorAdd(center, diffL);
- }
-
- public final float getMinX() {
- return low[0];
- }
-
- public final float getMinY() {
- return low[1];
- }
-
- public final float getWidth(){
- return high[0] - low[0];
- }
-
- public final float getHeight() {
- return high[1] - low[1];
- }
-
- public final float getDepth() {
- return high[2] - low[2];
- }
-
- public final AABBox clone() {
- return new AABBox(this.low, this.high);
- }
-
- public final boolean equals(Object obj) {
- if( obj == this ) {
- return true;
- }
- if( null == obj || !(obj instanceof AABBox) ) {
- return false;
- }
- final AABBox other = (AABBox) obj;
- return VectorUtil.checkEquality(low, other.low) &&
- VectorUtil.checkEquality(high, other.high) ;
- }
-
- public final String toString() {
- return "[ dim "+getWidth()+" x "+getHeight()+" x "+getDepth()+
- ", box "+low[0]+" / "+low[1]+" / "+low[2]+" .. "+high[0]+" / "+high[1]+" / "+high[2]+
- ", ctr "+center[0]+" / "+center[1]+" / "+center[2]+" ]";
- }
-}
diff --git a/src/jogl/classes/com/jogamp/graph/geom/Outline.java b/src/jogl/classes/com/jogamp/graph/geom/Outline.java
index 5030488cc..77a318078 100644
--- a/src/jogl/classes/com/jogamp/graph/geom/Outline.java
+++ b/src/jogl/classes/com/jogamp/graph/geom/Outline.java
@@ -30,17 +30,18 @@ package com.jogamp.graph.geom;
import java.util.ArrayList;
import com.jogamp.graph.geom.Vertex;
-import com.jogamp.graph.math.VectorUtil;
+import com.jogamp.opengl.math.VectorUtil;
+import com.jogamp.opengl.math.geom.AABBox;
/** Define a single continuous stroke by control vertices.
- * The vertices define the shape of the region defined by this
+ * The vertices define the shape of the region defined by this
* outline. The Outline can contain a list of off-curve and on-curve
* vertices which define curved regions.
- *
+ *
* Note: An outline should be closed to be rendered as a region.
- *
+ *
* @see OutlineShape, Region
*/
public class Outline implements Cloneable, Comparable<Outline> {
@@ -54,7 +55,7 @@ public class Outline implements Cloneable, Comparable<Outline> {
* An outline can contain off Curve vertices which define curved
* regions in the outline.
*/
- public Outline() {
+ public Outline() {
}
public final int getVertexCount() {
@@ -63,7 +64,7 @@ public class Outline implements Cloneable, Comparable<Outline> {
/** Appends a vertex to the outline loop/strip.
* @param vertex Vertex to be added
- * @throws NullPointerException if the {@link Vertex} element is null
+ * @throws NullPointerException if the {@link Vertex} element is null
*/
public final void addVertex(Vertex vertex) throws NullPointerException {
addVertex(vertices.size(), vertex);
@@ -72,7 +73,7 @@ public class Outline implements Cloneable, Comparable<Outline> {
/** Insert the {@link Vertex} element at the given {@code position} to the outline loop/strip.
* @param position of the added Vertex
* @param vertex Vertex object to be added
- * @throws NullPointerException if the {@link Vertex} element is null
+ * @throws NullPointerException if the {@link Vertex} element is null
* @throws IndexOutOfBoundsException if position is out of range (position < 0 || position > getVertexNumber())
*/
public final void addVertex(int position, Vertex vertex) throws NullPointerException, IndexOutOfBoundsException {
@@ -87,10 +88,10 @@ public class Outline implements Cloneable, Comparable<Outline> {
/** Replaces the {@link Vertex} element at the given {@code position}.
* <p>Sets the bounding box dirty, hence a next call to {@link #getBounds()} will validate it.</p>
- *
+ *
* @param position of the replaced Vertex
- * @param vertex replacement Vertex object
- * @throws NullPointerException if the {@link Outline} element is null
+ * @param vertex replacement Vertex object
+ * @throws NullPointerException if the {@link Outline} element is null
* @throws IndexOutOfBoundsException if position is out of range (position < 0 || position >= getVertexNumber())
*/
public final void setVertex(int position, Vertex vertex) throws NullPointerException, IndexOutOfBoundsException {
@@ -111,12 +112,12 @@ public class Outline implements Cloneable, Comparable<Outline> {
/** Removes the {@link Vertex} element at the given {@code position}.
* <p>Sets the bounding box dirty, hence a next call to {@link #getBounds()} will validate it.</p>
- *
+ *
* @param position of the to be removed Vertex
* @throws IndexOutOfBoundsException if position is out of range (position < 0 || position >= getVertexNumber())
*/
public final Vertex removeVertex(int position) throws IndexOutOfBoundsException {
- dirtyBBox = true;
+ dirtyBBox = true;
return vertices.remove(position);
}
@@ -138,7 +139,7 @@ public class Outline implements Cloneable, Comparable<Outline> {
/**
* Use the given outline loop/strip.
* <p>Validates the bounding box.</p>
- *
+ *
* @param vertices the new outline loop/strip
*/
public final void setVertices(ArrayList<Vertex> vertices) {
@@ -151,7 +152,7 @@ public class Outline implements Cloneable, Comparable<Outline> {
}
/** define if this outline is closed or not.
- * if set to closed, checks if the last vertex is
+ * if set to closed, checks if the last vertex is
* equal to the first vertex. If not Equal adds a
* vertex at the end to the list.
* @param closed
@@ -169,9 +170,10 @@ public class Outline implements Cloneable, Comparable<Outline> {
}
/** Compare two outlines with Bounding Box area
- * as criteria.
+ * as criteria.
* @see java.lang.Comparable#compareTo(java.lang.Object)
*/
+ @Override
public final int compareTo(Outline outline) {
float size = getBounds().getSize();
float newSize = outline.getBounds().getSize();
@@ -197,19 +199,20 @@ public class Outline implements Cloneable, Comparable<Outline> {
validateBoundingBox();
}
return bbox;
- }
+ }
/**
* @param obj the Object to compare this Outline with
- * @return true if {@code obj} is an Outline, not null, equals bounds and equal vertices in the same order
+ * @return true if {@code obj} is an Outline, not null, equals bounds and equal vertices in the same order
*/
+ @Override
public boolean equals(Object obj) {
if( obj == this) {
return true;
}
if( null == obj || !(obj instanceof Outline) ) {
return false;
- }
+ }
final Outline o = (Outline) obj;
if(getVertexCount() != o.getVertexCount()) {
return false;
@@ -228,6 +231,7 @@ public class Outline implements Cloneable, Comparable<Outline> {
/**
* @return deep clone of this Outline
*/
+ @Override
public Outline clone() {
Outline o;
try {
@@ -239,5 +243,5 @@ public class Outline implements Cloneable, Comparable<Outline> {
o.vertices.add(vertices.get(i).clone());
}
return o;
- }
+ }
}
diff --git a/src/jogl/classes/com/jogamp/graph/geom/Triangle.java b/src/jogl/classes/com/jogamp/graph/geom/Triangle.java
index fb34de221..a01cd834f 100644
--- a/src/jogl/classes/com/jogamp/graph/geom/Triangle.java
+++ b/src/jogl/classes/com/jogamp/graph/geom/Triangle.java
@@ -48,11 +48,11 @@ public class Triangle {
public Vertex[] getVertices() {
return vertices;
}
-
+
public boolean isEdgesBoundary() {
return boundaryEdges[0] || boundaryEdges[1] || boundaryEdges[2];
}
-
+
public boolean isVerticesBoundary() {
return boundaryVertices[0] || boundaryVertices[1] || boundaryVertices[2];
}
@@ -60,11 +60,11 @@ public class Triangle {
public void setEdgesBoundary(boolean[] boundary) {
this.boundaryEdges = boundary;
}
-
+
public boolean[] getEdgeBoundary() {
return boundaryEdges;
}
-
+
public boolean[] getVerticesBoundary() {
return boundaryVertices;
}
@@ -72,7 +72,8 @@ public class Triangle {
public void setVerticesBoundary(boolean[] boundaryVertices) {
this.boundaryVertices = boundaryVertices;
}
-
+
+ @Override
public String toString() {
return "Tri ID: " + id + "\n" + vertices[0] + "\n" + vertices[1] + "\n" + vertices[2];
}
diff --git a/src/jogl/classes/com/jogamp/graph/geom/Vertex.java b/src/jogl/classes/com/jogamp/graph/geom/Vertex.java
index 3080f32cc..994253f71 100644
--- a/src/jogl/classes/com/jogamp/graph/geom/Vertex.java
+++ b/src/jogl/classes/com/jogamp/graph/geom/Vertex.java
@@ -27,27 +27,27 @@
*/
package com.jogamp.graph.geom;
+import com.jogamp.opengl.math.Vert3fImmutable;
+
/**
- * A Vertex with custom memory layout using custom factory.
+ * A Vertex with custom memory layout using custom factory.
*/
-public interface Vertex extends Cloneable {
+public interface Vertex extends Vert3fImmutable, Cloneable {
public static interface Factory <T extends Vertex> {
T create();
T create(float x, float y, float z, boolean onCurve);
- T create(float[] coordsBuffer, int offset, int length, boolean onCurve);
+ T create(float[] coordsBuffer, int offset, int length, boolean onCurve);
}
-
+
void setCoord(float x, float y, float z);
/**
* @see System#arraycopy(Object, int, Object, int, int) for thrown IndexOutOfBoundsException
*/
void setCoord(float[] coordsBuffer, int offset, int length);
-
- float[] getCoord();
void setX(float x);
@@ -55,35 +55,30 @@ public interface Vertex extends Cloneable {
void setZ(float z);
- float getX();
-
- float getY();
-
- float getZ();
-
boolean isOnCurve();
void setOnCurve(boolean onCurve);
int getId();
-
+
void setId(int id);
-
+
float[] getTexCoord();
-
+
void setTexCoord(float s, float t);
-
+
/**
* @see System#arraycopy(Object, int, Object, int, int) for thrown IndexOutOfBoundsException
*/
void setTexCoord(float[] texCoordsBuffer, int offset, int length);
-
+
/**
* @param obj the Object to compare this Vertex with
- * @return true if {@code obj} is a Vertex and not null, on-curve flag is equal and has same vertex- and tex-coords.
+ * @return true if {@code obj} is a Vertex and not null, on-curve flag is equal and has same vertex- and tex-coords.
*/
+ @Override
boolean equals(Object obj);
-
+
/**
* @return deep clone of this Vertex
*/
diff --git a/src/jogl/classes/com/jogamp/graph/geom/opengl/SVertex.java b/src/jogl/classes/com/jogamp/graph/geom/opengl/SVertex.java
index 9dade17e9..b27604a44 100644
--- a/src/jogl/classes/com/jogamp/graph/geom/opengl/SVertex.java
+++ b/src/jogl/classes/com/jogamp/graph/geom/opengl/SVertex.java
@@ -28,7 +28,7 @@
package com.jogamp.graph.geom.opengl;
import com.jogamp.graph.geom.Vertex;
-import com.jogamp.graph.math.VectorUtil;
+import com.jogamp.opengl.math.VectorUtil;
/** A Simple Vertex Implementation. Where the coordinates, and other attributes are
* float based, and the coordinates and texture coordinates are saved in two float arrays.
@@ -39,25 +39,28 @@ public class SVertex implements Vertex {
protected float[] coord = new float[3];
protected boolean onCurve;
private float[] texCoord = new float[2];
-
+
static final Factory factory = new Factory();
-
- public static Factory factory() { return factory; }
-
+
+ public static Factory factory() { return factory; }
+
public static class Factory implements Vertex.Factory<SVertex> {
+ @Override
public SVertex create() {
return new SVertex();
}
+ @Override
public SVertex create(float x, float y, float z, boolean onCurve) {
return new SVertex(x, y, z, onCurve);
}
+ @Override
public SVertex create(float[] coordsBuffer, int offset, int length, boolean onCurve) {
return new SVertex(coordsBuffer, offset, length, onCurve);
- }
+ }
}
-
+
public SVertex() {
}
@@ -65,73 +68,92 @@ public class SVertex implements Vertex {
setCoord(x, y, z);
setOnCurve(onCurve);
}
-
+
public SVertex(float[] coordsBuffer, int offset, int length, boolean onCurve) {
setCoord(coordsBuffer, offset, length);
setOnCurve(onCurve);
}
-
- public SVertex(float[] coordsBuffer, int offset, int length,
+
+ public SVertex(float[] coordsBuffer, int offset, int length,
float[] texCoordsBuffer, int offsetTC, int lengthTC, boolean onCurve) {
setCoord(coordsBuffer, offset, length);
setTexCoord(texCoordsBuffer, offsetTC, lengthTC);
setOnCurve(onCurve);
}
-
+
+ @Override
public final void setCoord(float x, float y, float z) {
this.coord[0] = x;
this.coord[1] = y;
this.coord[2] = z;
}
+ @Override
public final void setCoord(float[] coordsBuffer, int offset, int length) {
System.arraycopy(coordsBuffer, offset, coord, 0, length);
}
-
+
+ @Override
+ public int getCoordCount() {
+ return 3;
+ }
+
+ @Override
public final float[] getCoord() {
return coord;
}
+ @Override
public final void setX(float x) {
this.coord[0] = x;
}
+ @Override
public final void setY(float y) {
this.coord[1] = y;
}
+ @Override
public final void setZ(float z) {
this.coord[2] = z;
}
+ @Override
public final float getX() {
return this.coord[0];
}
+ @Override
public final float getY() {
return this.coord[1];
}
+ @Override
public final float getZ() {
return this.coord[2];
}
+ @Override
public final boolean isOnCurve() {
return onCurve;
}
+ @Override
public final void setOnCurve(boolean onCurve) {
this.onCurve = onCurve;
}
+ @Override
public final int getId(){
return id;
}
-
+
+ @Override
public final void setId(int id){
this.id = id;
}
-
+
+ @Override
public boolean equals(Object obj) {
if( obj == this) {
return true;
@@ -140,34 +162,39 @@ public class SVertex implements Vertex {
return false;
}
final Vertex v = (Vertex) obj;
- return this == v ||
- isOnCurve() == v.isOnCurve() &&
+ return this == v ||
+ isOnCurve() == v.isOnCurve() &&
VectorUtil.checkEqualityVec2(getTexCoord(), v.getTexCoord()) &&
VectorUtil.checkEquality(getCoord(), v.getCoord()) ;
}
-
+
+ @Override
public final float[] getTexCoord() {
return texCoord;
}
+ @Override
public final void setTexCoord(float s, float t) {
this.texCoord[0] = s;
this.texCoord[1] = t;
}
+ @Override
public final void setTexCoord(float[] texCoordsBuffer, int offset, int length) {
System.arraycopy(texCoordsBuffer, offset, texCoord, 0, length);
}
-
+
/**
* @return deep clone of this Vertex, but keeping the id blank
*/
+ @Override
public SVertex clone(){
return new SVertex(this.coord, 0, 3, this.texCoord, 0, 2, this.onCurve);
}
-
+
+ @Override
public String toString() {
- return "[ID: " + id + ", onCurve: " + onCurve +
+ return "[ID: " + id + ", onCurve: " + onCurve +
": p " + coord[0] + ", " + coord[1] + ", " + coord[2] +
", t " + texCoord[0] + ", " + texCoord[1] + "]";
}
diff --git a/src/jogl/classes/com/jogamp/graph/math/Quaternion.java b/src/jogl/classes/com/jogamp/graph/math/Quaternion.java
deleted file mode 100755
index adaf073e3..000000000
--- a/src/jogl/classes/com/jogamp/graph/math/Quaternion.java
+++ /dev/null
@@ -1,382 +0,0 @@
-/**
- * Copyright 2010 JogAmp Community. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are
- * permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice, this list of
- * conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright notice, this list
- * of conditions and the following disclaimer in the documentation and/or other materials
- * provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
- * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * The views and conclusions contained in the software and documentation are those of the
- * authors and should not be interpreted as representing official policies, either expressed
- * or implied, of JogAmp Community.
- */
-package com.jogamp.graph.math;
-
-import jogamp.graph.math.MathFloat;
-
-public class Quaternion {
- protected float x,y,z,w;
-
- public Quaternion(){
-
- }
-
- public Quaternion(float x, float y, float z, float w) {
- this.x = x;
- this.y = y;
- this.z = z;
- this.w = w;
- }
-
- /** Constructor to create a rotation based quaternion from two vectors
- * @param vector1
- * @param vector2
- */
- public Quaternion(float[] vector1, float[] vector2)
- {
- float theta = (float)MathFloat.acos(dot(vector1, vector2));
- float[] cross = cross(vector1,vector2);
- cross = normalizeVec(cross);
-
- this.x = (float)MathFloat.sin(theta/2)*cross[0];
- this.y = (float)MathFloat.sin(theta/2)*cross[1];
- this.z = (float)MathFloat.sin(theta/2)*cross[2];
- this.w = (float)MathFloat.cos(theta/2);
- this.normalize();
- }
-
- /** Transform the rotational quaternion to axis based rotation angles
- * @return new float[4] with ,theta,Rx,Ry,Rz
- */
- public float[] toAxis()
- {
- float[] vec = new float[4];
- float scale = (float)MathFloat.sqrt(x * x + y * y + z * z);
- vec[0] =(float) MathFloat.acos(w) * 2.0f;
- vec[1] = x / scale;
- vec[2] = y / scale;
- vec[3] = z / scale;
- return vec;
- }
-
- /** Normalize a vector
- * @param vector input vector
- * @return normalized vector
- */
- private float[] normalizeVec(float[] vector)
- {
- float[] newVector = new float[3];
-
- float d = MathFloat.sqrt(vector[0]*vector[0] + vector[1]*vector[1] + vector[2]*vector[2]);
- if(d> 0.0f)
- {
- newVector[0] = vector[0]/d;
- newVector[1] = vector[1]/d;
- newVector[2] = vector[2]/d;
- }
- return newVector;
- }
- /** compute the dot product of two points
- * @param vec1 vector 1
- * @param vec2 vector 2
- * @return the dot product as float
- */
- private float dot(float[] vec1, float[] vec2)
- {
- return (vec1[0]*vec2[0] + vec1[1]*vec2[1] + vec1[2]*vec2[2]);
- }
- /** cross product vec1 x vec2
- * @param vec1 vector 1
- * @param vec2 vecttor 2
- * @return the resulting vector
- */
- private float[] cross(float[] vec1, float[] vec2)
- {
- float[] out = new float[3];
-
- out[0] = vec2[2]*vec1[1] - vec2[1]*vec1[2];
- out[1] = vec2[0]*vec1[2] - vec2[2]*vec1[0];
- out[2] = vec2[1]*vec1[0] - vec2[0]*vec1[1];
-
- return out;
- }
- public float getW() {
- return w;
- }
- public void setW(float w) {
- this.w = w;
- }
- 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;
- }
-
- /** Add a quaternion
- * @param q quaternion
- */
- public void add(Quaternion q)
- {
- x+=q.x;
- y+=q.y;
- z+=q.z;
- }
-
- /** Subtract a quaternion
- * @param q quaternion
- */
- public void subtract(Quaternion q)
- {
- x-=q.x;
- y-=q.y;
- z-=q.z;
- }
-
- /** Divide a quaternion by a constant
- * @param n a float to divide by
- */
- public void divide(float n)
- {
- x/=n;
- y/=n;
- z/=n;
- }
-
- /** Multiply this quaternion by
- * the param 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);
-
- float x1 = w*q.z + q.w*z + y*q.z - z*q.y;
- float y1 = w*q.x + q.w*x + z*q.x - x*q.z;
- float z1 = w*q.y + q.w*y + x*q.y - y*q.x;
-
- w = w1;
- x = x1;
- y = y1;
- z = z1;
- }
-
- /** Multiply a quaternion by a constant
- * @param n a float constant
- */
- public void mult(float n)
- {
- x*=n;
- y*=n;
- z*=n;
- }
-
- /** Normalize a quaternion required if
- * to be used as a rotational quaternion
- */
- public void normalize()
- {
- float norme = (float)MathFloat.sqrt(w*w + x*x + y*y + z*z);
- if (norme == 0.0f)
- {
- w = 1.0f;
- x = y = z = 0.0f;
- }
- else
- {
- float recip = 1.0f/norme;
-
- w *= recip;
- x *= recip;
- y *= recip;
- z *= recip;
- }
- }
-
- /** Invert the quaternion If rotational,
- * will produce a the inverse rotation
- */
- public void inverse()
- {
- float norm = w*w + x*x + y*y + z*z;
-
- float recip = 1.0f/norm;
-
- w *= recip;
- x = -1*x*recip;
- y = -1*y*recip;
- z = -1*z*recip;
- }
-
- /** Transform this quaternion to a
- * 4x4 column matrix representing the rotation
- * @return new float[16] column matrix 4x4
- */
- public float[] toMatrix()
- {
- 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;
- matrix[3] = 0;
-
- matrix[4] = 2*x*y - 2*w*z;
- matrix[5] = 1.0f - 2*x*x - 2*z*z;
- matrix[6] = 2*y*z + 2*w*x;
- matrix[7] = 0;
-
- matrix[8] = 2*x*z + 2*w*y;
- matrix[9] = 2*y*z - 2*w*x;
- matrix[10] = 1.0f - 2*x*x - 2*y*y;
- matrix[11] = 0;
-
- matrix[12] = 0;
- matrix[13] = 0;
- matrix[14] = 0;
- matrix[15] = 1;
- return matrix;
- }
-
- /** Set this quaternion from a Sphereical interpolation
- * of two param quaternion, used mostly for rotational animation
- * @param a initial quaternion
- * @param b target quaternion
- * @param t float between 0 and 1 representing interp.
- */
- public void slerp(Quaternion a,Quaternion b, float t)
- {
- float omega, cosom, sinom, sclp, sclq;
- cosom = a.x*b.x + a.y*b.y + a.z*b.z + a.w*b.w;
- if ((1.0f+cosom) > MathFloat.E) {
- if ((1.0f-cosom) > MathFloat.E) {
- omega = (float)MathFloat.acos(cosom);
- sinom = (float)MathFloat.sin(omega);
- sclp = (float)MathFloat.sin((1.0f-t)*omega) / sinom;
- sclq = (float)MathFloat.sin(t*omega) / sinom;
- }
- else {
- sclp = 1.0f - t;
- sclq = t;
- }
- x = sclp*a.x + sclq*b.x;
- y = sclp*a.y + sclq*b.y;
- z = sclp*a.z + sclq*b.z;
- w = sclp*a.w + sclq*b.w;
- }
- else {
- x =-a.y;
- y = a.x;
- z =-a.w;
- w = a.z;
- sclp = MathFloat.sin((1.0f-t) * MathFloat.PI * 0.5f);
- sclq = MathFloat.sin(t * MathFloat.PI * 0.5f);
- x = sclp*a.x + sclq*b.x;
- y = sclp*a.y + sclq*b.y;
- z = sclp*a.z + sclq*b.z;
- }
- }
-
- /** Check if this quaternion is empty, ie (0,0,0,1)
- * @return true if empty, false otherwise
- */
- public boolean isEmpty()
- {
- if (w==1 && x==0 && y==0 && z==0)
- return true;
- return false;
- }
-
- /** Check if this quaternion represents an identity
- * matrix, for rotation.
- * @return true if it is an identity rep., false otherwise
- */
- public boolean isIdentity()
- {
- if (w==0 && x==0 && y==0 && z==0)
- return true;
- return false;
- }
-
- /** compute the quaternion from a 3x3 column matrix
- * @param m 3x3 column matrix
- */
- public void setFromMatrix(float[] m) {
- float T= m[0] + m[4] + m[8] + 1;
- if (T>0){
- float S = 0.5f / (float)MathFloat.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 = MathFloat.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 = MathFloat.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 = MathFloat.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;
- z = 0.25f * S;
- }
- }
- }
-
- /** Check if the the 3x3 matrix (param) is in fact
- * an affine rotational matrix
- * @param m 3x3 column matrix
- * @return true if representing a rotational matrix, false otherwise
- */
- public boolean isRotationMatrix(float[] m) {
- double epsilon = 0.01; // margin to allow for rounding errors
- if (MathFloat.abs(m[0]*m[3] + m[3]*m[4] + m[6]*m[7]) > epsilon) return false;
- if (MathFloat.abs(m[0]*m[2] + m[3]*m[5] + m[6]*m[8]) > epsilon) return false;
- if (MathFloat.abs(m[1]*m[2] + m[4]*m[5] + m[7]*m[8]) > epsilon) return false;
- if (MathFloat.abs(m[0]*m[0] + m[3]*m[3] + m[6]*m[6] - 1) > epsilon) return false;
- if (MathFloat.abs(m[1]*m[1] + m[4]*m[4] + m[7]*m[7] - 1) > epsilon) return false;
- if (MathFloat.abs(m[2]*m[2] + m[5]*m[5] + m[8]*m[8] - 1) > epsilon) return false;
- return (MathFloat.abs(determinant(m)-1) < epsilon);
- }
- private float determinant(float[] m) {
- return m[0]*m[4]*m[8] + m[3]*m[7]*m[2] + m[6]*m[1]*m[5] - m[0]*m[7]*m[5] - m[3]*m[1]*m[8] - m[6]*m[4]*m[2];
- }
-}
diff --git a/src/jogl/classes/com/jogamp/graph/math/VectorUtil.java b/src/jogl/classes/com/jogamp/graph/math/VectorUtil.java
deleted file mode 100755
index 524ca1171..000000000
--- a/src/jogl/classes/com/jogamp/graph/math/VectorUtil.java
+++ /dev/null
@@ -1,544 +0,0 @@
-/**
- * Copyright 2010 JogAmp Community. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are
- * permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice, this list of
- * conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright notice, this list
- * of conditions and the following disclaimer in the documentation and/or other materials
- * provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
- * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * The views and conclusions contained in the software and documentation are those of the
- * authors and should not be interpreted as representing official policies, either expressed
- * or implied, of JogAmp Community.
- */
-package com.jogamp.graph.math;
-
-import java.util.ArrayList;
-
-import jogamp.graph.math.MathFloat;
-
-import com.jogamp.graph.geom.Vertex;
-
-public class VectorUtil {
-
- public enum Winding {
- CW(-1), CCW(1);
-
- public final int dir;
-
- Winding(int dir) {
- this.dir = dir;
- }
- }
-
- public static final int COLLINEAR = 0;
-
- /** compute the dot product of two points
- * @param vec1 vector 1
- * @param vec2 vector 2
- * @return the dot product as float
- */
- public static float dot(float[] vec1, float[] vec2)
- {
- return (vec1[0]*vec2[0] + vec1[1]*vec2[1] + vec1[2]*vec2[2]);
- }
- /** Normalize a vector
- * @param vector input vector
- * @return normalized vector
- */
- public static float[] normalize(float[] vector)
- {
- float[] newVector = new float[3];
-
- float d = MathFloat.sqrt(vector[0]*vector[0] + vector[1]*vector[1] + vector[2]*vector[2]);
- if(d> 0.0f)
- {
- newVector[0] = vector[0]/d;
- newVector[1] = vector[1]/d;
- newVector[2] = vector[2]/d;
- }
- return newVector;
- }
-
- /** Scales a vector by param
- * @param vector input vector
- * @param scale constant to scale by
- * @return scaled vector
- */
- public static float[] scale(float[] vector, float scale)
- {
- float[] newVector = new float[3];
-
- newVector[0] = vector[0]*scale;
- newVector[1] = vector[1]*scale;
- newVector[2] = vector[2]*scale;
- return newVector;
- }
-
- /** Adds to vectors
- * @param v1 vector 1
- * @param v2 vector 2
- * @return v1 + v2
- */
- public static float[] vectorAdd(float[] v1, float[] v2)
- {
- float[] newVector = new float[3];
-
- newVector[0] = v1[0] + v2[0];
- newVector[1] = v1[1] + v2[1];
- newVector[2] = v1[2] + v2[2];
- return newVector;
- }
-
- /** cross product vec1 x vec2
- * @param vec1 vector 1
- * @param vec2 vecttor 2
- * @return the resulting vector
- */
- public static float[] cross(float[] vec1, float[] vec2)
- {
- float[] out = new float[3];
-
- out[0] = vec2[2]*vec1[1] - vec2[1]*vec1[2];
- out[1] = vec2[0]*vec1[2] - vec2[2]*vec1[0];
- out[2] = vec2[1]*vec1[0] - vec2[0]*vec1[1];
-
- return out;
- }
-
- /** Column Matrix Vector multiplication
- * @param colMatrix column matrix (4x4)
- * @param vec vector(x,y,z)
- * @return result new float[3]
- */
- public static float[] colMatrixVectorMult(float[] colMatrix, float[] vec)
- {
- float[] out = new float[3];
-
- out[0] = vec[0]*colMatrix[0] + vec[1]*colMatrix[4] + vec[2]*colMatrix[8] + colMatrix[12];
- out[1] = vec[0]*colMatrix[1] + vec[1]*colMatrix[5] + vec[2]*colMatrix[9] + colMatrix[13];
- out[2] = vec[0]*colMatrix[2] + vec[1]*colMatrix[6] + vec[2]*colMatrix[10] + colMatrix[14];
-
- return out;
- }
-
- /** Matrix Vector multiplication
- * @param rawMatrix column matrix (4x4)
- * @param vec vector(x,y,z)
- * @return result new float[3]
- */
- public static float[] rowMatrixVectorMult(float[] rawMatrix, float[] vec)
- {
- float[] out = new float[3];
-
- out[0] = vec[0]*rawMatrix[0] + vec[1]*rawMatrix[1] + vec[2]*rawMatrix[2] + rawMatrix[3];
- out[1] = vec[0]*rawMatrix[4] + vec[1]*rawMatrix[5] + vec[2]*rawMatrix[6] + rawMatrix[7];
- out[2] = vec[0]*rawMatrix[8] + vec[1]*rawMatrix[9] + vec[2]*rawMatrix[10] + rawMatrix[11];
-
- return out;
- }
-
- /** Calculate the midpoint of two values
- * @param p1 first value
- * @param p2 second vale
- * @return midpoint
- */
- public static float mid(float p1, float p2)
- {
- return (p1+p2)/2.0f;
- }
- /** Calculate the midpoint of two points
- * @param p1 first point
- * @param p2 second point
- * @return midpoint
- */
- public static float[] mid(float[] p1, float[] p2)
- {
- float[] midPoint = new float[3];
- midPoint[0] = (p1[0] + p2[0])*0.5f;
- midPoint[1] = (p1[1] + p2[1])*0.5f;
- midPoint[2] = (p1[2] + p2[2])*0.5f;
-
- return midPoint;
- }
- /** Compute the norm of a vector
- * @param vec vector
- * @return vorm
- */
- public static float norm(float[] vec)
- {
- return MathFloat.sqrt(vec[0]*vec[0] + vec[1]*vec[1] + vec[2]*vec[2]);
- }
- /** Compute distance between 2 points
- * @param p0 a ref point on the line
- * @param vec vector representing the direction of the line
- * @param point the point to compute the relative distance of
- * @return distance float
- */
- public static float computeLength(float[] p0, float[] point)
- {
- float[] w = new float[]{point[0]-p0[0],point[1]-p0[1],point[2]-p0[2]};
-
- float distance = MathFloat.sqrt(w[0]*w[0] + w[1]*w[1] + w[2]*w[2]);
-
- return distance;
- }
-
- /**Check equality of 2 vec3 vectors
- * @param v1 vertex 1
- * @param v2 vertex 2
- * @return
- */
- public static boolean checkEquality(float[] v1, float[] v2)
- {
- if(Float.compare(v1[0], v2[0]) == 0 &&
- Float.compare(v1[1], v2[1]) == 0 &&
- Float.compare(v1[2], v2[2]) == 0 )
- return true;
- return false;
- }
-
- /**Check equality of 2 vec2 vectors
- * @param v1 vertex 1
- * @param v2 vertex 2
- * @return
- */
- public static boolean checkEqualityVec2(float[] v1, float[] v2)
- {
- if(Float.compare(v1[0], v2[0]) == 0 &&
- Float.compare(v1[1], v2[1]) == 0)
- return true;
- return false;
- }
-
- /** Compute the determinant of 3 vectors
- * @param a vector 1
- * @param b vector 2
- * @param c vector 3
- * @return the determinant value
- */
- public static float computeDeterminant(float[] a, float[] b, float[] c)
- {
- float area = a[0]*b[1]*c[2] + a[1]*b[2]*c[0] + a[2]*b[0]*c[1] - a[0]*b[2]*c[1] - a[1]*b[0]*c[2] - a[2]*b[1]*c[0];
- return area;
- }
-
- /** Check if three vertices are colliniear
- * @param v1 vertex 1
- * @param v2 vertex 2
- * @param v3 vertex 3
- * @return true if collinear, false otherwise
- */
- public static boolean checkCollinear(float[] v1, float[] v2, float[] v3)
- {
- return (computeDeterminant(v1, v2, v3) == VectorUtil.COLLINEAR);
- }
-
- /** Compute Vector
- * @param vector storage for resulting Vector V1V2
- * @param v1 vertex 1
- * @param v2 vertex2 2
- */
- public static void computeVector(float[] vector, float[] v1, float[] v2)
- {
- vector[0] = v2[0] - v1[0];
- vector[1] = v2[1] - v1[1];
- vector[2] = v2[2] - v1[2];
- }
-
- /** Check if vertices in triangle circumcircle
- * @param a triangle vertex 1
- * @param b triangle vertex 2
- * @param c triangle vertex 3
- * @param d vertex in question
- * @return true if the vertex d is inside the circle defined by the
- * vertices a, b, c. from paper by Guibas and Stolfi (1985).
- */
- public static boolean inCircle(Vertex a, Vertex b, Vertex c, Vertex d){
- final float[] A = a.getCoord();
- final float[] B = b.getCoord();
- final float[] C = c.getCoord();
- final float[] D = d.getCoord();
- return (A[0] * A[0] + A[1] * A[1]) * triArea(B, C, D) -
- (B[0] * B[0] + B[1] * B[1]) * triArea(A, C, D) +
- (C[0] * C[0] + C[1] * C[1]) * triArea(A, B, D) -
- (D[0] * D[0] + D[1] * D[1]) * triArea(A, B, C) > 0;
- }
-
- /** Computes oriented area of a triangle
- * @param a first vertex
- * @param b second vertex
- * @param c third vertex
- * @return compute twice the area of the oriented triangle (a,b,c), the area
- * is positive if the triangle is oriented counterclockwise.
- */
- public static float triArea(Vertex a, Vertex b, Vertex c){
- final float[] A = a.getCoord();
- final float[] B = b.getCoord();
- final float[] C = c.getCoord();
- return (B[0] - A[0]) * (C[1] - A[1]) - (B[1] - A[1])*(C[0] - A[0]);
- }
-
- /** Computes oriented area of a triangle
- * @param A first vertex
- * @param B second vertex
- * @param C third vertex
- * @return compute twice the area of the oriented triangle (a,b,c), the area
- * is positive if the triangle is oriented counterclockwise.
- */
- public static float triArea(float[] A, float[] B, float[] C){
- return (B[0] - A[0]) * (C[1] - A[1]) - (B[1] - A[1])*(C[0] - A[0]);
- }
-
- /** Check if a vertex is in triangle using
- * barycentric coordinates computation.
- * @param a first triangle vertex
- * @param b second triangle vertex
- * @param c third triangle vertex
- * @param p the vertex in question
- * @return true if p is in triangle (a, b, c), false otherwise.
- */
- public static boolean vertexInTriangle(float[] a, float[] b, float[] c,
- float[] p,
- float[] ac, float[] ab, float[] ap){
- // Compute vectors
- computeVector(ac, a, c); //v0
- computeVector(ab, a, b); //v1
- computeVector(ap, a, p); //v2
-
- // Compute dot products
- final float dot00 = dot(ac, ac);
- final float dot01 = dot(ac, ab);
- final float dot11 = dot(ab, ab);
- final float dot02 = dot(ac, ap);
- final float dot12 = dot(ab, ap);
-
- // Compute barycentric coordinates
- 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);
- }
-
- /** Check if one of three vertices are in triangle using
- * barycentric coordinates computation.
- * @param a first triangle vertex
- * @param b second triangle vertex
- * @param c third triangle vertex
- * @param p1 the vertex in question
- * @param p2 the vertex in question
- * @param p3 the vertex in question
- * @return true if p1 or p2 or p3 is in triangle (a, b, c), false otherwise.
- */
- public static boolean vertexInTriangle3(float[] a, float[] b, float[] c,
- float[] p1, float[] p2, float[] p3,
- float[] ac, float[] ab, float[] ap){
- // Compute vectors
- computeVector(ac, a, c); //v0
- computeVector(ab, a, b); //v1
-
- // Compute dot products
- final float dotAC_AC = dot(ac, ac);
- final float dotAC_AB = dot(ac, ab);
- final float dotAB_AB = dot(ab, ab);
-
- // Compute barycentric coordinates
- final float invDenom = 1 / (dotAC_AC * dotAB_AB - dotAC_AB * dotAC_AB);
- {
- computeVector(ap, a, p1); //v2
- final float dotAC_AP1 = dot(ac, ap);
- final float dotAB_AP1 = dot(ab, ap);
- final float u1 = (dotAB_AB * dotAC_AP1 - dotAC_AB * dotAB_AP1) * invDenom;
- final float v1 = (dotAC_AC * dotAB_AP1 - dotAC_AB * dotAC_AP1) * invDenom;
-
- // Check if point is in triangle
- if ( (u1 >= 0) && (v1 >= 0) && (u1 + v1 < 1) ) {
- return true;
- }
- }
-
- {
- computeVector(ap, a, p2); //v2
- final float dotAC_AP2 = dot(ac, ap);
- final float dotAB_AP2 = dot(ab, ap);
- final float u = (dotAB_AB * dotAC_AP2 - dotAC_AB * dotAB_AP2) * invDenom;
- final float v = (dotAC_AC * dotAB_AP2 - dotAC_AB * dotAC_AP2) * invDenom;
-
- // Check if point is in triangle
- if ( (u >= 0) && (v >= 0) && (u + v < 1) ) {
- return true;
- }
- }
-
- {
- computeVector(ap, a, p3); //v2
- final float dotAC_AP3 = dot(ac, ap);
- final float dotAB_AP3 = dot(ab, ap);
- final float u = (dotAB_AB * dotAC_AP3 - dotAC_AB * dotAB_AP3) * invDenom;
- final float v = (dotAC_AC * dotAB_AP3 - dotAC_AB * dotAC_AP3) * invDenom;
-
- // Check if point is in triangle
- if ( (u >= 0) && (v >= 0) && (u + v < 1) ) {
- return true;
- }
- }
-
- return false;
- }
-
- /** Check if points are in ccw order
- * @param a first vertex
- * @param b second vertex
- * @param c third vertex
- * @return true if the points a,b,c are in a ccw order
- */
- public static boolean ccw(Vertex a, Vertex b, Vertex c){
- return triArea(a,b,c) > 0;
- }
-
- /** Compute the winding of given points
- * @param a first vertex
- * @param b second vertex
- * @param c third vertex
- * @return Winding
- */
- public static Winding getWinding(Vertex a, Vertex b, Vertex c) {
- return triArea(a,b,c) > 0 ? Winding.CCW : Winding.CW ;
- }
-
- /** Computes the area of a list of vertices to check if ccw
- * @param vertices
- * @return positive area if ccw else negative area value
- */
- public static float area(ArrayList<Vertex> vertices) {
- 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();
- area += pCoord[0] * qCoord[1] - qCoord[0] * pCoord[1];
- }
- return area;
- }
-
- /** Compute the general winding of the vertices
- * @param vertices array of Vertices
- * @return CCW or CW {@link Winding}
- */
- public static Winding getWinding(ArrayList<Vertex> vertices) {
- return area(vertices) >= 0 ? Winding.CCW : Winding.CW ;
- }
-
-
- /** Compute intersection between two segments
- * @param a vertex 1 of first segment
- * @param b vertex 2 of first segment
- * @param c vertex 1 of second segment
- * @param d vertex 2 of second segment
- * @return the intersection coordinates if the segments intersect, otherwise
- * returns null
- */
- public static float[] seg2SegIntersection(Vertex a, Vertex b, Vertex c, Vertex d) {
- final float determinant = (a.getX()-b.getX())*(c.getY()-d.getY()) - (a.getY()-b.getY())*(c.getX()-d.getX());
-
- if (determinant == 0)
- return null;
-
- 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;
-
- 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;
-
- return new float[]{xi,yi,0};
- }
-
- /** Compute intersection between two segments
- * @param a vertex 1 of first segment
- * @param b vertex 2 of first segment
- * @param c vertex 1 of second segment
- * @param d vertex 2 of second segment
- * @return true if the segments intersect, otherwise returns false
- */
- public static boolean testSeg2SegIntersection(Vertex a, Vertex b, Vertex c, Vertex d) {
- final float[] A = a.getCoord();
- final float[] B = b.getCoord();
- final float[] C = c.getCoord();
- final float[] D = d.getCoord();
-
- final float determinant = (A[0]-B[0])*(C[1]-D[1]) - (A[1]-B[1])*(C[0]-D[0]);
-
- if (determinant == 0) {
- return false;
- }
-
- final float alpha = (A[0]*B[1]-A[1]*B[0]);
- final float beta = (C[0]*D[1]-C[1]*D[1]);
- final float xi = ((C[0]-D[0])*alpha-(A[0]-B[0])*beta)/determinant;
-
- final float gamma = (xi - A[0])/(B[0] - A[0]);
- final float gamma1 = (xi - C[0])/(D[0] - C[0]);
- if(gamma <= 0 || gamma >= 1 || gamma1 <= 0 || gamma1 >= 1) {
- return false;
- }
-
- return true;
- }
-
- /** Compute intersection between two lines
- * @param a vertex 1 of first line
- * @param b vertex 2 of first line
- * @param c vertex 1 of second line
- * @param d vertex 2 of second line
- * @return the intersection coordinates if the lines intersect, otherwise
- * returns null
- */
- public static float[] line2lineIntersection(Vertex a, Vertex b, Vertex c, Vertex d) {
- 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;
-
- return new float[]{xi,yi,0};
- }
-
- /** Check if a segment intersects with a triangle
- * @param a vertex 1 of the triangle
- * @param b vertex 2 of the triangle
- * @param c vertex 3 of the triangle
- * @param d vertex 1 of first segment
- * @param e vertex 2 of first segment
- * @return true if the segment intersects at least one segment of the triangle, false otherwise
- */
- public static boolean testTri2SegIntersection(Vertex a, Vertex b, Vertex c, Vertex d, Vertex e){
- return testSeg2SegIntersection(a, b, d, e) ||
- testSeg2SegIntersection(b, c, d, e) ||
- testSeg2SegIntersection(a, c, d, e) ;
- }
-}