diff options
Diffstat (limited to 'src/com/jogamp/graph/geom')
-rw-r--r-- | src/com/jogamp/graph/geom/AABBox.java | 115 | ||||
-rw-r--r-- | src/com/jogamp/graph/geom/Outline.java | 2 | ||||
-rw-r--r-- | src/com/jogamp/graph/geom/Vertex.java | 2 | ||||
-rw-r--r-- | src/com/jogamp/graph/geom/opengl/SVertex.java | 11 |
4 files changed, 87 insertions, 43 deletions
diff --git a/src/com/jogamp/graph/geom/AABBox.java b/src/com/jogamp/graph/geom/AABBox.java index a2566b91f..f97c43a57 100644 --- a/src/com/jogamp/graph/geom/AABBox.java +++ b/src/com/jogamp/graph/geom/AABBox.java @@ -30,15 +30,29 @@ package com.jogamp.graph.geom; import com.jogamp.graph.math.VectorUtil; /** - * Axis Aligned Bounding Box. + * Axis Aligned Bounding Box. Defined by two 3D coordinates (low and high) + * The low being the the lower left corner of the box, and the high being the upper + * right corner of the 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]; + /** Create a Axis Aligned bounding box (AABBox) where the low and and high MAX float Values. + */ public AABBox() {} + /** Create an AABBox specifying the coordinates of the low and high + * + * @param lx min x-coordinate + * @param ly min y-coordnate + * @param lz min z-coordinate + * @param hx max x-coordinate + * @param hy max y-coordinate + * @param hz max z-coordinate + */ public AABBox(float lx, float ly, float lz, float hx, float hy, float hz) { @@ -48,12 +62,10 @@ public class AABBox { computeCenter(); } - public String toString() { - return "[ "+low[0]+"/"+low[1]+"/"+low[1]+" .. "+high[0]+"/"+high[0]+"/"+high[0]+", ctr "+ - center[0]+"/"+center[1]+"/"+center[1]+" ]"; - } - - + /** Create a AABBox defining the low and high + * @param low min xyz-coordinates + * @param high max xyz-coordinates + */ public AABBox(float[] low, float[] high) { this.low = low; @@ -62,27 +74,39 @@ public class AABBox { computeCenter(); } + /** Get the max xyz-coordinates + * @return a float array containing the max xyz coordinates + */ public float[] getHigh() { return high; } - public void setHigh(float hx, float hy, float hz) + + private void setHigh(float hx, float hy, float hz) { this.high[0] = hx; this.high[1] = hy; this.high[2] = hz; } + + /** Get the min xyz-coordinates + * @return a float array containing the min xyz coordinates + */ public float[] getLow() { return low; } - public void setLow(float lx, float ly, float lz) + + private void setLow(float lx, float ly, float lz) { this.low[0] = lx; this.low[1] = ly; this.low[2] = lz; } + /** Resize the AABBox to encapsulate another AABox + * @param newBox AABBox to be encapsulated in + */ public void resize(AABBox newBox) { float[] newLow = newBox.getLow(); @@ -114,6 +138,12 @@ public class AABBox { center[2] = (high[2] + low[2])/2; } + /** 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 void resize(float x, float y, float z) { /** test low */ @@ -135,6 +165,13 @@ public class AABBox { computeCenter(); } + /** Check if the x & y coordinates are bounded/contained + * by this AABBox + * @param x x-axis coordinate value + * @param y y-axis coordinate value + * @return true if x belong to (low.x, high.x) and + * y belong to (low.y, high.y) + */ public boolean contains(float x, float y){ if(x<low[0] || x>high[0]){ return false; @@ -145,6 +182,14 @@ public class AABBox { return true; } + /** Check if the xyz coordinates are bounded/contained + * by this AABBox. + * @param x x-axis coordinate value + * @param y y-axis coordinate value + * @param z z-axis coordinate value + * @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 boolean contains(float x, float y, float z){ if(x<low[0] || x>high[0]){ return false; @@ -158,14 +203,15 @@ public class AABBox { 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) { + /** Check if there is a common region between this AABBox and the passed + * 2D region irrespective of z range + * @param x lower left x-coord + * @param y lower left y-coord + * @param w width + * @param h hight + * @return true if this AABBox might have a common region with this 2D region + */ + public boolean intersects(float x, float y, float w, float h) { if (w <= 0 || h <= 0) { return false; } @@ -176,8 +222,8 @@ public class AABBox { return false; } - final float x0 = getX(); - final float y0 = getY(); + final float x0 = getMinX(); + final float y0 = getMinY(); return (x + w > x0 && y + h > y0 && x < x0 + _w && @@ -185,26 +231,24 @@ public class AABBox { } + /** Get the size of the Box where the size is represented by the + * length of the vector between low and high. + * @return a float representing the size of the AABBox + */ public float getSize(){ return VectorUtil.computeLength(low, high); } + /**Get the Center of the AABBox + * @return the xyz-coordinates of the center of the AABBox + */ 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; - } - + /** Scale the AABBox by a constant + * @param size a constant float value + */ public void scale(float size) { float[] diffH = new float[3]; diffH[0] = high[0] - center[0]; @@ -224,11 +268,11 @@ public class AABBox { low = VectorUtil.vectorAdd(center, diffL); } - public float getX() { + public float getMinX() { return low[0]; } - public float getY() { + public float getMinY() { return low[1]; } @@ -246,4 +290,9 @@ public class AABBox { public AABBox clone(){ return new AABBox(this.low, this.high); } + + public String toString() { + return "[ "+low[0]+"/"+low[1]+"/"+low[1]+" .. "+high[0]+"/"+high[0]+"/"+high[0]+", ctr "+ + center[0]+"/"+center[1]+"/"+center[1]+" ]"; + } } diff --git a/src/com/jogamp/graph/geom/Outline.java b/src/com/jogamp/graph/geom/Outline.java index 4e588623e..4f8d26783 100644 --- a/src/com/jogamp/graph/geom/Outline.java +++ b/src/com/jogamp/graph/geom/Outline.java @@ -41,9 +41,7 @@ import com.jogamp.graph.math.VectorUtil; * * Note: An outline should be closed to be rendered as a region. * - * * @see OutlineShape, Region - * */ public class Outline<T extends Vertex> implements Comparable<Outline<T>>{ diff --git a/src/com/jogamp/graph/geom/Vertex.java b/src/com/jogamp/graph/geom/Vertex.java index 9d19c89f6..0e4e5e8df 100644 --- a/src/com/jogamp/graph/geom/Vertex.java +++ b/src/com/jogamp/graph/geom/Vertex.java @@ -40,8 +40,6 @@ public interface Vertex extends Comparable<Vertex>, Cloneable { 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); diff --git a/src/com/jogamp/graph/geom/opengl/SVertex.java b/src/com/jogamp/graph/geom/opengl/SVertex.java index 076ac7456..681067e40 100644 --- a/src/com/jogamp/graph/geom/opengl/SVertex.java +++ b/src/com/jogamp/graph/geom/opengl/SVertex.java @@ -31,6 +31,10 @@ package com.jogamp.graph.geom.opengl; import com.jogamp.graph.geom.Vertex; import com.jogamp.graph.math.VectorUtil; +/** A Simple Vertex Implementation. Where the coordinates, and other attributes are + * float based, and the coordinates and texture coordinates are saved in two float arrays. + * + */ public class SVertex implements Vertex { private int id = Integer.MAX_VALUE; protected float[] coord = new float[3]; @@ -61,11 +65,6 @@ public class SVertex implements Vertex { 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() { @@ -98,7 +97,7 @@ public class SVertex implements Vertex { throw new IndexOutOfBoundsException("coordsBuffer too small: "+coordsBuffer.length+" - "+offset+" < "+length); } if(length > 3) { - throw new IndexOutOfBoundsException("length too bug: "+length+" > "+3); + throw new IndexOutOfBoundsException("length too big: "+length+" > "+3); } int i=0; while(i<length) { |