From 526af50c03af2e00a028caf4b8504e6c3f3c4221 Mon Sep 17 00:00:00 2001 From: Rami Santina Date: Fri, 25 Mar 2011 12:00:55 +0200 Subject: Refactored Vertex Point PointTex GraphPoint namings Vertex class --> SVertex (Simple vertex wwhere memory impl is float[]) Point interface --> Vertex (which combines in it PointTex Interface) GraphPoint --> GraphVertex --- src/com/jogamp/graph/curve/HwRegionRenderer.java | 14 +- src/com/jogamp/graph/curve/OutlineShape.java | 68 ++++---- src/com/jogamp/graph/curve/Region.java | 6 +- .../jogamp/graph/curve/tess/CDTriangulator2D.java | 16 +- .../jogamp/graph/curve/text/HwTextRenderer.java | 17 +- src/com/jogamp/graph/font/FontFactory.java | 7 +- src/com/jogamp/graph/geom/Line.java | 2 +- src/com/jogamp/graph/geom/Outline.java | 14 +- src/com/jogamp/graph/geom/Point.java | 78 --------- src/com/jogamp/graph/geom/PointTex.java | 37 ----- src/com/jogamp/graph/geom/Triangle.java | 2 +- src/com/jogamp/graph/geom/Vertex.java | 82 ++++++++++ src/com/jogamp/graph/geom/opengl/SVertex.java | 179 ++++++++++++++++++++ src/com/jogamp/graph/geom/opengl/Vertex.java | 180 --------------------- 14 files changed, 333 insertions(+), 369 deletions(-) delete mode 100644 src/com/jogamp/graph/geom/Point.java delete mode 100644 src/com/jogamp/graph/geom/PointTex.java create mode 100644 src/com/jogamp/graph/geom/Vertex.java create mode 100644 src/com/jogamp/graph/geom/opengl/SVertex.java delete mode 100644 src/com/jogamp/graph/geom/opengl/Vertex.java (limited to 'src/com') diff --git a/src/com/jogamp/graph/curve/HwRegionRenderer.java b/src/com/jogamp/graph/curve/HwRegionRenderer.java index 3c3142061..2caa6bb7e 100755 --- a/src/com/jogamp/graph/curve/HwRegionRenderer.java +++ b/src/com/jogamp/graph/curve/HwRegionRenderer.java @@ -40,7 +40,7 @@ import javax.media.opengl.GLUniformData; import javax.media.opengl.fixedfunc.GLMatrixFunc; import com.jogamp.graph.geom.Triangle; -import com.jogamp.graph.geom.PointTex; +import com.jogamp.graph.geom.Vertex; import jogamp.opengl.Debug; import com.jogamp.opengl.util.PMVMatrix; @@ -71,7 +71,7 @@ public class HwRegionRenderer { /** Create a Hardware accelerated Region Renderer * @param context OpenGL rendering context - * @param factory optional Point.Factory for PointTex construction. Default is Vertex.Factory. + * @param factory optional Point.Factory for Vertex construction. Default is Vertex.Factory. */ public HwRegionRenderer(GLContext context) { this.context = context; @@ -248,8 +248,8 @@ public class HwRegionRenderer { outlineShape.transformOutlines(OutlineShape.QUADRATIC_NURBS); - ArrayList> triangles = (ArrayList>) outlineShape.triangulate(sharpness); - ArrayList vertices = (ArrayList) outlineShape.getVertices(); + ArrayList> triangles = (ArrayList>) outlineShape.triangulate(sharpness); + ArrayList vertices = (ArrayList) outlineShape.getVertices(); region.addVertices(vertices); region.addTriangles(triangles); @@ -265,11 +265,11 @@ public class HwRegionRenderer { for(OutlineShape outlineShape:outlineShapes){ outlineShape.transformOutlines(OutlineShape.QUADRATIC_NURBS); - ArrayList> triangles = outlineShape.triangulate(sharpness); + ArrayList> triangles = outlineShape.triangulate(sharpness); region.addTriangles(triangles); - ArrayList vertices = outlineShape.getVertices(); - for(PointTex vert:vertices){ + ArrayList vertices = outlineShape.getVertices(); + for(Vertex vert:vertices){ vert.setId(numVertices++); } region.addVertices(vertices); diff --git a/src/com/jogamp/graph/curve/OutlineShape.java b/src/com/jogamp/graph/curve/OutlineShape.java index d939d7427..b48804b4d 100755 --- a/src/com/jogamp/graph/curve/OutlineShape.java +++ b/src/com/jogamp/graph/curve/OutlineShape.java @@ -35,8 +35,8 @@ import jogamp.graph.math.VectorFloatUtil; import com.jogamp.graph.geom.Outline; import com.jogamp.graph.geom.Line; import com.jogamp.graph.geom.Triangle; -import com.jogamp.graph.geom.Point; -import com.jogamp.graph.geom.PointTex; +import com.jogamp.graph.geom.Vertex; +import com.jogamp.graph.geom.Vertex; import com.jogamp.graph.curve.tess.CDTriangulator2D; @@ -54,24 +54,24 @@ import com.jogamp.graph.curve.tess.CDTriangulator2D; */ public class OutlineShape { public static final int QUADRATIC_NURBS = 10; - private final Point.Factory pointFactory; - private ArrayList> outlines = new ArrayList>(3); + private final Vertex.Factory pointFactory; + private ArrayList> outlines = new ArrayList>(3); /** Create a new Outline based Shape */ - public OutlineShape(Point.Factory factory) { + public OutlineShape(Vertex.Factory factory) { pointFactory = factory; - outlines.add(new Outline()); + outlines.add(new Outline()); } - public final Point.Factory pointFactory() { return pointFactory; } + public final Vertex.Factory pointFactory() { return pointFactory; } /** Add a new empty outline * to the shape, this new outline will * be placed at the end of the outline list. */ public void addEmptyOutline(){ - outlines.add(new Outline()); + outlines.add(new Outline()); } /** Adds an outline to the OutlineShape object @@ -80,7 +80,7 @@ public class OutlineShape { * it will do nothing. * @param outline an Outline object */ - public void addOutline(Outline outline){ + public void addOutline(Outline outline){ if(outline.isEmpty()){ return; } @@ -94,7 +94,7 @@ public class OutlineShape { * shape * @param point */ - public final void addVertex(PointTex point){ + public final void addVertex(Vertex point){ getLastOutline().addVertex(point); } @@ -123,7 +123,7 @@ public class OutlineShape { * of outlines that define the shape * @return the last outline */ - public final Outline getLastOutline(){ + public final Outline getLastOutline(){ return outlines.get(outlines.size()-1); } /** Make sure that the outlines represent @@ -138,19 +138,19 @@ public class OutlineShape { } private void transformOutlinesQuadratic(){ - ArrayList> newOutlines = new ArrayList>(3); + ArrayList> newOutlines = new ArrayList>(3); /**loop over the outlines and make sure no * adj off-curve vertices */ - for(Outline outline:outlines){ - Outline newOutline = new Outline(); + for(Outline outline:outlines){ + Outline newOutline = new Outline(); - ArrayList vertices = outline.getVertices(); + ArrayList vertices = outline.getVertices(); int size =vertices.size()-1; for(int i=0;i outline:outlines){ - ArrayList vertices = outline.getVertices(); - for(PointTex vert:vertices){ + for(Outline outline:outlines){ + ArrayList vertices = outline.getVertices(); + for(Vertex vert:vertices){ vert.setId(maxVertexId); maxVertexId++; } @@ -180,9 +180,9 @@ public class OutlineShape { /** @return the list of vertices associated with the * {@code Outline} list of this object */ - public ArrayList getVertices(){ - ArrayList vertices = new ArrayList(); - for(Outline polyline:outlines){ + public ArrayList getVertices(){ + ArrayList vertices = new ArrayList(); + for(Outline polyline:outlines){ vertices.addAll(polyline.getVertices()); } return vertices; @@ -193,17 +193,17 @@ public class OutlineShape { * parts of this graph * @return arraylist of lines */ - public ArrayList> getLines(){ - ArrayList> lines = new ArrayList>(); - for(Outline outline:outlines){ - ArrayList outVertices = outline.getVertices(); + public ArrayList> getLines(){ + ArrayList> lines = new ArrayList>(); + for(Outline outline:outlines){ + ArrayList outVertices = outline.getVertices(); int size = outVertices.size(); for(int i=0; i < size; i++) { - PointTex currentVertex = outVertices.get(i); + Vertex currentVertex = outVertices.get(i); if(currentVertex.isOnCurve()) { - PointTex v2 = outVertices.get((i+1)%size); + Vertex v2 = outVertices.get((i+1)%size); if(v2.isOnCurve()){ - lines.add(new Line(currentVertex, v2)); + lines.add(new Line(currentVertex, v2)); } } } @@ -214,21 +214,21 @@ public class OutlineShape { /** Triangluate the graph object * @param sharpness sharpness of the curved regions default = 0.5 */ - public ArrayList> triangulate(float sharpness){ + public ArrayList> triangulate(float sharpness){ if(outlines.size() == 0){ return null; } sortOutlines(); generateVertexIds(); - CDTriangulator2D triangulator2d = new CDTriangulator2D(sharpness); + CDTriangulator2D triangulator2d = new CDTriangulator2D(sharpness); for(int index = 0; index< outlines.size();index++){ - Outline outline = outlines.get(index); + Outline outline = outlines.get(index); triangulator2d.addCurve(outline); } - ArrayList> triangles = triangulator2d.generateTriangulation(); + ArrayList> triangles = triangulator2d.generateTriangulation(); triangulator2d.reset(); return triangles; diff --git a/src/com/jogamp/graph/curve/Region.java b/src/com/jogamp/graph/curve/Region.java index 44f426313..f3a87bb7f 100755 --- a/src/com/jogamp/graph/curve/Region.java +++ b/src/com/jogamp/graph/curve/Region.java @@ -30,7 +30,7 @@ package com.jogamp.graph.curve; import java.util.ArrayList; import com.jogamp.graph.geom.Triangle; -import com.jogamp.graph.geom.PointTex; +import com.jogamp.graph.geom.Vertex; import com.jogamp.opengl.util.PMVMatrix; /** A Region is the OGL binding of one or more OutlineShapes @@ -80,7 +80,7 @@ public interface Region { * * @see update() */ - public void addTriangles(ArrayList> tris); + public void addTriangles(ArrayList> tris); /** Get the current number of vertices associated * with this region. This number is not necessary equal to @@ -98,7 +98,7 @@ public interface Region { * * @see update() */ - public void addVertices(ArrayList verts); + public void addVertices(ArrayList verts); /** Check if this region is dirty. A region is marked dirty * when new Vertices, Triangles, and or Lines are added after a diff --git a/src/com/jogamp/graph/curve/tess/CDTriangulator2D.java b/src/com/jogamp/graph/curve/tess/CDTriangulator2D.java index 936965f0c..00c97d463 100644 --- a/src/com/jogamp/graph/curve/tess/CDTriangulator2D.java +++ b/src/com/jogamp/graph/curve/tess/CDTriangulator2D.java @@ -31,13 +31,13 @@ package com.jogamp.graph.curve.tess; import java.util.ArrayList; import jogamp.graph.curve.tess.GraphOutline; -import jogamp.graph.curve.tess.GraphPoint; +import jogamp.graph.curve.tess.GraphVertex; import jogamp.graph.curve.tess.Loop; import jogamp.graph.math.VectorFloatUtil; import com.jogamp.graph.geom.Outline; import com.jogamp.graph.geom.Triangle; -import com.jogamp.graph.geom.PointTex; +import com.jogamp.graph.geom.Vertex; import jogamp.opengl.Debug; /** Constrained Delaunay Triangulation @@ -45,7 +45,7 @@ import jogamp.opengl.Debug; * Closed Regions with optional n holes. * */ -public class CDTriangulator2D { +public class CDTriangulator2D { protected static final boolean DEBUG = Debug.debug("Triangulation"); @@ -149,13 +149,13 @@ public class CDTriangulator2D { @SuppressWarnings("unchecked") private GraphOutline extractBoundaryTriangles(GraphOutline outline, boolean hole){ GraphOutline innerOutline = new GraphOutline(); - ArrayList> outVertices = outline.getGraphPoint(); + ArrayList> outVertices = outline.getGraphPoint(); int size = outVertices.size(); for(int i=0; i < size; i++) { - GraphPoint currentVertex = outVertices.get(i); - GraphPoint gv0 = outVertices.get((i+size-1)%size); - GraphPoint gv2 = outVertices.get((i+1)%size); - GraphPoint gv1 = currentVertex; + GraphVertex currentVertex = outVertices.get(i); + GraphVertex gv0 = outVertices.get((i+size-1)%size); + GraphVertex gv2 = outVertices.get((i+1)%size); + GraphVertex gv1 = currentVertex; if(!currentVertex.getPoint().isOnCurve()) { T v0 = (T) gv0.getPoint().clone(); diff --git a/src/com/jogamp/graph/curve/text/HwTextRenderer.java b/src/com/jogamp/graph/curve/text/HwTextRenderer.java index 61d8309c7..bbe62f158 100644 --- a/src/com/jogamp/graph/curve/text/HwTextRenderer.java +++ b/src/com/jogamp/graph/curve/text/HwTextRenderer.java @@ -48,9 +48,8 @@ import com.jogamp.common.util.ReflectionUtil; import com.jogamp.graph.curve.Region; import com.jogamp.graph.font.Font; import com.jogamp.graph.font.FontFactory; -import com.jogamp.graph.geom.Point; -import com.jogamp.graph.geom.PointTex; -import com.jogamp.graph.geom.opengl.Vertex; +import com.jogamp.graph.geom.Vertex; +import com.jogamp.graph.geom.opengl.SVertex; import jogamp.opengl.Debug; import com.jogamp.opengl.util.PMVMatrix; import com.jogamp.opengl.util.glsl.ShaderCode; @@ -100,28 +99,28 @@ public class HwTextRenderer { private GLContext context; private FloatBuffer color = FloatBuffer.allocate(3); private HashMap strings = new HashMap(); - private final Point.Factory pointFactory; + private final Vertex.Factory pointFactory; int win_width = 0; int win_height = 0; /** Create a Hardware accelerated Text Renderer * @param context OpenGL rendering context - * @param factory optional Point.Factory for PointTex construction. Default is Vertex.Factory. + * @param factory optional Point.Factory for Vertex construction. Default is Vertex.Factory. */ - public HwTextRenderer(GLContext context, Point.Factory factory, int type) { - this.pointFactory = (null != factory) ? factory : Vertex.factory(); + public HwTextRenderer(GLContext context, Vertex.Factory factory, int type) { + this.pointFactory = (null != factory) ? factory : SVertex.factory(); this.context = context; this.regionType = type; init(context, 0.5f); } - public Font createFont(Point.Factory factory, String name, int size) { + public Font createFont(Vertex.Factory factory, String name, int size) { return fontFactory.createFont(factory, name, size); } - public Font createFont(Point.Factory factory, + public Font createFont(Vertex.Factory factory, String[] families, String style, String variant, diff --git a/src/com/jogamp/graph/font/FontFactory.java b/src/com/jogamp/graph/font/FontFactory.java index d10e1c38b..a96dac1b8 100644 --- a/src/com/jogamp/graph/font/FontFactory.java +++ b/src/com/jogamp/graph/font/FontFactory.java @@ -27,19 +27,18 @@ */ package com.jogamp.graph.font; -import com.jogamp.graph.geom.Point; -import com.jogamp.graph.geom.PointTex; +import com.jogamp.graph.geom.Vertex; public interface FontFactory { - Font createFont(Point.Factory factory, + Font createFont(Vertex.Factory factory, String[] families, String style, String variant, String weight, String size); - Font createFont(Point.Factory factory, + Font createFont(Vertex.Factory factory, String name, int size); } \ No newline at end of file diff --git a/src/com/jogamp/graph/geom/Line.java b/src/com/jogamp/graph/geom/Line.java index dbdee569c..92d1b007f 100644 --- a/src/com/jogamp/graph/geom/Line.java +++ b/src/com/jogamp/graph/geom/Line.java @@ -27,7 +27,7 @@ */ package com.jogamp.graph.geom; -public class Line { +public class Line { private T v1; private T v2; diff --git a/src/com/jogamp/graph/geom/Outline.java b/src/com/jogamp/graph/geom/Outline.java index b8b824a1c..d9bde4177 100644 --- a/src/com/jogamp/graph/geom/Outline.java +++ b/src/com/jogamp/graph/geom/Outline.java @@ -29,7 +29,7 @@ package com.jogamp.graph.geom; import java.util.ArrayList; -import com.jogamp.graph.geom.Point; +import com.jogamp.graph.geom.Vertex; import jogamp.graph.math.VectorFloatUtil; @@ -45,7 +45,7 @@ import jogamp.graph.math.VectorFloatUtil; * @see OutlineShape, Region * */ -public class Outline implements Comparable>{ +public class Outline implements Comparable>{ private ArrayList vertices = new ArrayList(3); private boolean closed = false; @@ -68,20 +68,20 @@ public class Outline implements Comparable>{ box.resize(vertex.getX(), vertex.getY(), vertex.getZ()); } - public final void addVertex(Point.Factory factory, float x, float y, boolean onCurve) { + public final void addVertex(Vertex.Factory factory, float x, float y, boolean onCurve) { addVertex(factory, x, y, 0f, onCurve); } @SuppressWarnings("unchecked") - public final void addVertex(Point.Factory factory, float x, float y, float z, boolean onCurve) { - Point v = factory.create(x, y, z); + public final void addVertex(Vertex.Factory factory, float x, float y, float z, boolean onCurve) { + Vertex v = factory.create(x, y, z); v.setOnCurve(onCurve); addVertex((T)v); } @SuppressWarnings("unchecked") - public final void addVertex(Point.Factory factory, float[] coordsBuffer, int offset, int length, boolean onCurve) { - Point v = factory.create(coordsBuffer, offset, length); + public final void addVertex(Vertex.Factory factory, float[] coordsBuffer, int offset, int length, boolean onCurve) { + Vertex v = factory.create(coordsBuffer, offset, length); v.setOnCurve(onCurve); addVertex((T)v); } diff --git a/src/com/jogamp/graph/geom/Point.java b/src/com/jogamp/graph/geom/Point.java deleted file mode 100644 index 5f85801f8..000000000 --- a/src/com/jogamp/graph/geom/Point.java +++ /dev/null @@ -1,78 +0,0 @@ -/** - * Copyright 2011 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; - -/** - * A point with custom memory layout using custom factory. - */ -public interface Point extends Comparable, Cloneable { - - public static interface Factory { - T create(); - - T create(float x, float y); - - T create(float x, float y, float z); - - T create(float[] coordsBuffer, int offset, int length); - - // T[] create(T ... v); - } - - void setCoord(float x, float y); - - void setCoord(float x, float y, float z); - - void setCoord(float[] coordsBuffer, int offset, int length); - - float[] getCoord(); - - void setX(float x); - - void setY(float y); - - void setZ(float z); - - float getX(); - - float getY(); - - float getZ(); - - boolean isOnCurve(); - - void setOnCurve(boolean onCurve); - - int getId(); - - void setId(int id); - - int compareTo(Point p); - - Point clone(); -} diff --git a/src/com/jogamp/graph/geom/PointTex.java b/src/com/jogamp/graph/geom/PointTex.java deleted file mode 100644 index 59f7ee0c6..000000000 --- a/src/com/jogamp/graph/geom/PointTex.java +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Copyright 2011 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; - -/** - * A Point with texture coordinates - */ -public interface PointTex extends Point { - float[] getTexCoord(); - - void setTexCoord(float s, float t); -} diff --git a/src/com/jogamp/graph/geom/Triangle.java b/src/com/jogamp/graph/geom/Triangle.java index 341a4483b..7b11ba23d 100644 --- a/src/com/jogamp/graph/geom/Triangle.java +++ b/src/com/jogamp/graph/geom/Triangle.java @@ -27,7 +27,7 @@ */ package com.jogamp.graph.geom; -public class Triangle { +public class Triangle { private int id = Integer.MAX_VALUE; final private T[] vertices; private boolean[] boundaryEdges = new boolean[3]; diff --git a/src/com/jogamp/graph/geom/Vertex.java b/src/com/jogamp/graph/geom/Vertex.java new file mode 100644 index 000000000..9d19c89f6 --- /dev/null +++ b/src/com/jogamp/graph/geom/Vertex.java @@ -0,0 +1,82 @@ +/** + * Copyright 2011 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; + +/** + * A Vertex with custom memory layout using custom factory. + */ +public interface Vertex extends Comparable, Cloneable { + + public static interface Factory { + T create(); + + T create(float x, float y); + + T create(float x, float y, float z); + + T create(float[] coordsBuffer, int offset, int length); + + // T[] create(T ... v); + } + + void setCoord(float x, float y); + + void setCoord(float x, float y, float z); + + void setCoord(float[] coordsBuffer, int offset, int length); + + float[] getCoord(); + + void setX(float x); + + void setY(float y); + + void setZ(float z); + + float getX(); + + float getY(); + + float getZ(); + + boolean isOnCurve(); + + void setOnCurve(boolean onCurve); + + int getId(); + + void setId(int id); + + int compareTo(Vertex p); + + float[] getTexCoord(); + + void setTexCoord(float s, float t); + + Vertex clone(); +} diff --git a/src/com/jogamp/graph/geom/opengl/SVertex.java b/src/com/jogamp/graph/geom/opengl/SVertex.java new file mode 100644 index 000000000..86b95854d --- /dev/null +++ b/src/com/jogamp/graph/geom/opengl/SVertex.java @@ -0,0 +1,179 @@ +/** + * 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.opengl; + +import jogamp.graph.math.VectorFloatUtil; + +import com.jogamp.graph.geom.Vertex; + +public class SVertex implements Vertex { + private int id = Integer.MAX_VALUE; + protected float[] coord = new float[3]; + protected boolean onCurve = true; + private float[] texCoord = new float[2]; + + static final Factory factory = new Factory(); + + public static Factory factory() { return factory; } + + public static class Factory implements Vertex.Factory { + @Override + public SVertex create() { + return new SVertex(); + } + + @Override + public SVertex create(float x, float y) { + return new SVertex(x, y); + } + + @Override + public SVertex create(float x, float y, float z) { + return new SVertex(x, y, z); + } + + @Override + public SVertex create(float[] coordsBuffer, int offset, int length) { + return new SVertex(coordsBuffer, offset, length); + } + + /* @Override + public Vertex[] create(Vertex ... v) { + return v; + } */ + } + + public SVertex() { + } + + public SVertex(float x, float y) { + setCoord(x, y); + } + public SVertex(float x, float y, float z) { + setCoord(x, y, z); + } + public SVertex(float[] coordsBuffer, int offset, int length) { + setCoord(coordsBuffer, offset, length); + } + + public void setCoord(float x, float y) { + this.coord[0] = x; + this.coord[1] = y; + this.coord[2] = 0f; + } + + public void setCoord(float x, float y, float z) { + this.coord[0] = x; + this.coord[1] = y; + this.coord[2] = z; + } + + public void setCoord(float[] coordsBuffer, int offset, int length) { + if(length > coordsBuffer.length - offset) { + throw new IndexOutOfBoundsException("coordsBuffer too small: "+coordsBuffer.length+" - "+offset+" < "+length); + } + if(length > 3) { + throw new IndexOutOfBoundsException("length too bug: "+length+" > "+3); + } + int i=0; + while(i { - @Override - public Vertex create() { - return new Vertex(); - } - - @Override - public Vertex create(float x, float y) { - return new Vertex(x, y); - } - - @Override - public Vertex create(float x, float y, float z) { - return new Vertex(x, y, z); - } - - @Override - public Vertex create(float[] coordsBuffer, int offset, int length) { - return new Vertex(coordsBuffer, offset, length); - } - - /* @Override - public Vertex[] create(Vertex ... v) { - return v; - } */ - } - - public Vertex() { - } - - public Vertex(float x, float y) { - setCoord(x, y); - } - public Vertex(float x, float y, float z) { - setCoord(x, y, z); - } - public Vertex(float[] coordsBuffer, int offset, int length) { - setCoord(coordsBuffer, offset, length); - } - - public void setCoord(float x, float y) { - this.coord[0] = x; - this.coord[1] = y; - this.coord[2] = 0f; - } - - public void setCoord(float x, float y, float z) { - this.coord[0] = x; - this.coord[1] = y; - this.coord[2] = z; - } - - public void setCoord(float[] coordsBuffer, int offset, int length) { - if(length > coordsBuffer.length - offset) { - throw new IndexOutOfBoundsException("coordsBuffer too small: "+coordsBuffer.length+" - "+offset+" < "+length); - } - if(length > 3) { - throw new IndexOutOfBoundsException("length too bug: "+length+" > "+3); - } - int i=0; - while(i