diff options
author | Sven Gothel <[email protected]> | 2014-03-15 07:02:35 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2014-03-15 07:02:35 +0100 |
commit | 0b61e9a2641e38475a330303e49f6becf99158e1 (patch) | |
tree | 4d4bd7ead74950ce7df84d184519873bd83bf660 /src/jogl/classes/com | |
parent | e4641e304fbc64a5d185a39c6ca6357cc678e013 (diff) |
Bug 801: Remove Vertex.Factory from AffineTransform ; Add AABBox tranformed resize.
Diffstat (limited to 'src/jogl/classes/com')
6 files changed, 78 insertions, 36 deletions
diff --git a/src/jogl/classes/com/jogamp/graph/curve/OutlineShape.java b/src/jogl/classes/com/jogamp/graph/curve/OutlineShape.java index 0d3a61fac..63183bf68 100644 --- a/src/jogl/classes/com/jogamp/graph/curve/OutlineShape.java +++ b/src/jogl/classes/com/jogamp/graph/curve/OutlineShape.java @@ -332,7 +332,7 @@ public class OutlineShape implements Comparable<OutlineShape> { final Outline lo = getLastOutline(); lo.addVertex(v); if( 0 == ( dirtyBits & DIRTY_BOUNDS ) ) { - bbox.resize(lo.getBounds()); + bbox.resize(v.getCoord()); } // vertices.add(v); // FIXME: can do and remove DIRTY_VERTICES ? dirtyBits |= DIRTY_TRIANGLES | DIRTY_VERTICES; @@ -347,7 +347,7 @@ public class OutlineShape implements Comparable<OutlineShape> { final Outline lo = getLastOutline(); lo.addVertex(position, v); if( 0 == ( dirtyBits & DIRTY_BOUNDS ) ) { - bbox.resize(lo.getBounds()); + bbox.resize(v.getCoord()); } dirtyBits |= DIRTY_TRIANGLES | DIRTY_VERTICES; } @@ -653,11 +653,11 @@ public class OutlineShape implements Comparable<OutlineShape> { * Note: Triangulated data is lost in returned instance! * </p> */ - public OutlineShape transform(AffineTransform t) { + public final OutlineShape transform(final AffineTransform t) { final OutlineShape newOutlineShape = new OutlineShape(vertexFactory); final int osize = outlines.size(); for(int i=0; i<osize; i++) { - newOutlineShape.addOutline( outlines.get(i).transform(t) ); + newOutlineShape.addOutline( outlines.get(i).transform(t, vertexFactory) ); } return newOutlineShape; } diff --git a/src/jogl/classes/com/jogamp/graph/curve/Region.java b/src/jogl/classes/com/jogamp/graph/curve/Region.java index 853c837f5..bb0ed09d1 100644 --- a/src/jogl/classes/com/jogamp/graph/curve/Region.java +++ b/src/jogl/classes/com/jogamp/graph/curve/Region.java @@ -202,12 +202,12 @@ public abstract class Region { * The optional {@link AffineTransform} is applied to the bounding-box beforehand. * </p> */ - public final void addOutlineShape(final OutlineShape shape, final AffineTransform transform) { + public final void addOutlineShape(final OutlineShape shape, final AffineTransform t) { if( null != frustum ) { final AABBox shapeBox = shape.getBounds(); final AABBox shapeBoxT; - if( null != transform ) { - transform.transform(shapeBox, tmpBox); + if( null != t ) { + t.transform(shapeBox, tmpBox); shapeBoxT = tmpBox; } else { shapeBoxT = shapeBox; @@ -222,7 +222,7 @@ public abstract class Region { final List<Triangle> trisIn = shape.getTriangles(OutlineShape.VerticesState.QUADRATIC_NURBS); final ArrayList<Vertex> vertsIn = shape.getVertices(); if(DEBUG_INSTANCE) { - System.err.println("Region.addOutlineShape().0: tris: "+trisIn.size()+", verts "+vertsIn.size()+", transform "+transform); + System.err.println("Region.addOutlineShape().0: tris: "+trisIn.size()+", verts "+vertsIn.size()+", transform "+t); } final int idxOffset = numVertices; int vertsVNewIdxCount = 0, vertsTMovIdxCount = 0, vertsTNewIdxCount = 0, tris = 0; @@ -232,7 +232,7 @@ public abstract class Region { System.err.println("Region.addOutlineShape(): Processing Vertices"); } for(int i=0; i<vertsIn.size(); i++) { - pushNewVertexImpl(vertsIn.get(i), transform); + pushNewVertexImpl(vertsIn.get(i), t); vertsVNewIdxCount++; } if(DEBUG_INSTANCE) { @@ -261,9 +261,9 @@ public abstract class Region { if(Region.DEBUG_INSTANCE) { System.err.println("T["+i+"]: New Idx "+numVertices); } - pushNewVertexIdxImpl(triInVertices[0], transform); - pushNewVertexIdxImpl(triInVertices[1], transform); - pushNewVertexIdxImpl(triInVertices[2], transform); + pushNewVertexIdxImpl(triInVertices[0], t); + pushNewVertexIdxImpl(triInVertices[1], t); + pushNewVertexIdxImpl(triInVertices[2], t); vertsTNewIdxCount+=3; } tris++; diff --git a/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRegionUtil.java b/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRegionUtil.java index 0721c4726..140e03cfb 100644 --- a/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRegionUtil.java +++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRegionUtil.java @@ -128,7 +128,7 @@ public class TextRegionUtil { public final void visit(final OutlineShape shape, final AffineTransform t) { region.addOutlineShape(shape, t); } }; - processString(visitor, new AffineTransform(vertexFactory), font, pixelSize, str); + processString(visitor, new AffineTransform(), font, pixelSize, str); } /** diff --git a/src/jogl/classes/com/jogamp/graph/geom/Outline.java b/src/jogl/classes/com/jogamp/graph/geom/Outline.java index b299524c0..5f6dd028f 100644 --- a/src/jogl/classes/com/jogamp/graph/geom/Outline.java +++ b/src/jogl/classes/com/jogamp/graph/geom/Outline.java @@ -87,7 +87,7 @@ public class Outline implements Cloneable, Comparable<Outline> { } vertices.add(position, vertex); if(!dirtyBBox) { - bbox.resize(vertex.getX(), vertex.getY(), vertex.getZ()); + bbox.resize(vertex.getCoord()); } } @@ -187,12 +187,12 @@ public class Outline implements Cloneable, Comparable<Outline> { /** * Return a transformed instance with all vertices are copied and transformed. */ - public final Outline transform(AffineTransform t) { + public final Outline transform(final AffineTransform t, final Vertex.Factory<? extends Vertex> vertexFactory) { final Outline newOutline = new Outline(); final int vsize = vertices.size(); for(int i=0; i<vsize; i++) { final Vertex v = vertices.get(i); - newOutline.addVertex(t.transform(v, null)); + newOutline.addVertex(t.transform(v, vertexFactory.create())); } newOutline.closed = this.closed; return newOutline; @@ -202,7 +202,7 @@ public class Outline implements Cloneable, Comparable<Outline> { dirtyBBox = false; bbox.reset(); for (int i=0; i<vertices.size(); i++) { - bbox.resize(vertices.get(i).getCoord(), 0); + bbox.resize(vertices.get(i).getCoord()); } } diff --git a/src/jogl/classes/com/jogamp/graph/geom/Triangle.java b/src/jogl/classes/com/jogamp/graph/geom/Triangle.java index e353dd061..593d9cb24 100644 --- a/src/jogl/classes/com/jogamp/graph/geom/Triangle.java +++ b/src/jogl/classes/com/jogamp/graph/geom/Triangle.java @@ -67,11 +67,11 @@ public class Triangle { /** * Returns a transformed a clone of this instance using the given AffineTransform. */ - public Triangle transform(AffineTransform t) { + public Triangle transform(final AffineTransform t, final Vertex.Factory<? extends Vertex> vertexFactory) { final Triangle tri = new Triangle(id, boundaryEdges, boundaryVertices); - tri.vertices[0] = t.transform(vertices[0], null); - tri.vertices[1] = t.transform(vertices[1], null); - tri.vertices[2] = t.transform(vertices[2], null); + tri.vertices[0] = t.transform(vertices[0], vertexFactory.create()); + tri.vertices[1] = t.transform(vertices[1], vertexFactory.create()); + tri.vertices[2] = t.transform(vertices[2], vertexFactory.create()); return tri; } diff --git a/src/jogl/classes/com/jogamp/opengl/math/geom/AABBox.java b/src/jogl/classes/com/jogamp/opengl/math/geom/AABBox.java index c28b36f82..23edfd6e7 100644 --- a/src/jogl/classes/com/jogamp/opengl/math/geom/AABBox.java +++ b/src/jogl/classes/com/jogamp/opengl/math/geom/AABBox.java @@ -27,6 +27,8 @@ */ package com.jogamp.opengl.math.geom; +import jogamp.graph.geom.plane.AffineTransform; + import com.jogamp.opengl.math.FloatUtil; import com.jogamp.opengl.math.VectorUtil; import com.jogamp.opengl.util.PMVMatrix; @@ -60,8 +62,8 @@ public class AABBox implements Cloneable { * @param hy max y-coordinate * @param hz max z-coordinate */ - public AABBox(float lx, float ly, float lz, - float hx, float hy, float hz) { + public AABBox(final float lx, final float ly, final float lz, + final float hx, final float hy, final float hz) { setSize(lx, ly, lz, hx, hy, hz); } @@ -69,7 +71,7 @@ public class AABBox implements Cloneable { * @param low min xyz-coordinates * @param high max xyz-coordinates */ - public AABBox(float[] low, float[] high) { + public AABBox(final float[] low, final float[] high) { setSize(low[0],low[1],low[2], high[0],high[1],high[2]); } @@ -89,7 +91,7 @@ public class AABBox implements Cloneable { return high; } - private final void setHigh(float hx, float hy, float hz) { + private final void setHigh(final float hx, final float hy, final float hz) { this.high[0] = hx; this.high[1] = hy; this.high[2] = hz; @@ -102,7 +104,7 @@ public class AABBox implements Cloneable { return low; } - private final void setLow(float lx, float ly, float lz) { + private final void setLow(final float lx, final float ly, final float lz) { this.low[0] = lx; this.low[1] = ly; this.low[2] = lz; @@ -125,8 +127,8 @@ public class AABBox implements Cloneable { * @param hy max y-coordinate * @param hz max z-coordinate */ - public final void setSize(float lx, float ly, float lz, - float hx, float hy, float hz) { + public final void setSize(final float lx, final float ly, final float lz, + final float hx, final float hy, final float hz) { this.low[0] = lx; this.low[1] = ly; this.low[2] = lz; @@ -139,7 +141,7 @@ public class AABBox implements Cloneable { /** Resize the AABBox to encapsulate another AABox * @param newBox AABBox to be encapsulated in */ - public final void resize(AABBox newBox) { + public final void resize(final AABBox newBox) { float[] newLow = newBox.getLow(); float[] newHigh = newBox.getHigh(); @@ -162,13 +164,43 @@ public class AABBox implements Cloneable { computeCenter(); } + public final void resize(final AABBox newBox, final AffineTransform t, final float[] tmpV3) { + /** test low */ + { + final float[] newBoxLow = newBox.getLow(); + t.transform(newBoxLow, tmpV3); + tmpV3[2] = newBoxLow[2]; + if (tmpV3[0] < low[0]) + low[0] = tmpV3[0]; + if (tmpV3[1] < low[1]) + low[1] = tmpV3[1]; + if (tmpV3[2] < low[2]) + low[2] = tmpV3[2]; + } + + /** test high */ + { + final float[] newBoxHigh = newBox.getHigh(); + t.transform(newBoxHigh, tmpV3); + tmpV3[2] = newBoxHigh[2]; + if (tmpV3[0] > high[0]) + high[0] = tmpV3[0]; + if (tmpV3[1] > high[1]) + high[1] = tmpV3[1]; + if (tmpV3[2] > high[2]) + high[2] = tmpV3[2]; + } + + computeCenter(); + } + /** 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) { + public final void resize(final float x, final float y, final float z) { /** test low */ if (x < low[0]) { low[0] = x; @@ -194,15 +226,25 @@ public class AABBox implements Cloneable { computeCenter(); } - /** Resize the AABBox to encapsulate the passed + /** + * 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) { + public final void resize(final float[] xyz, final int offset) { resize(xyz[0+offset], xyz[1+offset], xyz[2+offset]); } + /** + * Resize the AABBox to encapsulate the passed + * xyz-coordinates. + * @param xyz xyz-axis coordinate values + */ + public final void resize(final float[] xyz) { + resize(xyz[0], xyz[1], xyz[2]); + } + /** Check if the x & y coordinates are bounded/contained * by this AABBox * @param x x-axis coordinate value @@ -210,7 +252,7 @@ public class AABBox implements Cloneable { * @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) { + public final boolean contains(final float x, final float y) { if(x<low[0] || x>high[0]){ return false; } @@ -228,7 +270,7 @@ public class AABBox implements Cloneable { * @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) { + public final boolean contains(final float x, final float y, final float z) { if(x<low[0] || x>high[0]){ return false; } @@ -249,7 +291,7 @@ public class AABBox implements Cloneable { * @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) { + public final boolean intersects(final float x, final float y, final float w, final float h) { if (w <= 0 || h <= 0) { return false; } @@ -289,7 +331,7 @@ public class AABBox implements Cloneable { * @param size a constant float value * @param tmpV3 caller provided temporary 3-component vector */ - public final void scale(float size, float[] tmpV3) { + public final void scale(final float size, final float[] tmpV3) { tmpV3[0] = high[0] - center[0]; tmpV3[1] = high[1] - center[1]; tmpV3[2] = high[2] - center[2]; |