From 1303328b476570d94e56c9d2fc061e3b09cf538a Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Mon, 9 May 2011 14:25:59 +0200 Subject: Loop: Fix invert; GlyphString/createRegion: Remove unnecessary on-the-fly object creation --- .../classes/com/jogamp/graph/curve/Region.java | 25 ++++++++++++++ src/jogl/classes/jogamp/graph/curve/tess/Loop.java | 40 +++++++++++----------- .../jogamp/graph/curve/text/GlyphString.java | 11 +++--- 3 files changed, 50 insertions(+), 26 deletions(-) (limited to 'src/jogl/classes') diff --git a/src/jogl/classes/com/jogamp/graph/curve/Region.java b/src/jogl/classes/com/jogamp/graph/curve/Region.java index 320483d8d..46bdedee4 100644 --- a/src/jogl/classes/com/jogamp/graph/curve/Region.java +++ b/src/jogl/classes/com/jogamp/graph/curve/Region.java @@ -83,6 +83,18 @@ public abstract class Region { return numVertices; } + /** 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); + setDirty(true); + } + /** 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} @@ -95,6 +107,19 @@ public abstract class Region { setDirty(true); } + /** 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); + numVertices++; + setDirty(true); + } + /** 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} diff --git a/src/jogl/classes/jogamp/graph/curve/tess/Loop.java b/src/jogl/classes/jogamp/graph/curve/tess/Loop.java index 9e29d3973..038d41b84 100644 --- a/src/jogl/classes/jogamp/graph/curve/tess/Loop.java +++ b/src/jogl/classes/jogamp/graph/curve/tess/Loop.java @@ -104,18 +104,25 @@ public class Loop { } boolean isCCW = VectorUtil.ccw(vertices.get(0).getPoint(), vertices.get(1).getPoint(), vertices.get(2).getPoint()); - boolean invert = isCCW && (direction == VectorUtil.CW); + boolean invert = isCCW != (direction == VectorUtil.CCW); + final int dir; + final int max; + final int edgeType; + int index; HEdge firstEdge = null; HEdge lastEdge = null; - int index =0; - int max = vertices.size(); - - int edgeType = HEdge.BOUNDARY; - if(invert){ - index = vertices.size() -1; + + if(!invert) { + dir = 1; + max = vertices.size(); + edgeType = HEdge.BOUNDARY; + index = 0; + } else { + dir = -1; max = -1; edgeType = HEdge.HOLE; + index = vertices.size() -1; } while(index != max){ @@ -125,33 +132,26 @@ public class Loop { HEdge edge = new HEdge(v1, edgeType); v1.addEdge(edge); - if(lastEdge != null){ + if(lastEdge != null) { lastEdge.setNext(edge); edge.setPrev(lastEdge); - } - else{ + } else { firstEdge = edge; } - if(!invert){ - if(index == vertices.size()-1){ + if(!invert) { + if(index == vertices.size()-1) { edge.setNext(firstEdge); firstEdge.setPrev(edge); } - } - else if (index == 0){ + } else if (index == 0) { edge.setNext(firstEdge); firstEdge.setPrev(edge); } lastEdge = edge; - if(!invert){ - index++; - } - else{ - index--; - } + index += dir; } return firstEdge; } diff --git a/src/jogl/classes/jogamp/graph/curve/text/GlyphString.java b/src/jogl/classes/jogamp/graph/curve/text/GlyphString.java index 53a3ec5e0..cd6cd56aa 100644 --- a/src/jogl/classes/jogamp/graph/curve/text/GlyphString.java +++ b/src/jogl/classes/jogamp/graph/curve/text/GlyphString.java @@ -152,20 +152,19 @@ public class GlyphString { // region.setFlipped(true); int numVertices = region.getNumVertices(); - ArrayList tris = new ArrayList(); for(int i=0; i< glyphs.size(); i++) { final GlyphShape glyph = glyphs.get(i); ArrayList gtris = glyph.triangulate(); - tris.addAll(gtris); + region.addTriangles(gtris); - ArrayList gVertices = glyph.getVertices(); + final ArrayList gVertices = glyph.getVertices(); for(int j=0; j