diff options
Diffstat (limited to 'src/jogl/classes/com/jogamp')
3 files changed, 54 insertions, 21 deletions
diff --git a/src/jogl/classes/com/jogamp/graph/curve/OutlineShape.java b/src/jogl/classes/com/jogamp/graph/curve/OutlineShape.java index f4cdffd5e..44a8e7384 100644 --- a/src/jogl/classes/com/jogamp/graph/curve/OutlineShape.java +++ b/src/jogl/classes/com/jogamp/graph/curve/OutlineShape.java @@ -133,6 +133,8 @@ public class OutlineShape implements Comparable<OutlineShape> { /** dirty bits DIRTY_BOUNDS */ private int dirtyBits; + private float sharpness; + /** Create a new Outline based Shape */ public OutlineShape(Vertex.Factory<? extends Vertex> factory) { @@ -144,6 +146,16 @@ public class OutlineShape implements Comparable<OutlineShape> { this.triangles = new ArrayList<Triangle>(); this.vertices = new ArrayList<Vertex>(); this.dirtyBits = 0; + this.sharpness = 0.5f; + } + + public float getSharpness() { return sharpness; } + + public void setSharpness(final float s) { + if( this.sharpness != s ) { + clearCache(); + sharpness=s; + } } /** Clears all data and reset all states as if this instance was newly created */ @@ -157,6 +169,13 @@ public class OutlineShape implements Comparable<OutlineShape> { dirtyBits = 0; } + /** Clears cached triangulated data, i.e. {@link #getTriangles(VerticesState)} and {@link #getVertices()}. */ + public void clearCache() { + vertices.clear(); + triangles.clear(); + dirtyBits |= DIRTY_TRIANGLES | DIRTY_VERTICES; + } + /** * Returns the associated vertex factory of this outline shape * @return Vertex.Factory object @@ -236,7 +255,7 @@ public class OutlineShape implements Comparable<OutlineShape> { /** * Insert the {@link OutlineShape} elements of type {@link Outline}, .. at the end of this shape, * using {@link #addOutline(Outline)} for each element. - * <p>Closes the current last outline via {@link #closeLastOutline()} before adding the new ones.</p> + * <p>Closes the current last outline via {@link #closeLastOutline(boolean)} before adding the new ones.</p> * @param outlineShape OutlineShape elements to be added. * @throws NullPointerException if the {@link OutlineShape} is null * @throws IndexOutOfBoundsException if position is out of range (position < 0 || position > getOutlineNumber()) @@ -245,7 +264,7 @@ public class OutlineShape implements Comparable<OutlineShape> { if (null == outlineShape) { throw new NullPointerException("OutlineShape is null"); } - closeLastOutline(); + closeLastOutline(true); for(int i=0; i<outlineShape.getOutlineNumber(); i++) { addOutline(outlineShape.getOutline(i)); } @@ -369,11 +388,15 @@ public class OutlineShape implements Comparable<OutlineShape> { /** * 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 - * is equal to the first.</p> + * <p> + * Checks whether the last vertex equals to the first of the last outline. + * If not equal, it either appends a clone of the first vertex + * or prepends a clone of the last vertex, depending on <code>closeTail</code>. + * </p> + * @param closeTail if true, a clone of the first vertex will be appended, + * otherwise a clone of the last vertex will be prepended. */ - public final void closeLastOutline() { + public final void closeLastOutline(boolean closeTail) { if( getLastOutline().setClosed(true) ) { dirtyBits |= DIRTY_TRIANGLES | DIRTY_VERTICES; } @@ -588,7 +611,7 @@ public class OutlineShape implements Comparable<OutlineShape> { triangles.clear(); final Triangulator triangulator2d = Triangulation.create(); for(int index = 0; index<outlines.size(); index++) { - triangulator2d.addCurve(triangles, outlines.get(index)); + triangulator2d.addCurve(triangles, outlines.get(index), sharpness); } triangulator2d.generate(triangles); triangulator2d.reset(); 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 39e84171b..96ff4bbb8 100644 --- a/src/jogl/classes/com/jogamp/graph/curve/tess/Triangulator.java +++ b/src/jogl/classes/com/jogamp/graph/curve/tess/Triangulator.java @@ -54,8 +54,9 @@ public interface Triangulator { * describing the shape * @param sink list where the generated triangles will be added * @param outline a bounding {@link Outline} + * @param sharpness TODO */ - public void addCurve(List<Triangle> sink, Outline outline); + public void addCurve(List<Triangle> sink, Outline outline, float sharpness); /** Generate the triangulation of the provided * List of {@link Outline}s diff --git a/src/jogl/classes/com/jogamp/graph/geom/Outline.java b/src/jogl/classes/com/jogamp/graph/geom/Outline.java index 26eba2741..2d9d74966 100644 --- a/src/jogl/classes/com/jogamp/graph/geom/Outline.java +++ b/src/jogl/classes/com/jogamp/graph/geom/Outline.java @@ -62,7 +62,8 @@ public class Outline implements Cloneable, Comparable<Outline> { return vertices.size(); } - /** Appends a vertex to the outline loop/strip. + /** + * Appends a vertex to the outline loop/strip. * @param vertex Vertex to be added * @throws NullPointerException if the {@link Vertex} element is null */ @@ -70,7 +71,8 @@ public class Outline implements Cloneable, Comparable<Outline> { addVertex(vertices.size(), vertex); } - /** Insert the {@link Vertex} element at the given {@code position} to the outline loop/strip. + /** + * 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 @@ -151,21 +153,28 @@ public class Outline implements Cloneable, Comparable<Outline> { return closed; } - /** define if this outline is closed or not. - * 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 + /** + * Ensure this outline is closed. + * <p> + * Checks whether the last vertex equals to the first. + * If not equal, it either appends a clone of the first vertex + * or prepends a clone of the last vertex, depending on <code>closeTail</code>. + * </p> + * @param closeTail if true, a clone of the first vertex will be appended, + * otherwise a clone of the last vertex will be prepended. * @return true if closing performed, otherwise false for NOP */ - public final boolean setClosed(boolean closed) { - this.closed = closed; - if( closed && !isEmpty() ) { + public final boolean setClosed(boolean closeTail) { + this.closed = true; + if( !isEmpty() ) { final Vertex first = vertices.get(0); final Vertex last = getLastVertex(); - if(!VectorUtil.checkEquality(first.getCoord(), last.getCoord())){ - Vertex v = first.clone(); - vertices.add(v); + if( !VectorUtil.checkEquality( first.getCoord(), last.getCoord() ) ) { + if( closeTail ) { + vertices.add(first.clone()); + } else { + vertices.add(0, last.clone()); + } return true; } } |