aboutsummaryrefslogtreecommitdiffstats
path: root/src/jogl/classes/com/jogamp
diff options
context:
space:
mode:
Diffstat (limited to 'src/jogl/classes/com/jogamp')
-rw-r--r--src/jogl/classes/com/jogamp/graph/curve/OutlineShape.java21
-rw-r--r--src/jogl/classes/com/jogamp/graph/curve/Region.java174
-rw-r--r--src/jogl/classes/com/jogamp/graph/curve/opengl/GLRegion.java40
-rw-r--r--src/jogl/classes/com/jogamp/graph/curve/opengl/RegionRenderer.java7
-rw-r--r--src/jogl/classes/com/jogamp/graph/curve/opengl/Renderer.java2
-rw-r--r--src/jogl/classes/com/jogamp/graph/curve/opengl/TextRenderer.java14
-rw-r--r--src/jogl/classes/com/jogamp/graph/font/Font.java24
-rw-r--r--src/jogl/classes/com/jogamp/opengl/math/VectorUtil.java160
-rw-r--r--src/jogl/classes/com/jogamp/opengl/math/geom/AABBox.java5
9 files changed, 300 insertions, 147 deletions
diff --git a/src/jogl/classes/com/jogamp/graph/curve/OutlineShape.java b/src/jogl/classes/com/jogamp/graph/curve/OutlineShape.java
index 226e57f07..c8d5a9db6 100644
--- a/src/jogl/classes/com/jogamp/graph/curve/OutlineShape.java
+++ b/src/jogl/classes/com/jogamp/graph/curve/OutlineShape.java
@@ -114,8 +114,8 @@ public class OutlineShape implements Comparable<OutlineShape> {
/** The list of {@link Outline}s that are part of this
* outline shape.
*/
- private ArrayList<Outline> outlines;
- private AABBox bbox;
+ /* pp */ ArrayList<Outline> outlines;
+ private final AABBox bbox;
/** dirty bits DIRTY_BOUNDS */
private int dirtyBits;
@@ -427,6 +427,10 @@ public class OutlineShape implements Comparable<OutlineShape> {
}while(!overlaps.isEmpty());
}
+ private final float[] tempVecAC = new float[3];
+ private final float[] tempVecAB = new float[3];
+ private final float[] tempVecAP = new float[3];
+
private Vertex checkTriOverlaps(Vertex a, Vertex b, Vertex c) {
int count = getOutlineNumber();
for (int cc = 0; cc < count; cc++) {
@@ -445,15 +449,14 @@ public class OutlineShape implements Comparable<OutlineShape> {
continue;
}
- if(VectorUtil.vertexInTriangle(a.getCoord(), b.getCoord(), c.getCoord(), current.getCoord())
- || VectorUtil.vertexInTriangle(a.getCoord(), b.getCoord(), c.getCoord(), nextV.getCoord())
- || VectorUtil.vertexInTriangle(a.getCoord(), b.getCoord(), c.getCoord(), prevV.getCoord())) {
-
+ if( VectorUtil.vertexInTriangle3(a.getCoord(), b.getCoord(), c.getCoord(),
+ current.getCoord(), nextV.getCoord(), prevV.getCoord(),
+ tempVecAC, tempVecAB, tempVecAP) ) {
return current;
}
- if(VectorUtil.tri2SegIntersection(a, b, c, prevV, current)
- || VectorUtil.tri2SegIntersection(a, b, c, current, nextV)
- || VectorUtil.tri2SegIntersection(a, b, c, prevV, nextV)) {
+ if(VectorUtil.testTri2SegIntersection(a, b, c, prevV, current) ||
+ VectorUtil.testTri2SegIntersection(a, b, c, current, nextV) ||
+ VectorUtil.testTri2SegIntersection(a, b, c, prevV, nextV)) {
return current;
}
}
diff --git a/src/jogl/classes/com/jogamp/graph/curve/Region.java b/src/jogl/classes/com/jogamp/graph/curve/Region.java
index a9779523a..e36e37c26 100644
--- a/src/jogl/classes/com/jogamp/graph/curve/Region.java
+++ b/src/jogl/classes/com/jogamp/graph/curve/Region.java
@@ -28,36 +28,35 @@
package com.jogamp.graph.curve;
import java.util.ArrayList;
+import java.util.List;
+import jogamp.graph.curve.opengl.RegionFactory;
import jogamp.opengl.Debug;
+import com.jogamp.graph.curve.opengl.GLRegion;
import com.jogamp.graph.geom.Triangle;
import com.jogamp.graph.geom.Vertex;
import com.jogamp.opengl.math.geom.AABBox;
-/** Abstract Outline shape GL representation
- * define the method an OutlineShape(s) is
- * binded rendered.
+/** Abstract Outline shape GL representation define the method an OutlineShape(s)
+ * is bound and rendered.
*
- * @see GLRegion
- */
+ * @see GLRegion */
public abstract class Region {
- /** Debug flag for region impl (graph.curve)
- */
+ /** Debug flag for region impl (graph.curve) */
public static final boolean DEBUG = Debug.debug("graph.curve");
public static final boolean DEBUG_INSTANCE = false;
- /** View based Anti-Aliasing, A Two pass region rendering, slower
- * and more resource hungry (FBO), but AA is perfect.
- * Otherwise the default fast one pass MSAA region rendering is being used.
- */
+ /** View based Anti-Aliasing, A Two pass region rendering, slower and more
+ * resource hungry (FBO), but AA is perfect. Otherwise the default fast one
+ * pass MSAA region rendering is being used. */
public static final int VBAA_RENDERING_BIT = 1 << 0;
/** Use non uniform weights [0.0 .. 1.9] for curve region rendering.
- * Otherwise the default weight 1.0 for uniform curve region rendering is being applied.
- */
+ * Otherwise the default weight 1.0 for uniform curve region rendering is
+ * being applied. */
public static final int VARIABLE_CURVE_WEIGHT_BIT = 1 << 1;
public static final int TWO_PASS_DEFAULT_TEXTURE_UNIT = 0;
@@ -70,16 +69,38 @@ public abstract class Region {
protected ArrayList<Vertex> vertices = new ArrayList<Vertex>();
public static boolean isVBAA(int renderModes) {
- return 0 != ( renderModes & Region.VBAA_RENDERING_BIT );
+ return 0 != (renderModes & Region.VBAA_RENDERING_BIT);
}
/** Check if render mode capable of non uniform weights
- * @param renderModes bit-field of modes, e.g. {@link Region#VARIABLE_CURVE_WEIGHT_BIT},
- * {@link Region#VBAA_RENDERING_BIT}
- * @return true of capable of non uniform weights
- */
+ *
+ * @param renderModes
+ * bit-field of modes, e.g.
+ * {@link Region#VARIABLE_CURVE_WEIGHT_BIT},
+ * {@link Region#VBAA_RENDERING_BIT}
+ * @return true of capable of non uniform weights */
public static boolean isNonUniformWeight(int renderModes) {
- return 0 != ( renderModes & Region.VARIABLE_CURVE_WEIGHT_BIT );
+ return 0 != (renderModes & Region.VARIABLE_CURVE_WEIGHT_BIT);
+ }
+
+ /** Create a {@link Region} defining the list of {@link OutlineShape}.
+ * Combining the Shapes into single buffers.
+ * @return the resulting Region inclusive the generated region
+ */
+ public static Region create(List<OutlineShape> outlineShapes, int renderModes) {
+ final Region region = RegionFactory.create(renderModes);
+ region.addOutlineShapes(outlineShapes);
+ return region;
+ }
+
+ /**
+ * Create a {@link Region} defining this {@link OutlineShape}
+ * @return the resulting Region.
+ */
+ public static Region create(OutlineShape outlineShape, int renderModes) {
+ final Region region = RegionFactory.create(renderModes);
+ region.addOutlineShape(outlineShape);
+ return region;
}
protected Region(int regionRenderModes) {
@@ -87,100 +108,119 @@ public abstract class Region {
}
/** Get current Models
- * @return bit-field of render modes
- */
+ *
+ * @return bit-field of render modes */
public final int getRenderModes() {
return renderModes;
}
/** Check if current Region is using VBAA
- * @return true if capable of two pass rendering - VBAA
- */
+ *
+ * @return true if capable of two pass rendering - VBAA */
public boolean isVBAA() {
return Region.isVBAA(renderModes);
}
/** Check if current instance uses non uniform weights
- * @return true if capable of nonuniform weights
- */
+ *
+ * @return true if capable of nonuniform weights */
public boolean isNonUniformWeight() {
return Region.isNonUniformWeight(renderModes);
}
- /** Get the current number of vertices associated
- * with this region. This number is not necessary equal to
- * the OGL bound number of vertices.
- * @return vertices count
- */
- public final int getNumVertices(){
+ /** Get the current number of vertices associated with this region. This
+ * number is not necessary equal to the OGL bound number of vertices.
+ *
+ * @return vertices count */
+ public final int getNumVertices() {
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
+ /** Adds a {@link Triangle} object to the Region This triangle will be bound
+ * to OGL objects on the next call to {@code update}
*
- * @see update(GL2ES2)
- */
+ * @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}
- * @param tris an arraylist of triangle objects
+ /** 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}
*
- * @see update(GL2ES2)
- */
- public void addTriangles(ArrayList<Triangle> tris) {
+ * @param tris
+ * a list of triangle objects
+ *
+ * @see update(GL2ES2) */
+ public void addTriangles(List<Triangle> tris) {
triangles.addAll(tris);
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
+ /** Adds a {@link Vertex} object to the Region This vertex will be bound to
+ * OGL objects on the next call to {@code update}
*
- * @see update(GL2ES2)
- */
+ * @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}
- * @param verts an arraylist of vertex objects
+ /** 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}
*
- * @see update(GL2ES2)
- */
- public void addVertices(ArrayList<Vertex> verts) {
+ * @param verts
+ * a list of vertex objects
+ *
+ * @see update(GL2ES2) */
+ public void addVertices(List<Vertex> verts) {
vertices.addAll(verts);
numVertices = vertices.size();
setDirty(true);
}
- /**
- * @return the AxisAligned bounding box of
- * current region
- */
- public final AABBox getBounds(){
+ public void addOutlineShape(OutlineShape shape) {
+ shape.transformOutlines(OutlineShape.VerticesState.QUADRATIC_NURBS);
+ List<Triangle> tris = shape.triangulate();
+ if(null != tris) {
+ triangles.addAll(tris);
+ for (int j = 0; j < shape.outlines.size(); j++) {
+ final ArrayList<Vertex> sovs = shape.outlines.get(j).getVertices();
+ for (int k = 0; k < sovs.size(); k++) {
+ final Vertex v = sovs.get(k);
+ v.setId(numVertices++);
+ vertices.add(v);
+ }
+ }
+ }
+ setDirty(true);
+ }
+
+ public void addOutlineShapes(List<OutlineShape> shapes) {
+ for (int i = 0; i < shapes.size(); i++) {
+ addOutlineShape(shapes.get(i));
+ }
+ setDirty(true);
+ }
+
+ /** @return the AxisAligned bounding box of current region */
+ public final AABBox getBounds() {
return box;
}
- /** Check if this region is dirty. A region is marked dirty
- * when new Vertices, Triangles, and or Lines are added after a
- * call to update()
+ /** Check if this region is dirty. A region is marked dirty when new
+ * Vertices, Triangles, and or Lines are added after a call to update()
+ *
* @return true if region is Dirty, false otherwise
*
- * @see update(GL2ES2)
- */
+ * @see update(GL2ES2) */
public final boolean isDirty() {
return dirty;
}
diff --git a/src/jogl/classes/com/jogamp/graph/curve/opengl/GLRegion.java b/src/jogl/classes/com/jogamp/graph/curve/opengl/GLRegion.java
index dfb7a95b3..d63e02a9c 100644
--- a/src/jogl/classes/com/jogamp/graph/curve/opengl/GLRegion.java
+++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/GLRegion.java
@@ -27,17 +27,13 @@
*/
package com.jogamp.graph.curve.opengl;
-
-import java.util.ArrayList;
+import java.util.List;
import javax.media.opengl.GL2ES2;
import com.jogamp.opengl.util.PMVMatrix;
import com.jogamp.graph.curve.OutlineShape;
import com.jogamp.graph.curve.Region;
-import com.jogamp.graph.geom.Triangle;
-import com.jogamp.graph.geom.Vertex;
-import jogamp.graph.curve.opengl.RegionFactory;
/** A GLRegion is the OGL binding of one or more OutlineShapes
* Defined by its vertices and generated triangles. The Region
@@ -55,42 +51,16 @@ public abstract class GLRegion extends Region {
* Combining the Shapes into single buffers.
* @return the resulting Region inclusive the generated region
*/
- public static GLRegion create(OutlineShape[] outlineShapes, int renderModes) {
- final GLRegion region = RegionFactory.create(renderModes);
-
- int numVertices = region.getNumVertices();
-
- for(int index=0; index<outlineShapes.length; index++) {
- OutlineShape outlineShape = outlineShapes[index];
- outlineShape.transformOutlines(OutlineShape.VerticesState.QUADRATIC_NURBS);
-
- ArrayList<Triangle> triangles = outlineShape.triangulate();
- region.addTriangles(triangles);
-
- ArrayList<Vertex> vertices = outlineShape.getVertices();
- for(int pos=0; pos < vertices.size(); pos++){
- Vertex vert = vertices.get(pos);
- vert.setId(numVertices++);
- }
- region.addVertices(vertices);
- }
-
- return region;
+ public static GLRegion create(List<OutlineShape> outlineShapes, int renderModes) {
+ return (GLRegion) Region.create(outlineShapes, renderModes);
}
/**
- * Create an ogl {@link GLRegion} defining this {@link OutlineShape}
+ * Create an ogl {@link Region} defining this {@link OutlineShape}
* @return the resulting Region.
*/
public static GLRegion create(OutlineShape outlineShape, int renderModes) {
- final GLRegion region = RegionFactory.create(renderModes);
-
- outlineShape.transformOutlines(OutlineShape.VerticesState.QUADRATIC_NURBS);
- ArrayList<Triangle> triangles = (ArrayList<Triangle>) outlineShape.triangulate();
- ArrayList<Vertex> vertices = (ArrayList<Vertex>) outlineShape.getVertices();
- region.addVertices(vertices);
- region.addTriangles(triangles);
- return region;
+ return (GLRegion) Region.create(outlineShape, renderModes);
}
protected GLRegion(int renderModes) {
diff --git a/src/jogl/classes/com/jogamp/graph/curve/opengl/RegionRenderer.java b/src/jogl/classes/com/jogamp/graph/curve/opengl/RegionRenderer.java
index f7d4bfd2f..faaf72a99 100644
--- a/src/jogl/classes/com/jogamp/graph/curve/opengl/RegionRenderer.java
+++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/RegionRenderer.java
@@ -53,12 +53,11 @@ public abstract class RegionRenderer extends Renderer {
/** Render an {@link OutlineShape} in 3D space at the position provided
* the triangles of the shapes will be generated, if not yet generated
* @param region the OutlineShape to Render.
- * @param position the initial translation of the outlineShape.
* @param texWidth desired texture width for multipass-rendering.
* The actual used texture-width is written back when mp rendering is enabled, otherwise the store is untouched.
* @throws Exception if HwRegionRenderer not initialized
*/
- public final void draw(GL2ES2 gl, Region region, float[] position, int[/*1*/] texWidth) {
+ public final void draw(GL2ES2 gl, Region region, int[/*1*/] texWidth) {
if(!isInitialized()) {
throw new GLException("RegionRenderer: not initialized!");
}
@@ -66,14 +65,14 @@ public abstract class RegionRenderer extends Renderer {
throw new GLException("Incompatible render modes, : region modes "+region.getRenderModes()+
" doesn't contain renderer modes "+this.getRenderModes());
}
- drawImpl(gl, region, position, texWidth);
+ drawImpl(gl, region, texWidth);
}
/**
* Usually just dispatched the draw call to the Region's draw implementation,
* e.g. {@link com.jogamp.graph.curve.opengl.GLRegion#draw(GL2ES2, RenderState, int, int, int[]) GLRegion#draw(GL2ES2, RenderState, int, int, int[])}.
*/
- protected abstract void drawImpl(GL2ES2 gl, Region region, float[] position, int[] texWidth);
+ protected abstract void drawImpl(GL2ES2 gl, Region region, int[] texWidth);
@Override
protected void destroyImpl(GL2ES2 gl) {
diff --git a/src/jogl/classes/com/jogamp/graph/curve/opengl/Renderer.java b/src/jogl/classes/com/jogamp/graph/curve/opengl/Renderer.java
index 029286601..31e4f0b8f 100644
--- a/src/jogl/classes/com/jogamp/graph/curve/opengl/Renderer.java
+++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/Renderer.java
@@ -102,7 +102,7 @@ public abstract class Renderer {
* Initialize shader and bindings for GPU based rendering bound to the given GL object's GLContext
* if not initialized yet.
* <p>Leaves the renderer enabled, ie ShaderState.</p>
- * <p>Shall be called by a {@code draw()} method, e.g. {@link RegionRenderer#draw(GL2ES2, Region, float[], int)}</p>
+ * <p>Shall be called by a {@code draw()} method, e.g. {@link RegionRenderer#draw(GL2ES2, Region, int)}</p>
*
* @param gl referencing the current GLContext to which the ShaderState is bound to
* @throws GLException if initialization failed
diff --git a/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRenderer.java b/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRenderer.java
index f6ce852d8..44007ca79 100644
--- a/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRenderer.java
+++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRenderer.java
@@ -35,8 +35,15 @@ import javax.media.opengl.GL2ES2;
import jogamp.graph.curve.text.GlyphString;
+import com.jogamp.graph.curve.OutlineShape;
import com.jogamp.graph.font.Font;
+import com.jogamp.graph.geom.Vertex.Factory;
+/**
+ * @deprecated use {@link com.jogamp.graph.font.Font#getOutlineShapes(java.util.List, CharSequence, float, Factory)},
+ * {@link com.jogamp.graph.curve.Region#create(OutlineShape, int)}
+ * and a {@link com.jogamp.graph.curve.opengl.RegionRenderer}.
+ */
public abstract class TextRenderer extends Renderer {
/**
* Create a Hardware accelerated Text Renderer.
@@ -57,14 +64,13 @@ public abstract class TextRenderer extends Renderer {
* @param gl the current GL state
* @param font {@link Font} to be used
* @param str text to be rendered
- * @param position the lower left corner of the string
* @param fontSize font size
* @param texWidth desired texture width for multipass-rendering.
* The actual used texture-width is written back when mp rendering is enabled, otherwise the store is untouched.
* @throws Exception if TextRenderer not initialized
*/
public abstract void drawString3D(GL2ES2 gl, Font font,
- String str, float[] position, int fontSize, int[/*1*/] texSize);
+ String str, int fontSize, int[/*1*/] texSize);
/**Create the resulting {@link GlyphString} that represents
* the String wrt to the font.
@@ -187,7 +193,7 @@ public abstract class TextRenderer extends Renderer {
/** Default cache limit, see {@link #setCacheLimit(int)} */
public static final int DEFAULT_CACHE_LIMIT = 256;
- private HashMap<String, GlyphString> stringCacheMap = new HashMap<String, GlyphString>(DEFAULT_CACHE_LIMIT);
- private ArrayList<String> stringCacheArray = new ArrayList<String>(DEFAULT_CACHE_LIMIT);
+ private final HashMap<String, GlyphString> stringCacheMap = new HashMap<String, GlyphString>(DEFAULT_CACHE_LIMIT);
+ private final ArrayList<String> stringCacheArray = new ArrayList<String>(DEFAULT_CACHE_LIMIT);
private int stringCacheLimit = DEFAULT_CACHE_LIMIT;
} \ No newline at end of file
diff --git a/src/jogl/classes/com/jogamp/graph/font/Font.java b/src/jogl/classes/com/jogamp/graph/font/Font.java
index a4a8fd53d..6c0041de9 100644
--- a/src/jogl/classes/com/jogamp/graph/font/Font.java
+++ b/src/jogl/classes/com/jogamp/graph/font/Font.java
@@ -27,6 +27,11 @@
*/
package com.jogamp.graph.font;
+import java.util.List;
+
+import com.jogamp.graph.curve.OutlineShape;
+import com.jogamp.graph.geom.Vertex;
+import com.jogamp.graph.geom.Vertex.Factory;
import com.jogamp.opengl.math.geom.AABBox;
/**
@@ -82,8 +87,11 @@ public interface Font {
public Font getFont();
public char getSymbol();
+ public short getID();
+ public float getScale(float pixelSize);
public AABBox getBBox(float pixelSize);
public float getAdvance(float pixelSize, boolean useFrationalMetrics);
+ public int hashCode();
}
@@ -108,6 +116,22 @@ public interface Font {
public boolean isPrintableChar( char c );
+ /**
+ * @param glyph source of the created OutlineShape
+ * @param vertexFactory factory for vertices
+ * @return OutlineShape of the glyph
+ */
+ public OutlineShape getOutlineShape(Glyph glyph, Factory<? extends Vertex> vertexFactory);
+
+ /**
+ * @param shapes optional storage of OutlineShapes passed by user, new shapes are appended
+ * @param string source of the created OutlineShapes
+ * @param pixelSize
+ * @param vertexFactory factory for vertices
+ * @return List of OutlineShapes, one OutlineShape per character
+ */
+ public List<OutlineShape> getOutlineShapes(List<OutlineShape> shapes, CharSequence string, float pixelSize, Factory<? extends Vertex> vertexFactory);
+
/** Shall return {@link #getFullFamilyName()} */
@Override
public String toString();
diff --git a/src/jogl/classes/com/jogamp/opengl/math/VectorUtil.java b/src/jogl/classes/com/jogamp/opengl/math/VectorUtil.java
index e1e797088..053876b56 100644
--- a/src/jogl/classes/com/jogamp/opengl/math/VectorUtil.java
+++ b/src/jogl/classes/com/jogamp/opengl/math/VectorUtil.java
@@ -271,17 +271,14 @@ public class VectorUtil {
}
/** Compute Vector
+ * @param vector storage for resulting Vector V1V2
* @param v1 vertex 1
* @param v2 vertex2 2
- * @return Vector V1V2
*/
- public static float[] computeVector(float[] v1, float[] v2)
- {
- final float[] vector = new float[3];
+ public static void computeVector(float[] vector, float[] v1, float[] v2) {
vector[0] = v2[0] - v1[0];
vector[1] = v2[1] - v1[1];
vector[2] = v2[2] - v1[2];
- return vector;
}
/** Check if vertices in triangle circumcircle
@@ -292,11 +289,15 @@ public class VectorUtil {
* @return true if the vertex d is inside the circle defined by the
* vertices a, b, c. from paper by Guibas and Stolfi (1985).
*/
- public static boolean inCircle(Vert2fImmutable a, Vert2fImmutable b, Vert2fImmutable c, Vert2fImmutable d){
- return (a.getX() * a.getX() + a.getY() * a.getY()) * triArea(b, c, d) -
- (b.getX() * b.getX() + b.getY() * b.getY()) * triArea(a, c, d) +
- (c.getX() * c.getX() + c.getY() * c.getY()) * triArea(a, b, d) -
- (d.getX() * d.getX() + d.getY() * d.getY()) * triArea(a, b, c) > 0;
+ public static boolean inCircle(Vert2fImmutable a, Vert2fImmutable b, Vert2fImmutable c, Vert2fImmutable d) {
+ final float[] A = a.getCoord();
+ final float[] B = b.getCoord();
+ final float[] C = c.getCoord();
+ final float[] D = d.getCoord();
+ return (A[0] * A[0] + A[1] * A[1]) * triArea(B, C, D) -
+ (B[0] * B[0] + B[1] * B[1]) * triArea(A, C, D) +
+ (C[0] * C[0] + C[1] * C[1]) * triArea(A, B, D) -
+ (D[0] * D[0] + D[1] * D[1]) * triArea(A, B, C) > 0;
}
/** Computes oriented area of a triangle
@@ -306,8 +307,22 @@ public class VectorUtil {
* @return compute twice the area of the oriented triangle (a,b,c), the area
* is positive if the triangle is oriented counterclockwise.
*/
- public static float triArea(Vert2fImmutable a, Vert2fImmutable b, Vert2fImmutable c) {
- return (b.getX() - a.getX()) * (c.getY() - a.getY()) - (b.getY() - a.getY())*(c.getX() - a.getX());
+ public static float triArea(Vert2fImmutable a, Vert2fImmutable b, Vert2fImmutable c){
+ final float[] A = a.getCoord();
+ final float[] B = b.getCoord();
+ final float[] C = c.getCoord();
+ return (B[0] - A[0]) * (C[1] - A[1]) - (B[1] - A[1]) * (C[0] - A[0]);
+ }
+
+ /** Computes oriented area of a triangle
+ * @param A first vertex
+ * @param B second vertex
+ * @param C third vertex
+ * @return compute twice the area of the oriented triangle (a,b,c), the area
+ * is positive if the triangle is oriented counterclockwise.
+ */
+ public static float triArea(float[] A, float[] B, float[] C){
+ return (B[0] - A[0]) * (C[1] - A[1]) - (B[1] - A[1])*(C[0] - A[0]);
}
/** Check if a vertex is in triangle using
@@ -318,11 +333,13 @@ public class VectorUtil {
* @param p the vertex in question
* @return true if p is in triangle (a, b, c), false otherwise.
*/
- public static boolean vertexInTriangle(float[] a, float[] b, float[] c, float[] p){
+ public static boolean vertexInTriangle(float[] a, float[] b, float[] c,
+ float[] p,
+ float[] ac, float[] ab, float[] ap){
// Compute vectors
- final float[] ac = computeVector(a, c); //v0
- final float[] ab = computeVector(a, b); //v1
- final float[] ap = computeVector(a, p); //v2
+ computeVector(ac, a, c); //v0
+ computeVector(ab, a, b); //v1
+ computeVector(ap, a, p); //v2
// Compute dot products
final float dot00 = dot(ac, ac);
@@ -340,6 +357,72 @@ public class VectorUtil {
return (u >= 0) && (v >= 0) && (u + v < 1);
}
+ /** Check if one of three vertices are in triangle using
+ * barycentric coordinates computation.
+ * @param a first triangle vertex
+ * @param b second triangle vertex
+ * @param c third triangle vertex
+ * @param p1 the vertex in question
+ * @param p2 the vertex in question
+ * @param p3 the vertex in question
+ * @return true if p1 or p2 or p3 is in triangle (a, b, c), false otherwise.
+ */
+ public static boolean vertexInTriangle3(float[] a, float[] b, float[] c,
+ float[] p1, float[] p2, float[] p3,
+ float[] ac, float[] ab, float[] ap){
+ // Compute vectors
+ computeVector(ac, a, c); //v0
+ computeVector(ab, a, b); //v1
+
+ // Compute dot products
+ final float dotAC_AC = dot(ac, ac);
+ final float dotAC_AB = dot(ac, ab);
+ final float dotAB_AB = dot(ab, ab);
+
+ // Compute barycentric coordinates
+ final float invDenom = 1 / (dotAC_AC * dotAB_AB - dotAC_AB * dotAC_AB);
+ {
+ computeVector(ap, a, p1); //v2
+ final float dotAC_AP1 = dot(ac, ap);
+ final float dotAB_AP1 = dot(ab, ap);
+ final float u1 = (dotAB_AB * dotAC_AP1 - dotAC_AB * dotAB_AP1) * invDenom;
+ final float v1 = (dotAC_AC * dotAB_AP1 - dotAC_AB * dotAC_AP1) * invDenom;
+
+ // Check if point is in triangle
+ if ( (u1 >= 0) && (v1 >= 0) && (u1 + v1 < 1) ) {
+ return true;
+ }
+ }
+
+ {
+ computeVector(ap, a, p2); //v2
+ final float dotAC_AP2 = dot(ac, ap);
+ final float dotAB_AP2 = dot(ab, ap);
+ final float u = (dotAB_AB * dotAC_AP2 - dotAC_AB * dotAB_AP2) * invDenom;
+ final float v = (dotAC_AC * dotAB_AP2 - dotAC_AB * dotAC_AP2) * invDenom;
+
+ // Check if point is in triangle
+ if ( (u >= 0) && (v >= 0) && (u + v < 1) ) {
+ return true;
+ }
+ }
+
+ {
+ computeVector(ap, a, p3); //v2
+ final float dotAC_AP3 = dot(ac, ap);
+ final float dotAB_AP3 = dot(ab, ap);
+ final float u = (dotAB_AB * dotAC_AP3 - dotAC_AB * dotAB_AP3) * invDenom;
+ final float v = (dotAC_AC * dotAB_AP3 - dotAC_AB * dotAC_AP3) * invDenom;
+
+ // Check if point is in triangle
+ if ( (u >= 0) && (v >= 0) && (u + v < 1) ) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
/** Check if points are in ccw order
* @param a first vertex
* @param b second vertex
@@ -412,6 +495,38 @@ public class VectorUtil {
return new float[]{xi,yi,0};
}
+ /** Compute intersection between two segments
+ * @param a vertex 1 of first segment
+ * @param b vertex 2 of first segment
+ * @param c vertex 1 of second segment
+ * @param d vertex 2 of second segment
+ * @return true if the segments intersect, otherwise returns false
+ */
+ public static boolean testSeg2SegIntersection(Vert2fImmutable a, Vert2fImmutable b, Vert2fImmutable c, Vert2fImmutable d) {
+ final float[] A = a.getCoord();
+ final float[] B = b.getCoord();
+ final float[] C = c.getCoord();
+ final float[] D = d.getCoord();
+
+ final float determinant = (A[0]-B[0])*(C[1]-D[1]) - (A[1]-B[1])*(C[0]-D[0]);
+
+ if (determinant == 0) {
+ return false;
+ }
+
+ final float alpha = (A[0]*B[1]-A[1]*B[0]);
+ final float beta = (C[0]*D[1]-C[1]*D[1]);
+ final float xi = ((C[0]-D[0])*alpha-(A[0]-B[0])*beta)/determinant;
+
+ final float gamma = (xi - A[0])/(B[0] - A[0]);
+ final float gamma1 = (xi - C[0])/(D[0] - C[0]);
+ if(gamma <= 0 || gamma >= 1 || gamma1 <= 0 || gamma1 >= 1) {
+ return false;
+ }
+
+ return true;
+ }
+
/** Compute intersection between two lines
* @param a vertex 1 of first line
* @param b vertex 2 of first line
@@ -442,14 +557,9 @@ public class VectorUtil {
* @param e vertex 2 of first segment
* @return true if the segment intersects at least one segment of the triangle, false otherwise
*/
- public static boolean tri2SegIntersection(Vert2fImmutable a, Vert2fImmutable b, Vert2fImmutable c, Vert2fImmutable d, Vert2fImmutable e){
- if(seg2SegIntersection(a, b, d, e) != null)
- return true;
- if(seg2SegIntersection(b, c, d, e) != null)
- return true;
- if(seg2SegIntersection(a, c, d, e) != null)
- return true;
-
- return false;
+ public static boolean testTri2SegIntersection(Vert2fImmutable a, Vert2fImmutable b, Vert2fImmutable c, Vert2fImmutable d, Vert2fImmutable e){
+ return testSeg2SegIntersection(a, b, d, e) ||
+ testSeg2SegIntersection(b, c, d, e) ||
+ testSeg2SegIntersection(a, c, d, e) ;
}
}
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 d48677da5..5fbc28c60 100644
--- a/src/jogl/classes/com/jogamp/opengl/math/geom/AABBox.java
+++ b/src/jogl/classes/com/jogamp/opengl/math/geom/AABBox.java
@@ -353,7 +353,8 @@ public class AABBox implements Cloneable {
@Override
public final String toString() {
- return "[ "+low[0]+"/"+low[1]+"/"+low[1]+" .. "+high[0]+"/"+high[0]+"/"+high[0]+", ctr "+
- center[0]+"/"+center[1]+"/"+center[1]+" ]";
+ return "[ dim "+getWidth()+" x "+getHeight()+" x "+getDepth()+
+ ", box "+low[0]+" / "+low[1]+" / "+low[2]+" .. "+high[0]+" / "+high[1]+" / "+high[2]+
+ ", ctr "+center[0]+" / "+center[1]+" / "+center[2]+" ]";
}
}