diff options
author | Sven Gothel <sgothel@jausoft.com> | 2011-03-25 03:55:20 +0100 |
---|---|---|
committer | Sven Gothel <sgothel@jausoft.com> | 2011-03-25 03:55:20 +0100 |
commit | 6c07da79c276abef7a7c2f51b05fb1e04f7666db (patch) | |
tree | c39889de030fd62ee6835ec1ebe2b2783866cfcd /src/com/jogamp | |
parent | 49379f06ceefeaa795af05b1c890047176fe19ef (diff) |
Add com.jogamp.graph.geom types
Diffstat (limited to 'src/com/jogamp')
-rw-r--r-- | src/com/jogamp/graph/geom/AABBox.java | 244 | ||||
-rw-r--r-- | src/com/jogamp/graph/geom/Line.java | 61 | ||||
-rw-r--r-- | src/com/jogamp/graph/geom/Outline.java | 150 | ||||
-rw-r--r-- | src/com/jogamp/graph/geom/Point.java | 78 | ||||
-rw-r--r-- | src/com/jogamp/graph/geom/PointTex.java | 37 | ||||
-rw-r--r-- | src/com/jogamp/graph/geom/Triangle.java | 79 | ||||
-rw-r--r-- | src/com/jogamp/graph/geom/opengl/Vertex.java | 180 |
7 files changed, 829 insertions, 0 deletions
diff --git a/src/com/jogamp/graph/geom/AABBox.java b/src/com/jogamp/graph/geom/AABBox.java new file mode 100644 index 000000000..9199e5253 --- /dev/null +++ b/src/com/jogamp/graph/geom/AABBox.java @@ -0,0 +1,244 @@ +/** + * 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 jogamp.graph.math.VectorFloatUtil; + +/** + * Axis Aligned Bounding Box. + */ +public class AABBox { + private float[] low = {Float.MAX_VALUE,Float.MAX_VALUE,Float.MAX_VALUE}; + private float[] high = {-1*Float.MAX_VALUE,-1*Float.MAX_VALUE,-1*Float.MAX_VALUE}; + private float[] center = new float[3]; + + public AABBox() {} + + public AABBox(float lx, float ly, float lz, + float hx, float hy, float hz) + { + setLow(lx, ly, lz); + setHigh(hx, hy, hz); + + computeCenter(); + } + + + public AABBox(float[] low, float[] high) + { + this.low = low; + this.high = high; + + computeCenter(); + } + + public float[] getHigh() + { + return high; + } + public void setHigh(float hx, float hy, float hz) + { + this.high[0] = hx; + this.high[1] = hy; + this.high[2] = hz; + } + public float[] getLow() + { + return low; + } + public void setLow(float lx, float ly, float lz) + { + this.low[0] = lx; + this.low[1] = ly; + this.low[2] = lz; + } + + public 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 void computeCenter() + { + center[0] = (high[0] + low[0])/2; + center[1] = (high[1] + low[1])/2; + center[2] = (high[2] + low[2])/2; + } + + public 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(); + } + + public 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; + } + + public 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; + } + + /** + * @return true if area is empty + */ + boolean isEmpty() { + return getWidth() <=0 || getHeight() <= 0 ; + } + + public boolean intersects(double x, double y, double w, double 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 = getX(); + final float y0 = getY(); + return (x + w > x0 && + y + h > y0 && + x < x0 + _w && + y < y0 + _h); + } + + + public float getSize(){ + return VectorFloatUtil.computeLength(low, high); + } + + public float[] getCenter() { + return center; + } + + public void setCenter(float[] center) { + this.center = center; + } + + public void setHigh(float[] high) { + this.high = high; + } + + public void setLow(float[] low) { + this.low = low; + } + + public 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 = VectorFloatUtil.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 = VectorFloatUtil.scale(diffL, size); + + high = VectorFloatUtil.vectorAdd(center, diffH); + low = VectorFloatUtil.vectorAdd(center, diffL); + } + + public float getX() { + return low[0]; + } + + public float getY() { + return low[1]; + } + + public float getWidth(){ + return high[0] - low[0]; + } + + public float getHeight() { + return high[1] - low[1]; + } + + public float getDepth() { + return high[2] - low[2]; + } + public AABBox clone(){ + return new AABBox(this.low, this.high); + } +} diff --git a/src/com/jogamp/graph/geom/Line.java b/src/com/jogamp/graph/geom/Line.java new file mode 100644 index 000000000..dbdee569c --- /dev/null +++ b/src/com/jogamp/graph/geom/Line.java @@ -0,0 +1,61 @@ +/** + * 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; + +public class Line <T extends Point> { + private T v1; + private T v2; + + public Line(T v1, T v2) { + this.v1 = v1; + this.v2 = v2; + } + + public T getV1() { + return v1; + } + + public void setV1(T v1) { + this.v1 = v1; + } + + public T getV2() { + return v2; + } + + public void setV2(T v2) { + this.v2 = v2; + } + public boolean isEqual(T t1, T t2){ + if((t1 == v1 || t1 == v2) + &&(t2 == v2 || t2 == v1)){ + return true; + } + return false; + } +} diff --git a/src/com/jogamp/graph/geom/Outline.java b/src/com/jogamp/graph/geom/Outline.java new file mode 100644 index 000000000..b8b824a1c --- /dev/null +++ b/src/com/jogamp/graph/geom/Outline.java @@ -0,0 +1,150 @@ +/** + * 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 java.util.ArrayList; + +import com.jogamp.graph.geom.Point; + +import jogamp.graph.math.VectorFloatUtil; + + +/** Define a single continuous stroke by control vertices. + * 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<T extends Point> implements Comparable<Outline<T>>{ + + private ArrayList<T> vertices = new ArrayList<T>(3); + private boolean closed = false; + private AABBox box = new AABBox(); + + /**Create an outline defined by control vertices. + * An outline can contain off Curve vertices which define curved + * regions in the outline. + */ + public Outline(){ + + } + + /** Add a vertex to the outline. The vertex is added at the + * end of the outline loop/strip. + * @param vertex Vertex to be added + */ + public final void addVertex(T vertex) { + vertices.add(vertex); + box.resize(vertex.getX(), vertex.getY(), vertex.getZ()); + } + + public final void addVertex(Point.Factory<? extends Point> factory, float x, float y, boolean onCurve) { + addVertex(factory, x, y, 0f, onCurve); + } + + @SuppressWarnings("unchecked") + public final void addVertex(Point.Factory<? extends Point> factory, float x, float y, float z, boolean onCurve) { + Point v = factory.create(x, y, z); + v.setOnCurve(onCurve); + addVertex((T)v); + } + + @SuppressWarnings("unchecked") + public final void addVertex(Point.Factory<? extends Point> factory, float[] coordsBuffer, int offset, int length, boolean onCurve) { + Point v = factory.create(coordsBuffer, offset, length); + v.setOnCurve(onCurve); + addVertex((T)v); + } + + public T getVertex(int index){ + return vertices.get(index); + } + + public boolean isEmpty(){ + return (vertices.size() == 0); + } + public T getLastVertex(){ + if(isEmpty()){ + return null; + } + return vertices.get(vertices.size()-1); + } + + public ArrayList<T> getVertices() { + return vertices; + } + public void setVertices(ArrayList<T> vertices) { + this.vertices = vertices; + } + public AABBox getBox() { + return box; + } + public boolean isClosed() { + 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 + */ + public void setClosed(boolean closed) { + this.closed = closed; + if(closed){ + T first = vertices.get(0); + T last = getLastVertex(); + if(!VectorFloatUtil.checkEquality(first.getCoord(), last.getCoord())){ + @SuppressWarnings("unchecked") + T v = (T) first.clone(); + vertices.add(v); + } + } + } + + /** Compare two outlines with Bounding Box area + * as criteria. + * @see java.lang.Comparable#compareTo(java.lang.Object) + */ + public int compareTo(Outline<T> outline) { + float size = box.getSize(); + float newSize = outline.getBox().getSize(); + if(size < newSize){ + return -1; + } + else if(size > newSize){ + return 1; + } + return 0; + } +} diff --git a/src/com/jogamp/graph/geom/Point.java b/src/com/jogamp/graph/geom/Point.java new file mode 100644 index 000000000..5f85801f8 --- /dev/null +++ b/src/com/jogamp/graph/geom/Point.java @@ -0,0 +1,78 @@ +/** + * 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<Point>, Cloneable { + + public static interface Factory <T extends Point> { + 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 new file mode 100644 index 000000000..59f7ee0c6 --- /dev/null +++ b/src/com/jogamp/graph/geom/PointTex.java @@ -0,0 +1,37 @@ +/** + * 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 new file mode 100644 index 000000000..341a4483b --- /dev/null +++ b/src/com/jogamp/graph/geom/Triangle.java @@ -0,0 +1,79 @@ +/** + * 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; + +public class Triangle<T extends PointTex> { + private int id = Integer.MAX_VALUE; + final private T[] vertices; + private boolean[] boundaryEdges = new boolean[3]; + private boolean[] boundaryVertices = null; + + public Triangle(T ... v123){ + vertices = v123; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public T[] getVertices() { + return vertices; + } + + public boolean isEdgesBoundary() { + return boundaryEdges[0] || boundaryEdges[1] || boundaryEdges[2]; + } + + public boolean isVerticesBoundary() { + return boundaryVertices[0] || boundaryVertices[1] || boundaryVertices[2]; + } + + public void setEdgesBoundary(boolean[] boundary) { + this.boundaryEdges = boundary; + } + + public boolean[] getEdgeBoundary() { + return boundaryEdges; + } + + public boolean[] getVerticesBoundary() { + return boundaryVertices; + } + + public void setVerticesBoundary(boolean[] boundaryVertices) { + this.boundaryVertices = boundaryVertices; + } + + public String toString() { + return "Tri ID: " + id + "\n" + vertices[0] + "\n" + vertices[1] + "\n" + vertices[2]; + } +} diff --git a/src/com/jogamp/graph/geom/opengl/Vertex.java b/src/com/jogamp/graph/geom/opengl/Vertex.java new file mode 100644 index 000000000..77d18d7f5 --- /dev/null +++ b/src/com/jogamp/graph/geom/opengl/Vertex.java @@ -0,0 +1,180 @@ +/** + * 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.Point; +import com.jogamp.graph.geom.PointTex; + +public class Vertex implements PointTex { + 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 Point.Factory<Vertex> { + @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<length) { + this.coord[i++] = coordsBuffer[offset++]; + } + } + + public float[] getCoord() { + return coord; + } + + public void setX(float x) { + this.coord[0] = x; + } + + public void setY(float y) { + this.coord[1] = y; + } + + public void setZ(float z) { + this.coord[2] = z; + } + + public float getX() { + return this.coord[0]; + } + + public float getY() { + return this.coord[1]; + } + + public float getZ() { + return this.coord[2]; + } + + public boolean isOnCurve() { + return onCurve; + } + + public void setOnCurve(boolean onCurve) { + this.onCurve = onCurve; + } + + public int getId(){ + return id; + } + + public void setId(int id){ + this.id = id; + } + + public int compareTo(Point p) { + if(VectorFloatUtil.checkEquality(coord, p.getCoord())) { + return 0; + } + return -1; + } + + public float[] getTexCoord() { + return texCoord; + } + + public void setTexCoord(float s, float t) { + this.texCoord[0] = s; + this.texCoord[1] = t; + } + + public Vertex clone(){ + Vertex v = new Vertex(this.coord, 0, 3); + v.setOnCurve(this.onCurve); + return v; + } + + public String toString() { + return "[ID: " + id + " X: " + coord[0] + + " Y: " + coord[1] + " Z: " + coord[2] + "]"; + } +} |