Ported GLU tessellation code from JOGL to work within LWJGL
This commit is contained in:
parent
757f3bbbce
commit
175eb088c6
|
@ -0,0 +1,80 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2008 LWJGL Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * 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.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "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 THE COPYRIGHT OWNER 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.
|
||||
*/
|
||||
package org.lwjgl.test.glu.tessellation;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.util.glu.GLUtessellatorCallbackAdapter;
|
||||
|
||||
public class TessCallback extends GLUtessellatorCallbackAdapter {
|
||||
|
||||
public void begin(int type) {
|
||||
GL11.glBegin(type);
|
||||
}
|
||||
|
||||
public void combine(double[] coords, Object[] data, float[] weight, Object[] outData) {
|
||||
for (int i=0;i<outData.length;i++) {
|
||||
double[] combined = new double[6];
|
||||
combined[0] = coords[0];
|
||||
combined[1] = coords[1];
|
||||
combined[2] = coords[2];
|
||||
combined[3] = 1;
|
||||
combined[4] = 1;
|
||||
combined[5] = 1;
|
||||
|
||||
outData[i] = new VertexData(combined);
|
||||
}
|
||||
// vertex[0] = coords[0];
|
||||
// vertex[1] = coords[1];
|
||||
// vertex[2] = coords[2];
|
||||
//
|
||||
// for (int i = 3; i < 6; i++)
|
||||
// {
|
||||
// vertex[i] = weight[0] * vertex_data[0][i] +
|
||||
// indent indweight[1] * vertex_data[1][i] +
|
||||
// indent indweight[2] * vertex_data[2][i] +
|
||||
// indent indweight[3] * vertex_data[3][i];
|
||||
// }
|
||||
//
|
||||
// *dataOut = vertex;
|
||||
}
|
||||
|
||||
public void end() {
|
||||
GL11.glEnd();
|
||||
}
|
||||
|
||||
public void vertex(Object vertexData) {
|
||||
VertexData vertex = (VertexData) vertexData;
|
||||
|
||||
GL11.glVertex3d(vertex.data[0], vertex.data[1], vertex.data[2]);
|
||||
GL11.glColor3d(vertex.data[3], vertex.data[4], vertex.data[5]);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,195 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2008 LWJGL Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * 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.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "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 THE COPYRIGHT OWNER 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.
|
||||
*/
|
||||
package org.lwjgl.test.glu.tessellation;
|
||||
import org.lwjgl.LWJGLException;
|
||||
import org.lwjgl.opengl.Display;
|
||||
import org.lwjgl.opengl.DisplayMode;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.util.glu.GLU;
|
||||
import org.lwjgl.util.glu.GLUtessellator;
|
||||
|
||||
public class TessellationTest {
|
||||
private GLUtessellator tesselator;
|
||||
|
||||
void init()
|
||||
{
|
||||
// Create a new tessellation object
|
||||
tesselator = GLU.gluNewTess();
|
||||
|
||||
// Set callback functions
|
||||
TessCallback callback = new TessCallback();
|
||||
tesselator.gluTessCallback(GLU.GLU_TESS_VERTEX, callback);
|
||||
tesselator.gluTessCallback(GLU.GLU_TESS_BEGIN, callback);
|
||||
tesselator.gluTessCallback(GLU.GLU_TESS_END, callback);
|
||||
tesselator.gluTessCallback(GLU.GLU_TESS_COMBINE, callback);
|
||||
}
|
||||
|
||||
void setWindingRule(int windingRule)
|
||||
{
|
||||
// Set the winding rule
|
||||
tesselator.gluTessProperty(GLU.GLU_TESS_WINDING_RULE, windingRule);
|
||||
}
|
||||
|
||||
void renderContour(double obj_data[][], int num_vertices)
|
||||
{
|
||||
for (int x = 0; x < num_vertices; x++) //loop through the vertices
|
||||
{
|
||||
tesselator.gluTessVertex(obj_data[x], 0, new VertexData(obj_data[x])); //store the vertex
|
||||
}
|
||||
}
|
||||
|
||||
void beginPolygon()
|
||||
{
|
||||
tesselator.gluTessBeginPolygon(null);
|
||||
}
|
||||
|
||||
void endPolygon()
|
||||
{
|
||||
tesselator.gluTessEndPolygon();
|
||||
}
|
||||
|
||||
void beginContour()
|
||||
{
|
||||
tesselator.gluTessBeginContour();
|
||||
}
|
||||
|
||||
void endContour()
|
||||
{
|
||||
tesselator.gluTessEndContour();
|
||||
}
|
||||
|
||||
void end()
|
||||
{
|
||||
tesselator.gluDeleteTess();
|
||||
}
|
||||
|
||||
private void createDisplay() throws LWJGLException {
|
||||
int width = 300;
|
||||
int height = 300;
|
||||
|
||||
Display.setDisplayMode(new DisplayMode(width,height));
|
||||
Display.create();
|
||||
Display.setVSyncEnabled(true);
|
||||
|
||||
GL11.glEnable(GL11.GL_TEXTURE_2D);
|
||||
GL11.glShadeModel(GL11.GL_SMOOTH);
|
||||
GL11.glDisable(GL11.GL_DEPTH_TEST);
|
||||
GL11.glDisable(GL11.GL_LIGHTING);
|
||||
|
||||
GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
GL11.glClearDepth(1);
|
||||
|
||||
GL11.glEnable(GL11.GL_BLEND);
|
||||
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
GL11.glViewport(0,0,width,height);
|
||||
GL11.glMatrixMode(GL11.GL_MODELVIEW);
|
||||
|
||||
GL11.glMatrixMode(GL11.GL_PROJECTION);
|
||||
GL11.glLoadIdentity();
|
||||
GL11.glOrtho(0, width, height, 0, 1, -1);
|
||||
GL11.glMatrixMode(GL11.GL_MODELVIEW);
|
||||
}
|
||||
|
||||
private void loop() {
|
||||
while (true) {
|
||||
render();
|
||||
Display.update();
|
||||
Display.sync(100);
|
||||
|
||||
if (Display.isCloseRequested()) {
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void render() {
|
||||
GL11.glTranslatef(150,125,0);
|
||||
|
||||
GL11.glScalef(50,50,1);
|
||||
// first polygon: a star-5 vertices and color information
|
||||
double star[][] = { {0.6f, -0.1f, 0f, 1.0f, 1.0f, 1.0f},
|
||||
{1.35f, 1.4f, 0f, 1.0f, 1.0f, 1.0f},
|
||||
{2.1f, -0.1f, 0f, 1.0f, 1.0f, 1.0f},
|
||||
{0.6f, 0.9f, 0f, 1.0f, 1.0f, 1.0f},
|
||||
{2.1f, 0.9f, 0f, 1.0f, 1.0f, 1.0f} };
|
||||
|
||||
//second polygon: a quad-4 vertices; first contour
|
||||
double quad[][] = { {0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f},
|
||||
{1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f},
|
||||
{1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f},
|
||||
{0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f} };
|
||||
|
||||
//second polygon: a triangle-3 vertices; second contour
|
||||
double tri[][] = {{0.3f, 0.3f, 0.0f, 0.0f, 0.0f, 0.0f},
|
||||
{0.7f, 0.3f, 0.0f, 0.0f, 0.0f, 0.0f},
|
||||
{0.5f, 0.7f, 0.0f, 0.0f, 0.0f, 0.0f} };
|
||||
|
||||
// render the first polygon: the textured star
|
||||
|
||||
// set winding rule to positive
|
||||
setWindingRule(GLU.GLU_TESS_WINDING_POSITIVE);
|
||||
beginPolygon();
|
||||
beginContour();
|
||||
renderContour(star, 5);
|
||||
endContour();
|
||||
endPolygon();
|
||||
|
||||
// render the second polygon: triangle cut out of a quad
|
||||
|
||||
GL11.glTranslatef(-2,0,0);
|
||||
// set winding rule to odd
|
||||
setWindingRule(GLU.GLU_TESS_WINDING_ODD);
|
||||
// begin the new polygon
|
||||
beginPolygon();
|
||||
beginContour();
|
||||
renderContour(quad, 4);
|
||||
endContour();
|
||||
beginContour();
|
||||
renderContour(tri, 3);
|
||||
endContour();
|
||||
endPolygon();
|
||||
// delete the tess object
|
||||
end();
|
||||
}
|
||||
|
||||
private void start() throws LWJGLException {
|
||||
createDisplay();
|
||||
init();
|
||||
loop();
|
||||
}
|
||||
|
||||
public static void main(String[] argv) throws LWJGLException {
|
||||
TessellationTest test = new TessellationTest();
|
||||
test.start();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2008 LWJGL Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * 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.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "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 THE COPYRIGHT OWNER 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.
|
||||
*/
|
||||
package org.lwjgl.test.glu.tessellation;
|
||||
|
||||
class VertexData {
|
||||
public double[] data;
|
||||
|
||||
VertexData(double[] data) {
|
||||
this.data = data;
|
||||
}
|
||||
}
|
|
@ -37,6 +37,7 @@ import java.nio.IntBuffer;
|
|||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.Util;
|
||||
import org.lwjgl.util.glu.tessellation.GLUtessellatorImpl;
|
||||
|
||||
/**
|
||||
* GLU.java
|
||||
|
@ -86,6 +87,7 @@ public class GLU {
|
|||
|
||||
/**** Tesselation constants ****/
|
||||
|
||||
public static final double GLU_TESS_MAX_COORD = 1.0e150;
|
||||
public static final double TESS_MAX_COORD = 1.0e150;
|
||||
|
||||
/* TessProperty */
|
||||
|
@ -420,4 +422,8 @@ public class GLU {
|
|||
return Util.translateGLErrorString(error_code);
|
||||
}
|
||||
}
|
||||
|
||||
public static GLUtessellator gluNewTess() {
|
||||
return new GLUtessellatorImpl();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2008 LWJGL Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * 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.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "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 THE COPYRIGHT OWNER 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.
|
||||
*/
|
||||
|
||||
package org.lwjgl.util.glu;
|
||||
|
||||
public interface GLUtessellator {
|
||||
|
||||
public abstract void gluDeleteTess();
|
||||
|
||||
public abstract void gluTessProperty(int which, double value);
|
||||
|
||||
/* Returns tessellator property */
|
||||
public abstract void gluGetTessProperty(int which, double[] value,
|
||||
int value_offset); /* gluGetTessProperty() */
|
||||
|
||||
public abstract void gluTessNormal(double x, double y, double z);
|
||||
|
||||
public abstract void gluTessCallback(int which,
|
||||
GLUtessellatorCallback aCallback);
|
||||
|
||||
public abstract void gluTessVertex(double[] coords, int coords_offset,
|
||||
Object vertexData);
|
||||
|
||||
public abstract void gluTessBeginPolygon(Object data);
|
||||
|
||||
public abstract void gluTessBeginContour();
|
||||
|
||||
public abstract void gluTessEndContour();
|
||||
|
||||
public abstract void gluTessEndPolygon();
|
||||
|
||||
/*******************************************************/
|
||||
|
||||
/* Obsolete calls -- for backward compatibility */
|
||||
|
||||
public abstract void gluBeginPolygon();
|
||||
|
||||
/*ARGSUSED*/
|
||||
public abstract void gluNextContour(int type);
|
||||
|
||||
public abstract void gluEndPolygon();
|
||||
|
||||
}
|
|
@ -0,0 +1,388 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2008 LWJGL Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * 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.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "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 THE COPYRIGHT OWNER 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Portions Copyright (C) 2003-2006 Sun Microsystems, Inc.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/*
|
||||
** License Applicability. Except to the extent portions of this file are
|
||||
** made subject to an alternative license as permitted in the SGI Free
|
||||
** Software License B, Version 1.1 (the "License"), the contents of this
|
||||
** file are subject only to the provisions of the License. You may not use
|
||||
** this file except in compliance with the License. You may obtain a copy
|
||||
** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
|
||||
** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
|
||||
**
|
||||
** http://oss.sgi.com/projects/FreeB
|
||||
**
|
||||
** Note that, as provided in the License, the Software is distributed on an
|
||||
** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
|
||||
** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
|
||||
** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
|
||||
** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
|
||||
**
|
||||
** NOTE: The Original Code (as defined below) has been licensed to Sun
|
||||
** Microsystems, Inc. ("Sun") under the SGI Free Software License B
|
||||
** (Version 1.1), shown above ("SGI License"). Pursuant to Section
|
||||
** 3.2(3) of the SGI License, Sun is distributing the Covered Code to
|
||||
** you under an alternative license ("Alternative License"). This
|
||||
** Alternative License includes all of the provisions of the SGI License
|
||||
** except that Section 2.2 and 11 are omitted. Any differences between
|
||||
** the Alternative License and the SGI License are offered solely by Sun
|
||||
** and not by SGI.
|
||||
**
|
||||
** Original Code. The Original Code is: OpenGL Sample Implementation,
|
||||
** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
|
||||
** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
|
||||
** Copyright in any portions created by third parties is as indicated
|
||||
** elsewhere herein. All Rights Reserved.
|
||||
**
|
||||
** Additional Notice Provisions: The application programming interfaces
|
||||
** established by SGI in conjunction with the Original Code are The
|
||||
** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
|
||||
** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
|
||||
** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
|
||||
** Window System(R) (Version 1.3), released October 19, 1998. This software
|
||||
** was created using the OpenGL(R) version 1.2.1 Sample Implementation
|
||||
** published by SGI, but has not been independently verified as being
|
||||
** compliant with the OpenGL(R) version 1.2.1 Specification.
|
||||
**
|
||||
** Author: Eric Veach, July 1994
|
||||
** Java Port: Pepijn Van Eeckhoudt, July 2003
|
||||
** Java Port: Nathan Parker Burg, August 2003
|
||||
*/
|
||||
package org.lwjgl.util.glu;
|
||||
|
||||
/**
|
||||
* <b>GLUtessellatorCallback</b> interface provides methods that the user will
|
||||
* override to define the callbacks for a tessellation object.
|
||||
*
|
||||
* @author Eric Veach, July 1994
|
||||
* @author Java Port: Pepijn Van Eeckhoudt, July 2003
|
||||
* @author Java Port: Nathan Parker Burg, August 2003
|
||||
*/
|
||||
public interface GLUtessellatorCallback {
|
||||
/**
|
||||
* The <b>begin</b> callback method is invoked like
|
||||
* {@link javax.media.opengl.GL#glBegin glBegin} to indicate the start of a
|
||||
* (triangle) primitive. The method takes a single argument of type int. If
|
||||
* the <b>GLU_TESS_BOUNDARY_ONLY</b> property is set to <b>GL_FALSE</b>, then
|
||||
* the argument is set to either <b>GL_TRIANGLE_FAN</b>,
|
||||
* <b>GL_TRIANGLE_STRIP</b>, or <b>GL_TRIANGLES</b>. If the
|
||||
* <b>GLU_TESS_BOUNDARY_ONLY</b> property is set to <b>GL_TRUE</b>, then the
|
||||
* argument will be set to <b>GL_LINE_LOOP</b>.
|
||||
*
|
||||
* @param type
|
||||
* Specifics the type of begin/end pair being defined. The following
|
||||
* values are valid: <b>GL_TRIANGLE_FAN</b>, <b>GL_TRIANGLE_STRIP</b>,
|
||||
* <b>GL_TRIANGLES</b> or <b>GL_LINE_LOOP</b>.
|
||||
*
|
||||
* @see GLU#gluTessCallback gluTessCallback
|
||||
* @see #end end
|
||||
* @see #begin begin
|
||||
*/
|
||||
public void begin(int type);
|
||||
|
||||
/**
|
||||
* The same as the {@link #begin begin} callback method except that
|
||||
* it takes an additional reference argument. This reference is
|
||||
* identical to the opaque reference provided when {@link
|
||||
* GLU#gluTessBeginPolygon gluTessBeginPolygon} was called.
|
||||
*
|
||||
* @param type
|
||||
* Specifics the type of begin/end pair being defined. The following
|
||||
* values are valid: <b>GL_TRIANGLE_FAN</b>, <b>GL_TRIANGLE_STRIP</b>,
|
||||
* <b>GL_TRIANGLES</b> or <b>GL_LINE_LOOP</b>.
|
||||
* @param polygonData
|
||||
* Specifics a reference to user-defined data.
|
||||
*
|
||||
* @see GLU#gluTessCallback gluTessCallback
|
||||
* @see #endData endData
|
||||
* @see #begin begin
|
||||
*/
|
||||
public void beginData(int type, Object polygonData);
|
||||
|
||||
|
||||
/**
|
||||
* The <b>edgeFlag</b> callback method is similar to
|
||||
* {@link javax.media.opengl.GL#glEdgeFlag glEdgeFlag}. The method takes
|
||||
* a single boolean boundaryEdge that indicates which edges lie on the
|
||||
* polygon boundary. If the boundaryEdge is <b>GL_TRUE</b>, then each vertex
|
||||
* that follows begins an edge that lies on the polygon boundary, that is,
|
||||
* an edge that separates an interior region from an exterior one. If the
|
||||
* boundaryEdge is <b>GL_FALSE</b>, then each vertex that follows begins an
|
||||
* edge that lies in the polygon interior. The edge flag callback (if
|
||||
* defined) is invoked before the first vertex callback.<P>
|
||||
*
|
||||
* Since triangle fans and triangle strips do not support edge flags, the
|
||||
* begin callback is not called with <b>GL_TRIANGLE_FAN</b> or
|
||||
* <b>GL_TRIANGLE_STRIP</b> if a non-null edge flag callback is provided.
|
||||
* (If the callback is initialized to null, there is no impact on
|
||||
* performance). Instead, the fans and strips are converted to independent
|
||||
* triangles.
|
||||
*
|
||||
* @param boundaryEdge
|
||||
* Specifics which edges lie on the polygon boundary.
|
||||
*
|
||||
* @see GLU#gluTessCallback gluTessCallback
|
||||
* @see #edgeFlagData edgeFlagData
|
||||
*/
|
||||
public void edgeFlag(boolean boundaryEdge);
|
||||
|
||||
|
||||
/**
|
||||
* The same as the {@link #edgeFlag edgeFlage} callback method
|
||||
* except that it takes an additional reference argument. This
|
||||
* reference is identical to the opaque reference provided when
|
||||
* {@link GLU#gluTessBeginPolygon gluTessBeginPolygon} was called.
|
||||
*
|
||||
* @param boundaryEdge
|
||||
* Specifics which edges lie on the polygon boundary.
|
||||
* @param polygonData
|
||||
* Specifics a reference to user-defined data.
|
||||
*
|
||||
* @see GLU#gluTessCallback gluTessCallback
|
||||
* @see #edgeFlag edgeFlag
|
||||
*/
|
||||
public void edgeFlagData(boolean boundaryEdge, Object polygonData);
|
||||
|
||||
|
||||
/**
|
||||
* The <b>vertex</b> callback method is invoked between the {@link
|
||||
* #begin begin} and {@link #end end} callback methods. It is
|
||||
* similar to {@link javax.media.opengl.GL#glVertex3f glVertex3f},
|
||||
* and it defines the vertices of the triangles created by the
|
||||
* tessellation process. The method takes a reference as its only
|
||||
* argument. This reference is identical to the opaque reference
|
||||
* provided by the user when the vertex was described (see {@link
|
||||
* GLU#gluTessVertex gluTessVertex}).
|
||||
*
|
||||
* @param vertexData
|
||||
* Specifics a reference to the vertices of the triangles created
|
||||
* byt the tessellatin process.
|
||||
*
|
||||
* @see GLU#gluTessCallback gluTessCallback
|
||||
* @see #vertexData vertexData
|
||||
*/
|
||||
public void vertex(Object vertexData);
|
||||
|
||||
|
||||
/**
|
||||
* The same as the {@link #vertex vertex} callback method except
|
||||
* that it takes an additional reference argument. This reference is
|
||||
* identical to the opaque reference provided when {@link
|
||||
* GLU#gluTessBeginPolygon gluTessBeginPolygon} was called.
|
||||
*
|
||||
* @param vertexData
|
||||
* Specifics a reference to the vertices of the triangles created
|
||||
* byt the tessellatin process.
|
||||
* @param polygonData
|
||||
* Specifics a reference to user-defined data.
|
||||
*
|
||||
* @see GLU#gluTessCallback gluTessCallback
|
||||
* @see #vertex vertex
|
||||
*/
|
||||
public void vertexData(Object vertexData, Object polygonData);
|
||||
|
||||
|
||||
/**
|
||||
* The end callback serves the same purpose as
|
||||
* {@link javax.media.opengl.GL#glEnd glEnd}. It indicates the end of a
|
||||
* primitive and it takes no arguments.
|
||||
*
|
||||
* @see GLU#gluTessCallback gluTessCallback
|
||||
* @see #begin begin
|
||||
* @see #endData endData
|
||||
*/
|
||||
public void end();
|
||||
|
||||
|
||||
/**
|
||||
* The same as the {@link #end end} callback method except that it
|
||||
* takes an additional reference argument. This reference is
|
||||
* identical to the opaque reference provided when {@link
|
||||
* GLU#gluTessBeginPolygon gluTessBeginPolygon} was called.
|
||||
*
|
||||
* @param polygonData
|
||||
* Specifics a reference to user-defined data.
|
||||
*
|
||||
* @see GLU#gluTessCallback gluTessCallback
|
||||
* @see #beginData beginData
|
||||
* @see #end end
|
||||
*/
|
||||
public void endData(Object polygonData);
|
||||
|
||||
|
||||
/**
|
||||
* The <b>combine</b> callback method is called to create a new vertex when
|
||||
* the tessellation detects an intersection, or wishes to merge features. The
|
||||
* method takes four arguments: an array of three elements each of type
|
||||
* double, an array of four references, an array of four elements each of
|
||||
* type float, and a reference to a reference.<P>
|
||||
*
|
||||
* The vertex is defined as a linear combination of up to four existing
|
||||
* vertices, stored in <i>data</i>. The coefficients of the linear combination
|
||||
* are given by <i>weight</i>; these weights always add up to 1. All vertex
|
||||
* pointers are valid even when some of the weights are 0. <i>coords</i> gives
|
||||
* the location of the new vertex.<P>
|
||||
*
|
||||
* The user must allocate another vertex, interpolate parameters using
|
||||
* <i>data</i> and <i>weight</i>, and return the new vertex pointer in
|
||||
* <i>outData</i>. This handle is supplied during rendering callbacks. The
|
||||
* user is responsible for freeing the memory some time after
|
||||
* {@link GLU#gluTessEndPolygon gluTessEndPolygon} is
|
||||
* called.<P>
|
||||
*
|
||||
* For example, if the polygon lies in an arbitrary plane in 3-space, and a
|
||||
* color is associated with each vertex, the <b>GLU_TESS_COMBINE</b>
|
||||
* callback might look like this:
|
||||
* </UL>
|
||||
* <PRE>
|
||||
* void myCombine(double[] coords, Object[] data,
|
||||
* float[] weight, Object[] outData)
|
||||
* {
|
||||
* MyVertex newVertex = new MyVertex();
|
||||
*
|
||||
* newVertex.x = coords[0];
|
||||
* newVertex.y = coords[1];
|
||||
* newVertex.z = coords[2];
|
||||
* newVertex.r = weight[0]*data[0].r +
|
||||
* weight[1]*data[1].r +
|
||||
* weight[2]*data[2].r +
|
||||
* weight[3]*data[3].r;
|
||||
* newVertex.g = weight[0]*data[0].g +
|
||||
* weight[1]*data[1].g +
|
||||
* weight[2]*data[2].g +
|
||||
* weight[3]*data[3].g;
|
||||
* newVertex.b = weight[0]*data[0].b +
|
||||
* weight[1]*data[1].b +
|
||||
* weight[2]*data[2].b +
|
||||
* weight[3]*data[3].b;
|
||||
* newVertex.a = weight[0]*data[0].a +
|
||||
* weight[1]*data[1].a +
|
||||
* weight[2]*data[2].a +
|
||||
* weight[3]*data[3].a;
|
||||
* outData = newVertex;
|
||||
* }</PRE>
|
||||
*
|
||||
* @param coords
|
||||
* Specifics the location of the new vertex.
|
||||
* @param data
|
||||
* Specifics the vertices used to create the new vertex.
|
||||
* @param weight
|
||||
* Specifics the weights used to create the new vertex.
|
||||
* @param outData
|
||||
* Reference user the put the coodinates of the new vertex.
|
||||
*
|
||||
* @see GLU#gluTessCallback gluTessCallback
|
||||
* @see #combineData combineData
|
||||
*/
|
||||
public void combine(double[] coords, Object[] data,
|
||||
float[] weight, Object[] outData);
|
||||
|
||||
|
||||
/**
|
||||
* The same as the {@link #combine combine} callback method except
|
||||
* that it takes an additional reference argument. This reference is
|
||||
* identical to the opaque reference provided when {@link
|
||||
* GLU#gluTessBeginPolygon gluTessBeginPolygon} was called.
|
||||
*
|
||||
* @param coords
|
||||
* Specifics the location of the new vertex.
|
||||
* @param data
|
||||
* Specifics the vertices used to create the new vertex.
|
||||
* @param weight
|
||||
* Specifics the weights used to create the new vertex.
|
||||
* @param outData
|
||||
* Reference user the put the coodinates of the new vertex.
|
||||
* @param polygonData
|
||||
* Specifics a reference to user-defined data.
|
||||
*
|
||||
* @see GLU#gluTessCallback gluTessCallback
|
||||
* @see #combine combine
|
||||
*/
|
||||
public void combineData(double[] coords, Object[] data,
|
||||
float[] weight, Object[] outData,
|
||||
Object polygonData);
|
||||
|
||||
|
||||
/**
|
||||
* The <b>error</b> callback method is called when an error is encountered.
|
||||
* The one argument is of type int; it indicates the specific error that
|
||||
* occurred and will be set to one of <b>GLU_TESS_MISSING_BEGIN_POLYGON</b>,
|
||||
* <b>GLU_TESS_MISSING_END_POLYGON</b>, <b>GLU_TESS_MISSING_BEGIN_CONTOUR</b>,
|
||||
* <b>GLU_TESS_MISSING_END_CONTOUR</b>, <b>GLU_TESS_COORD_TOO_LARGE</b>,
|
||||
* <b>GLU_TESS_NEED_COMBINE_CALLBACK</b> or <b>GLU_OUT_OF_MEMORY</b>.
|
||||
* Character strings describing these errors can be retrieved with the
|
||||
* {@link GLU#gluErrorString gluErrorString} call.<P>
|
||||
*
|
||||
* The GLU library will recover from the first four errors by inserting the
|
||||
* missing call(s). <b>GLU_TESS_COORD_TOO_LARGE</b> indicates that some
|
||||
* vertex coordinate exceeded the predefined constant
|
||||
* <b>GLU_TESS_MAX_COORD</b> in absolute value, and that the value has been
|
||||
* clamped. (Coordinate values must be small enough so that two can be
|
||||
* multiplied together without overflow.)
|
||||
* <b>GLU_TESS_NEED_COMBINE_CALLBACK</b> indicates that the tessellation
|
||||
* detected an intersection between two edges in the input data, and the
|
||||
* <b>GLU_TESS_COMBINE</b> or <b>GLU_TESS_COMBINE_DATA</b> callback was not
|
||||
* provided. No output is generated. <b>GLU_OUT_OF_MEMORY</b> indicates that
|
||||
* there is not enough memory so no output is generated.
|
||||
*
|
||||
* @param errnum
|
||||
* Specifics the error number code.
|
||||
*
|
||||
* @see GLU#gluTessCallback gluTessCallback
|
||||
* @see #errorData errorData
|
||||
*/
|
||||
public void error(int errnum);
|
||||
|
||||
|
||||
/**
|
||||
* The same as the {@link #error error} callback method except that
|
||||
* it takes an additional reference argument. This reference is
|
||||
* identical to the opaque reference provided when {@link
|
||||
* GLU#gluTessBeginPolygon gluTessBeginPolygon} was called.
|
||||
*
|
||||
* @param errnum
|
||||
* Specifics the error number code.
|
||||
* @param polygonData
|
||||
* Specifics a reference to user-defined data.
|
||||
*
|
||||
* @see GLU#gluTessCallback gluTessCallback
|
||||
* @see #error error
|
||||
*/
|
||||
public void errorData(int errnum, Object polygonData);
|
||||
|
||||
//void mesh(com.sun.opengl.impl.tessellator.GLUmesh mesh);
|
||||
}
|
|
@ -0,0 +1,116 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2008 LWJGL Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * 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.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "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 THE COPYRIGHT OWNER 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Portions Copyright (C) 2003-2006 Sun Microsystems, Inc.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/*
|
||||
** License Applicability. Except to the extent portions of this file are
|
||||
** made subject to an alternative license as permitted in the SGI Free
|
||||
** Software License B, Version 1.1 (the "License"), the contents of this
|
||||
** file are subject only to the provisions of the License. You may not use
|
||||
** this file except in compliance with the License. You may obtain a copy
|
||||
** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
|
||||
** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
|
||||
**
|
||||
** http://oss.sgi.com/projects/FreeB
|
||||
**
|
||||
** Note that, as provided in the License, the Software is distributed on an
|
||||
** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
|
||||
** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
|
||||
** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
|
||||
** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
|
||||
**
|
||||
** NOTE: The Original Code (as defined below) has been licensed to Sun
|
||||
** Microsystems, Inc. ("Sun") under the SGI Free Software License B
|
||||
** (Version 1.1), shown above ("SGI License"). Pursuant to Section
|
||||
** 3.2(3) of the SGI License, Sun is distributing the Covered Code to
|
||||
** you under an alternative license ("Alternative License"). This
|
||||
** Alternative License includes all of the provisions of the SGI License
|
||||
** except that Section 2.2 and 11 are omitted. Any differences between
|
||||
** the Alternative License and the SGI License are offered solely by Sun
|
||||
** and not by SGI.
|
||||
**
|
||||
** Original Code. The Original Code is: OpenGL Sample Implementation,
|
||||
** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
|
||||
** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
|
||||
** Copyright in any portions created by third parties is as indicated
|
||||
** elsewhere herein. All Rights Reserved.
|
||||
**
|
||||
** Additional Notice Provisions: The application programming interfaces
|
||||
** established by SGI in conjunction with the Original Code are The
|
||||
** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
|
||||
** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
|
||||
** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
|
||||
** Window System(R) (Version 1.3), released October 19, 1998. This software
|
||||
** was created using the OpenGL(R) version 1.2.1 Sample Implementation
|
||||
** published by SGI, but has not been independently verified as being
|
||||
** compliant with the OpenGL(R) version 1.2.1 Specification.
|
||||
**
|
||||
** Author: Eric Veach, July 1994
|
||||
** Java Port: Pepijn Van Eeckhoudt, July 2003
|
||||
** Java Port: Nathan Parker Burg, August 2003
|
||||
*/
|
||||
package org.lwjgl.util.glu;
|
||||
|
||||
/**
|
||||
* The <b>GLUtessellatorCallbackAdapter</b> provides a default implementation of
|
||||
* {@link GLUtessellatorCallback GLUtessellatorCallback}
|
||||
* with empty callback methods. This class can be extended to provide user
|
||||
* defined callback methods.
|
||||
*
|
||||
* @author Eric Veach, July 1994
|
||||
* @author Java Port: Pepijn Van Eechhoudt, July 2003
|
||||
* @author Java Port: Nathan Parker Burg, August 2003
|
||||
*/
|
||||
|
||||
public class GLUtessellatorCallbackAdapter implements GLUtessellatorCallback {
|
||||
public void begin(int type) {}
|
||||
public void edgeFlag(boolean boundaryEdge) {}
|
||||
public void vertex(Object vertexData) {}
|
||||
public void end() {}
|
||||
// public void mesh(com.sun.opengl.impl.tessellator.GLUmesh mesh) {}
|
||||
public void error(int errnum) {}
|
||||
public void combine(double[] coords, Object[] data,
|
||||
float[] weight, Object[] outData) {}
|
||||
public void beginData(int type, Object polygonData) {}
|
||||
public void edgeFlagData(boolean boundaryEdge,
|
||||
Object polygonData) {}
|
||||
public void vertexData(Object vertexData, Object polygonData) {}
|
||||
public void endData(Object polygonData) {}
|
||||
public void errorData(int errnum, Object polygonData) {}
|
||||
public void combineData(double[] coords, Object[] data,
|
||||
float[] weight, Object[] outData,
|
||||
Object polygonData) {}
|
||||
}
|
|
@ -0,0 +1,100 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2008 LWJGL Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * 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.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "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 THE COPYRIGHT OWNER 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Portions Copyright (C) 2003-2006 Sun Microsystems, Inc.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/*
|
||||
** License Applicability. Except to the extent portions of this file are
|
||||
** made subject to an alternative license as permitted in the SGI Free
|
||||
** Software License B, Version 1.1 (the "License"), the contents of this
|
||||
** file are subject only to the provisions of the License. You may not use
|
||||
** this file except in compliance with the License. You may obtain a copy
|
||||
** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
|
||||
** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
|
||||
**
|
||||
** http://oss.sgi.com/projects/FreeB
|
||||
**
|
||||
** Note that, as provided in the License, the Software is distributed on an
|
||||
** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
|
||||
** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
|
||||
** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
|
||||
** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
|
||||
**
|
||||
** NOTE: The Original Code (as defined below) has been licensed to Sun
|
||||
** Microsystems, Inc. ("Sun") under the SGI Free Software License B
|
||||
** (Version 1.1), shown above ("SGI License"). Pursuant to Section
|
||||
** 3.2(3) of the SGI License, Sun is distributing the Covered Code to
|
||||
** you under an alternative license ("Alternative License"). This
|
||||
** Alternative License includes all of the provisions of the SGI License
|
||||
** except that Section 2.2 and 11 are omitted. Any differences between
|
||||
** the Alternative License and the SGI License are offered solely by Sun
|
||||
** and not by SGI.
|
||||
**
|
||||
** Original Code. The Original Code is: OpenGL Sample Implementation,
|
||||
** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
|
||||
** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
|
||||
** Copyright in any portions created by third parties is as indicated
|
||||
** elsewhere herein. All Rights Reserved.
|
||||
**
|
||||
** Additional Notice Provisions: The application programming interfaces
|
||||
** established by SGI in conjunction with the Original Code are The
|
||||
** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
|
||||
** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
|
||||
** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
|
||||
** Window System(R) (Version 1.3), released October 19, 1998. This software
|
||||
** was created using the OpenGL(R) version 1.2.1 Sample Implementation
|
||||
** published by SGI, but has not been independently verified as being
|
||||
** compliant with the OpenGL(R) version 1.2.1 Specification.
|
||||
**
|
||||
** Author: Eric Veach, July 1994
|
||||
** Java Port: Pepijn Van Eeckhoudt, July 2003
|
||||
** Java Port: Nathan Parker Burg, August 2003
|
||||
*/
|
||||
package org.lwjgl.util.glu.tessellation;
|
||||
|
||||
class ActiveRegion {
|
||||
GLUhalfEdge eUp; /* upper edge, directed right to left */
|
||||
DictNode nodeUp; /* dictionary node corresponding to eUp */
|
||||
int windingNumber; /* used to determine which regions are
|
||||
* inside the polygon */
|
||||
boolean inside; /* is this region inside the polygon? */
|
||||
boolean sentinel; /* marks fake edges at t = +/-infinity */
|
||||
boolean dirty; /* marks regions where the upper or lower
|
||||
* edge has changed, but we haven't checked
|
||||
* whether they intersect yet */
|
||||
boolean fixUpperEdge; /* marks temporary edges introduced when
|
||||
* we process a "right vertex" (one without
|
||||
* any edges leaving to the right) */
|
||||
}
|
|
@ -0,0 +1,90 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2008 LWJGL Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * 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.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "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 THE COPYRIGHT OWNER 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Portions Copyright (C) 2003-2006 Sun Microsystems, Inc.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/*
|
||||
** License Applicability. Except to the extent portions of this file are
|
||||
** made subject to an alternative license as permitted in the SGI Free
|
||||
** Software License B, Version 1.1 (the "License"), the contents of this
|
||||
** file are subject only to the provisions of the License. You may not use
|
||||
** this file except in compliance with the License. You may obtain a copy
|
||||
** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
|
||||
** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
|
||||
**
|
||||
** http://oss.sgi.com/projects/FreeB
|
||||
**
|
||||
** Note that, as provided in the License, the Software is distributed on an
|
||||
** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
|
||||
** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
|
||||
** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
|
||||
** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
|
||||
**
|
||||
** NOTE: The Original Code (as defined below) has been licensed to Sun
|
||||
** Microsystems, Inc. ("Sun") under the SGI Free Software License B
|
||||
** (Version 1.1), shown above ("SGI License"). Pursuant to Section
|
||||
** 3.2(3) of the SGI License, Sun is distributing the Covered Code to
|
||||
** you under an alternative license ("Alternative License"). This
|
||||
** Alternative License includes all of the provisions of the SGI License
|
||||
** except that Section 2.2 and 11 are omitted. Any differences between
|
||||
** the Alternative License and the SGI License are offered solely by Sun
|
||||
** and not by SGI.
|
||||
**
|
||||
** Original Code. The Original Code is: OpenGL Sample Implementation,
|
||||
** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
|
||||
** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
|
||||
** Copyright in any portions created by third parties is as indicated
|
||||
** elsewhere herein. All Rights Reserved.
|
||||
**
|
||||
** Additional Notice Provisions: The application programming interfaces
|
||||
** established by SGI in conjunction with the Original Code are The
|
||||
** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
|
||||
** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
|
||||
** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
|
||||
** Window System(R) (Version 1.3), released October 19, 1998. This software
|
||||
** was created using the OpenGL(R) version 1.2.1 Sample Implementation
|
||||
** published by SGI, but has not been independently verified as being
|
||||
** compliant with the OpenGL(R) version 1.2.1 Specification.
|
||||
**
|
||||
** Author: Eric Veach, July 1994
|
||||
** Java Port: Pepijn Van Eeckhoudt, July 2003
|
||||
** Java Port: Nathan Parker Burg, August 2003
|
||||
*/
|
||||
package org.lwjgl.util.glu.tessellation;
|
||||
|
||||
class CachedVertex {
|
||||
public double[] coords = new double[3];
|
||||
public Object data;
|
||||
}
|
|
@ -0,0 +1,172 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2008 LWJGL Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * 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.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "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 THE COPYRIGHT OWNER 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Portions Copyright (C) 2003-2006 Sun Microsystems, Inc.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/*
|
||||
** License Applicability. Except to the extent portions of this file are
|
||||
** made subject to an alternative license as permitted in the SGI Free
|
||||
** Software License B, Version 1.1 (the "License"), the contents of this
|
||||
** file are subject only to the provisions of the License. You may not use
|
||||
** this file except in compliance with the License. You may obtain a copy
|
||||
** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
|
||||
** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
|
||||
**
|
||||
** http://oss.sgi.com/projects/FreeB
|
||||
**
|
||||
** Note that, as provided in the License, the Software is distributed on an
|
||||
** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
|
||||
** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
|
||||
** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
|
||||
** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
|
||||
**
|
||||
** NOTE: The Original Code (as defined below) has been licensed to Sun
|
||||
** Microsystems, Inc. ("Sun") under the SGI Free Software License B
|
||||
** (Version 1.1), shown above ("SGI License"). Pursuant to Section
|
||||
** 3.2(3) of the SGI License, Sun is distributing the Covered Code to
|
||||
** you under an alternative license ("Alternative License"). This
|
||||
** Alternative License includes all of the provisions of the SGI License
|
||||
** except that Section 2.2 and 11 are omitted. Any differences between
|
||||
** the Alternative License and the SGI License are offered solely by Sun
|
||||
** and not by SGI.
|
||||
**
|
||||
** Original Code. The Original Code is: OpenGL Sample Implementation,
|
||||
** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
|
||||
** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
|
||||
** Copyright in any portions created by third parties is as indicated
|
||||
** elsewhere herein. All Rights Reserved.
|
||||
**
|
||||
** Additional Notice Provisions: The application programming interfaces
|
||||
** established by SGI in conjunction with the Original Code are The
|
||||
** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
|
||||
** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
|
||||
** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
|
||||
** Window System(R) (Version 1.3), released October 19, 1998. This software
|
||||
** was created using the OpenGL(R) version 1.2.1 Sample Implementation
|
||||
** published by SGI, but has not been independently verified as being
|
||||
** compliant with the OpenGL(R) version 1.2.1 Specification.
|
||||
**
|
||||
** Author: Eric Veach, July 1994
|
||||
** Java Port: Pepijn Van Eeckhoudt, July 2003
|
||||
** Java Port: Nathan Parker Burg, August 2003
|
||||
*/
|
||||
package org.lwjgl.util.glu.tessellation;
|
||||
|
||||
class Dict {
|
||||
DictNode head;
|
||||
Object frame;
|
||||
DictLeq leq;
|
||||
|
||||
private Dict() {
|
||||
}
|
||||
|
||||
static Dict dictNewDict(Object frame, DictLeq leq) {
|
||||
Dict dict = new Dict();
|
||||
dict.head = new DictNode();
|
||||
|
||||
dict.head.key = null;
|
||||
dict.head.next = dict.head;
|
||||
dict.head.prev = dict.head;
|
||||
|
||||
dict.frame = frame;
|
||||
dict.leq = leq;
|
||||
|
||||
return dict;
|
||||
}
|
||||
|
||||
static void dictDeleteDict(Dict dict) {
|
||||
dict.head = null;
|
||||
dict.frame = null;
|
||||
dict.leq = null;
|
||||
}
|
||||
|
||||
static DictNode dictInsert(Dict dict, Object key) {
|
||||
return dictInsertBefore(dict, dict.head, key);
|
||||
}
|
||||
|
||||
static DictNode dictInsertBefore(Dict dict, DictNode node, Object key) {
|
||||
do {
|
||||
node = node.prev;
|
||||
} while (node.key != null && !dict.leq.leq(dict.frame, node.key, key));
|
||||
|
||||
DictNode newNode = new DictNode();
|
||||
newNode.key = key;
|
||||
newNode.next = node.next;
|
||||
node.next.prev = newNode;
|
||||
newNode.prev = node;
|
||||
node.next = newNode;
|
||||
|
||||
return newNode;
|
||||
}
|
||||
|
||||
static Object dictKey(DictNode aNode) {
|
||||
return aNode.key;
|
||||
}
|
||||
|
||||
static DictNode dictSucc(DictNode aNode) {
|
||||
return aNode.next;
|
||||
}
|
||||
|
||||
static DictNode dictPred(DictNode aNode) {
|
||||
return aNode.prev;
|
||||
}
|
||||
|
||||
static DictNode dictMin(Dict aDict) {
|
||||
return aDict.head.next;
|
||||
}
|
||||
|
||||
static DictNode dictMax(Dict aDict) {
|
||||
return aDict.head.prev;
|
||||
}
|
||||
|
||||
static void dictDelete(Dict dict, DictNode node) {
|
||||
node.next.prev = node.prev;
|
||||
node.prev.next = node.next;
|
||||
}
|
||||
|
||||
static DictNode dictSearch(Dict dict, Object key) {
|
||||
DictNode node = dict.head;
|
||||
|
||||
do {
|
||||
node = node.next;
|
||||
} while (node.key != null && !(dict.leq.leq(dict.frame, key, node.key)));
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
public interface DictLeq {
|
||||
boolean leq(Object frame, Object key1, Object key2);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,91 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2008 LWJGL Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * 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.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "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 THE COPYRIGHT OWNER 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Portions Copyright (C) 2003-2006 Sun Microsystems, Inc.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/*
|
||||
** License Applicability. Except to the extent portions of this file are
|
||||
** made subject to an alternative license as permitted in the SGI Free
|
||||
** Software License B, Version 1.1 (the "License"), the contents of this
|
||||
** file are subject only to the provisions of the License. You may not use
|
||||
** this file except in compliance with the License. You may obtain a copy
|
||||
** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
|
||||
** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
|
||||
**
|
||||
** http://oss.sgi.com/projects/FreeB
|
||||
**
|
||||
** Note that, as provided in the License, the Software is distributed on an
|
||||
** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
|
||||
** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
|
||||
** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
|
||||
** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
|
||||
**
|
||||
** NOTE: The Original Code (as defined below) has been licensed to Sun
|
||||
** Microsystems, Inc. ("Sun") under the SGI Free Software License B
|
||||
** (Version 1.1), shown above ("SGI License"). Pursuant to Section
|
||||
** 3.2(3) of the SGI License, Sun is distributing the Covered Code to
|
||||
** you under an alternative license ("Alternative License"). This
|
||||
** Alternative License includes all of the provisions of the SGI License
|
||||
** except that Section 2.2 and 11 are omitted. Any differences between
|
||||
** the Alternative License and the SGI License are offered solely by Sun
|
||||
** and not by SGI.
|
||||
**
|
||||
** Original Code. The Original Code is: OpenGL Sample Implementation,
|
||||
** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
|
||||
** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
|
||||
** Copyright in any portions created by third parties is as indicated
|
||||
** elsewhere herein. All Rights Reserved.
|
||||
**
|
||||
** Additional Notice Provisions: The application programming interfaces
|
||||
** established by SGI in conjunction with the Original Code are The
|
||||
** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
|
||||
** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
|
||||
** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
|
||||
** Window System(R) (Version 1.3), released October 19, 1998. This software
|
||||
** was created using the OpenGL(R) version 1.2.1 Sample Implementation
|
||||
** published by SGI, but has not been independently verified as being
|
||||
** compliant with the OpenGL(R) version 1.2.1 Specification.
|
||||
**
|
||||
** Author: Eric Veach, July 1994
|
||||
** Java Port: Pepijn Van Eeckhoudt, July 2003
|
||||
** Java Port: Nathan Parker Burg, August 2003
|
||||
*/
|
||||
package org.lwjgl.util.glu.tessellation;
|
||||
|
||||
class DictNode {
|
||||
Object key;
|
||||
DictNode next;
|
||||
DictNode prev;
|
||||
}
|
|
@ -0,0 +1,97 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2008 LWJGL Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * 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.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "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 THE COPYRIGHT OWNER 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Portions Copyright (C) 2003-2006 Sun Microsystems, Inc.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/*
|
||||
** License Applicability. Except to the extent portions of this file are
|
||||
** made subject to an alternative license as permitted in the SGI Free
|
||||
** Software License B, Version 1.1 (the "License"), the contents of this
|
||||
** file are subject only to the provisions of the License. You may not use
|
||||
** this file except in compliance with the License. You may obtain a copy
|
||||
** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
|
||||
** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
|
||||
**
|
||||
** http://oss.sgi.com/projects/FreeB
|
||||
**
|
||||
** Note that, as provided in the License, the Software is distributed on an
|
||||
** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
|
||||
** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
|
||||
** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
|
||||
** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
|
||||
**
|
||||
** NOTE: The Original Code (as defined below) has been licensed to Sun
|
||||
** Microsystems, Inc. ("Sun") under the SGI Free Software License B
|
||||
** (Version 1.1), shown above ("SGI License"). Pursuant to Section
|
||||
** 3.2(3) of the SGI License, Sun is distributing the Covered Code to
|
||||
** you under an alternative license ("Alternative License"). This
|
||||
** Alternative License includes all of the provisions of the SGI License
|
||||
** except that Section 2.2 and 11 are omitted. Any differences between
|
||||
** the Alternative License and the SGI License are offered solely by Sun
|
||||
** and not by SGI.
|
||||
**
|
||||
** Original Code. The Original Code is: OpenGL Sample Implementation,
|
||||
** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
|
||||
** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
|
||||
** Copyright in any portions created by third parties is as indicated
|
||||
** elsewhere herein. All Rights Reserved.
|
||||
**
|
||||
** Additional Notice Provisions: The application programming interfaces
|
||||
** established by SGI in conjunction with the Original Code are The
|
||||
** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
|
||||
** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
|
||||
** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
|
||||
** Window System(R) (Version 1.3), released October 19, 1998. This software
|
||||
** was created using the OpenGL(R) version 1.2.1 Sample Implementation
|
||||
** published by SGI, but has not been independently verified as being
|
||||
** compliant with the OpenGL(R) version 1.2.1 Specification.
|
||||
**
|
||||
** Author: Eric Veach, July 1994
|
||||
** Java Port: Pepijn Van Eeckhoudt, July 2003
|
||||
** Java Port: Nathan Parker Burg, August 2003
|
||||
*/
|
||||
package org.lwjgl.util.glu.tessellation;
|
||||
|
||||
class GLUface {
|
||||
public GLUface next; /* next face (never NULL) */
|
||||
public GLUface prev; /* previous face (never NULL) */
|
||||
public GLUhalfEdge anEdge; /* a half edge with this left face */
|
||||
public Object data; /* room for client's data */
|
||||
|
||||
/* Internal data (keep hidden) */
|
||||
public GLUface trail; /* "stack" for conversion to strips */
|
||||
public boolean marked; /* flag for conversion to strips */
|
||||
public boolean inside; /* this face is in the polygon interior */
|
||||
}
|
|
@ -0,0 +1,105 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2008 LWJGL Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * 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.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "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 THE COPYRIGHT OWNER 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Portions Copyright (C) 2003-2006 Sun Microsystems, Inc.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/*
|
||||
** License Applicability. Except to the extent portions of this file are
|
||||
** made subject to an alternative license as permitted in the SGI Free
|
||||
** Software License B, Version 1.1 (the "License"), the contents of this
|
||||
** file are subject only to the provisions of the License. You may not use
|
||||
** this file except in compliance with the License. You may obtain a copy
|
||||
** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
|
||||
** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
|
||||
**
|
||||
** http://oss.sgi.com/projects/FreeB
|
||||
**
|
||||
** Note that, as provided in the License, the Software is distributed on an
|
||||
** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
|
||||
** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
|
||||
** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
|
||||
** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
|
||||
**
|
||||
** NOTE: The Original Code (as defined below) has been licensed to Sun
|
||||
** Microsystems, Inc. ("Sun") under the SGI Free Software License B
|
||||
** (Version 1.1), shown above ("SGI License"). Pursuant to Section
|
||||
** 3.2(3) of the SGI License, Sun is distributing the Covered Code to
|
||||
** you under an alternative license ("Alternative License"). This
|
||||
** Alternative License includes all of the provisions of the SGI License
|
||||
** except that Section 2.2 and 11 are omitted. Any differences between
|
||||
** the Alternative License and the SGI License are offered solely by Sun
|
||||
** and not by SGI.
|
||||
**
|
||||
** Original Code. The Original Code is: OpenGL Sample Implementation,
|
||||
** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
|
||||
** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
|
||||
** Copyright in any portions created by third parties is as indicated
|
||||
** elsewhere herein. All Rights Reserved.
|
||||
**
|
||||
** Additional Notice Provisions: The application programming interfaces
|
||||
** established by SGI in conjunction with the Original Code are The
|
||||
** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
|
||||
** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
|
||||
** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
|
||||
** Window System(R) (Version 1.3), released October 19, 1998. This software
|
||||
** was created using the OpenGL(R) version 1.2.1 Sample Implementation
|
||||
** published by SGI, but has not been independently verified as being
|
||||
** compliant with the OpenGL(R) version 1.2.1 Specification.
|
||||
**
|
||||
** Author: Eric Veach, July 1994
|
||||
** Java Port: Pepijn Van Eeckhoudt, July 2003
|
||||
** Java Port: Nathan Parker Burg, August 2003
|
||||
*/
|
||||
package org.lwjgl.util.glu.tessellation;
|
||||
|
||||
|
||||
|
||||
class GLUhalfEdge {
|
||||
public GLUhalfEdge next; /* doubly-linked list (prev==Sym->next) */
|
||||
public GLUhalfEdge Sym; /* same edge, opposite direction */
|
||||
public GLUhalfEdge Onext; /* next edge CCW around origin */
|
||||
public GLUhalfEdge Lnext; /* next edge CCW around left face */
|
||||
public GLUvertex Org; /* origin vertex (Overtex too long) */
|
||||
public GLUface Lface; /* left face */
|
||||
|
||||
/* Internal data (keep hidden) */
|
||||
public ActiveRegion activeRegion; /* a region with this upper edge (sweep.c) */
|
||||
public int winding; /* change in winding number when crossing */
|
||||
public boolean first;
|
||||
|
||||
public GLUhalfEdge(boolean first) {
|
||||
this.first = first;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,94 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2008 LWJGL Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * 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.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "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 THE COPYRIGHT OWNER 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Portions Copyright (C) 2003-2006 Sun Microsystems, Inc.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/*
|
||||
** License Applicability. Except to the extent portions of this file are
|
||||
** made subject to an alternative license as permitted in the SGI Free
|
||||
** Software License B, Version 1.1 (the "License"), the contents of this
|
||||
** file are subject only to the provisions of the License. You may not use
|
||||
** this file except in compliance with the License. You may obtain a copy
|
||||
** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
|
||||
** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
|
||||
**
|
||||
** http://oss.sgi.com/projects/FreeB
|
||||
**
|
||||
** Note that, as provided in the License, the Software is distributed on an
|
||||
** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
|
||||
** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
|
||||
** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
|
||||
** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
|
||||
**
|
||||
** NOTE: The Original Code (as defined below) has been licensed to Sun
|
||||
** Microsystems, Inc. ("Sun") under the SGI Free Software License B
|
||||
** (Version 1.1), shown above ("SGI License"). Pursuant to Section
|
||||
** 3.2(3) of the SGI License, Sun is distributing the Covered Code to
|
||||
** you under an alternative license ("Alternative License"). This
|
||||
** Alternative License includes all of the provisions of the SGI License
|
||||
** except that Section 2.2 and 11 are omitted. Any differences between
|
||||
** the Alternative License and the SGI License are offered solely by Sun
|
||||
** and not by SGI.
|
||||
**
|
||||
** Original Code. The Original Code is: OpenGL Sample Implementation,
|
||||
** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
|
||||
** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
|
||||
** Copyright in any portions created by third parties is as indicated
|
||||
** elsewhere herein. All Rights Reserved.
|
||||
**
|
||||
** Additional Notice Provisions: The application programming interfaces
|
||||
** established by SGI in conjunction with the Original Code are The
|
||||
** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
|
||||
** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
|
||||
** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
|
||||
** Window System(R) (Version 1.3), released October 19, 1998. This software
|
||||
** was created using the OpenGL(R) version 1.2.1 Sample Implementation
|
||||
** published by SGI, but has not been independently verified as being
|
||||
** compliant with the OpenGL(R) version 1.2.1 Specification.
|
||||
**
|
||||
** Author: Eric Veach, July 1994
|
||||
** Java Port: Pepijn Van Eeckhoudt, July 2003
|
||||
** Java Port: Nathan Parker Burg, August 2003
|
||||
*/
|
||||
package org.lwjgl.util.glu.tessellation;
|
||||
|
||||
|
||||
|
||||
class GLUmesh {
|
||||
GLUvertex vHead = new GLUvertex(); /* dummy header for vertex list */
|
||||
GLUface fHead = new GLUface(); /* dummy header for face list */
|
||||
GLUhalfEdge eHead = new GLUhalfEdge(true); /* dummy header for edge list */
|
||||
GLUhalfEdge eHeadSym = new GLUhalfEdge(false); /* and its symmetric counterpart */
|
||||
}
|
|
@ -0,0 +1,668 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2008 LWJGL Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * 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.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "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 THE COPYRIGHT OWNER 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Portions Copyright (C) 2003-2006 Sun Microsystems, Inc.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/*
|
||||
** License Applicability. Except to the extent portions of this file are
|
||||
** made subject to an alternative license as permitted in the SGI Free
|
||||
** Software License B, Version 1.1 (the "License"), the contents of this
|
||||
** file are subject only to the provisions of the License. You may not use
|
||||
** this file except in compliance with the License. You may obtain a copy
|
||||
** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
|
||||
** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
|
||||
**
|
||||
** http://oss.sgi.com/projects/FreeB
|
||||
**
|
||||
** Note that, as provided in the License, the Software is distributed on an
|
||||
** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
|
||||
** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
|
||||
** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
|
||||
** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
|
||||
**
|
||||
** NOTE: The Original Code (as defined below) has been licensed to Sun
|
||||
** Microsystems, Inc. ("Sun") under the SGI Free Software License B
|
||||
** (Version 1.1), shown above ("SGI License"). Pursuant to Section
|
||||
** 3.2(3) of the SGI License, Sun is distributing the Covered Code to
|
||||
** you under an alternative license ("Alternative License"). This
|
||||
** Alternative License includes all of the provisions of the SGI License
|
||||
** except that Section 2.2 and 11 are omitted. Any differences between
|
||||
** the Alternative License and the SGI License are offered solely by Sun
|
||||
** and not by SGI.
|
||||
**
|
||||
** Original Code. The Original Code is: OpenGL Sample Implementation,
|
||||
** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
|
||||
** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
|
||||
** Copyright in any portions created by third parties is as indicated
|
||||
** elsewhere herein. All Rights Reserved.
|
||||
**
|
||||
** Additional Notice Provisions: The application programming interfaces
|
||||
** established by SGI in conjunction with the Original Code are The
|
||||
** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
|
||||
** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
|
||||
** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
|
||||
** Window System(R) (Version 1.3), released October 19, 1998. This software
|
||||
** was created using the OpenGL(R) version 1.2.1 Sample Implementation
|
||||
** published by SGI, but has not been independently verified as being
|
||||
** compliant with the OpenGL(R) version 1.2.1 Specification.
|
||||
**
|
||||
** Author: Eric Veach, July 1994
|
||||
** Java Port: Pepijn Van Eeckhoudt, July 2003
|
||||
** Java Port: Nathan Parker Burg, August 2003
|
||||
*/
|
||||
package org.lwjgl.util.glu.tessellation;
|
||||
|
||||
import org.lwjgl.util.glu.GLU;
|
||||
import org.lwjgl.util.glu.GLUtessellator;
|
||||
import org.lwjgl.util.glu.GLUtessellatorCallback;
|
||||
import org.lwjgl.util.glu.GLUtessellatorCallbackAdapter;
|
||||
|
||||
public class GLUtessellatorImpl implements GLUtessellator {
|
||||
public static final int TESS_MAX_CACHE = 100;
|
||||
|
||||
private int state; /* what begin/end calls have we seen? */
|
||||
|
||||
private GLUhalfEdge lastEdge; /* lastEdge->Org is the most recent vertex */
|
||||
GLUmesh mesh; /* stores the input contours, and eventually
|
||||
the tessellation itself */
|
||||
|
||||
/*** state needed for projecting onto the sweep plane ***/
|
||||
|
||||
double[] normal = new double[3]; /* user-specified normal (if provided) */
|
||||
double[] sUnit = new double[3]; /* unit vector in s-direction (debugging) */
|
||||
double[] tUnit = new double[3]; /* unit vector in t-direction (debugging) */
|
||||
|
||||
/*** state needed for the line sweep ***/
|
||||
|
||||
private double relTolerance; /* tolerance for merging features */
|
||||
int windingRule; /* rule for determining polygon interior */
|
||||
boolean fatalError; /* fatal error: needed combine callback */
|
||||
|
||||
Dict dict; /* edge dictionary for sweep line */
|
||||
PriorityQ pq; /* priority queue of vertex events */
|
||||
GLUvertex event; /* current sweep event being processed */
|
||||
|
||||
/*** state needed for rendering callbacks (see render.c) ***/
|
||||
|
||||
boolean flagBoundary; /* mark boundary edges (use EdgeFlag) */
|
||||
boolean boundaryOnly; /* Extract contours, not triangles */
|
||||
GLUface lonelyTriList;
|
||||
/* list of triangles which could not be rendered as strips or fans */
|
||||
|
||||
|
||||
|
||||
/*** state needed to cache single-contour polygons for renderCache() */
|
||||
|
||||
private boolean flushCacheOnNextVertex; /* empty cache on next vertex() call */
|
||||
int cacheCount; /* number of cached vertices */
|
||||
CachedVertex[] cache = new CachedVertex[TESS_MAX_CACHE]; /* the vertex data */
|
||||
|
||||
/*** rendering callbacks that also pass polygon data ***/
|
||||
private Object polygonData; /* client data for current polygon */
|
||||
|
||||
private GLUtessellatorCallback callBegin;
|
||||
private GLUtessellatorCallback callEdgeFlag;
|
||||
private GLUtessellatorCallback callVertex;
|
||||
private GLUtessellatorCallback callEnd;
|
||||
// private GLUtessellatorCallback callMesh;
|
||||
private GLUtessellatorCallback callError;
|
||||
private GLUtessellatorCallback callCombine;
|
||||
|
||||
private GLUtessellatorCallback callBeginData;
|
||||
private GLUtessellatorCallback callEdgeFlagData;
|
||||
private GLUtessellatorCallback callVertexData;
|
||||
private GLUtessellatorCallback callEndData;
|
||||
// private GLUtessellatorCallback callMeshData;
|
||||
private GLUtessellatorCallback callErrorData;
|
||||
private GLUtessellatorCallback callCombineData;
|
||||
|
||||
private static final double GLU_TESS_DEFAULT_TOLERANCE = 0.0;
|
||||
// private static final int GLU_TESS_MESH = 100112; /* void (*)(GLUmesh *mesh) */
|
||||
private static GLUtessellatorCallback NULL_CB = new GLUtessellatorCallbackAdapter();
|
||||
|
||||
// #define MAX_FAST_ALLOC (MAX(sizeof(EdgePair), \
|
||||
// MAX(sizeof(GLUvertex),sizeof(GLUface))))
|
||||
|
||||
public GLUtessellatorImpl() {
|
||||
state = TessState.T_DORMANT;
|
||||
|
||||
normal[0] = 0;
|
||||
normal[1] = 0;
|
||||
normal[2] = 0;
|
||||
|
||||
relTolerance = GLU_TESS_DEFAULT_TOLERANCE;
|
||||
windingRule = GLU.GLU_TESS_WINDING_ODD;
|
||||
flagBoundary = false;
|
||||
boundaryOnly = false;
|
||||
|
||||
callBegin = NULL_CB;
|
||||
callEdgeFlag = NULL_CB;
|
||||
callVertex = NULL_CB;
|
||||
callEnd = NULL_CB;
|
||||
callError = NULL_CB;
|
||||
callCombine = NULL_CB;
|
||||
// callMesh = NULL_CB;
|
||||
|
||||
callBeginData = NULL_CB;
|
||||
callEdgeFlagData = NULL_CB;
|
||||
callVertexData = NULL_CB;
|
||||
callEndData = NULL_CB;
|
||||
callErrorData = NULL_CB;
|
||||
callCombineData = NULL_CB;
|
||||
|
||||
polygonData = null;
|
||||
|
||||
for (int i = 0; i < cache.length; i++) {
|
||||
cache[i] = new CachedVertex();
|
||||
}
|
||||
}
|
||||
|
||||
static public GLUtessellator gluNewTess()
|
||||
{
|
||||
return new GLUtessellatorImpl();
|
||||
}
|
||||
|
||||
|
||||
private void makeDormant() {
|
||||
/* Return the tessellator to its original dormant state. */
|
||||
|
||||
if (mesh != null) {
|
||||
Mesh.__gl_meshDeleteMesh(mesh);
|
||||
}
|
||||
state = TessState.T_DORMANT;
|
||||
lastEdge = null;
|
||||
mesh = null;
|
||||
}
|
||||
|
||||
private void requireState(int newState) {
|
||||
if (state != newState) gotoState(newState);
|
||||
}
|
||||
|
||||
private void gotoState(int newState) {
|
||||
while (state != newState) {
|
||||
/* We change the current state one level at a time, to get to
|
||||
* the desired state.
|
||||
*/
|
||||
if (state < newState) {
|
||||
if (state == TessState.T_DORMANT) {
|
||||
callErrorOrErrorData(GLU.GLU_TESS_MISSING_BEGIN_POLYGON);
|
||||
gluTessBeginPolygon(null);
|
||||
} else if (state == TessState.T_IN_POLYGON) {
|
||||
callErrorOrErrorData(GLU.GLU_TESS_MISSING_BEGIN_CONTOUR);
|
||||
gluTessBeginContour();
|
||||
}
|
||||
} else {
|
||||
if (state == TessState.T_IN_CONTOUR) {
|
||||
callErrorOrErrorData(GLU.GLU_TESS_MISSING_END_CONTOUR);
|
||||
gluTessEndContour();
|
||||
} else if (state == TessState.T_IN_POLYGON) {
|
||||
callErrorOrErrorData(GLU.GLU_TESS_MISSING_END_POLYGON);
|
||||
/* gluTessEndPolygon( tess ) is too much work! */
|
||||
makeDormant();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void gluDeleteTess() {
|
||||
requireState(TessState.T_DORMANT);
|
||||
}
|
||||
|
||||
public void gluTessProperty(int which, double value) {
|
||||
switch (which) {
|
||||
case GLU.GLU_TESS_TOLERANCE:
|
||||
if (value < 0.0 || value > 1.0) break;
|
||||
relTolerance = value;
|
||||
return;
|
||||
|
||||
case GLU.GLU_TESS_WINDING_RULE:
|
||||
int windingRule = (int) value;
|
||||
if (windingRule != value) break; /* not an integer */
|
||||
|
||||
switch (windingRule) {
|
||||
case GLU.GLU_TESS_WINDING_ODD:
|
||||
case GLU.GLU_TESS_WINDING_NONZERO:
|
||||
case GLU.GLU_TESS_WINDING_POSITIVE:
|
||||
case GLU.GLU_TESS_WINDING_NEGATIVE:
|
||||
case GLU.GLU_TESS_WINDING_ABS_GEQ_TWO:
|
||||
this.windingRule = windingRule;
|
||||
return;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
case GLU.GLU_TESS_BOUNDARY_ONLY:
|
||||
boundaryOnly = (value != 0);
|
||||
return;
|
||||
|
||||
default:
|
||||
callErrorOrErrorData(GLU.GLU_INVALID_ENUM);
|
||||
return;
|
||||
}
|
||||
callErrorOrErrorData(GLU.GLU_INVALID_VALUE);
|
||||
}
|
||||
|
||||
/* Returns tessellator property */
|
||||
public void gluGetTessProperty(int which, double[] value, int value_offset) {
|
||||
switch (which) {
|
||||
case GLU.GLU_TESS_TOLERANCE:
|
||||
/* tolerance should be in range [0..1] */
|
||||
assert (0.0 <= relTolerance && relTolerance <= 1.0);
|
||||
value[value_offset] = relTolerance;
|
||||
break;
|
||||
case GLU.GLU_TESS_WINDING_RULE:
|
||||
assert (windingRule == GLU.GLU_TESS_WINDING_ODD ||
|
||||
windingRule == GLU.GLU_TESS_WINDING_NONZERO ||
|
||||
windingRule == GLU.GLU_TESS_WINDING_POSITIVE ||
|
||||
windingRule == GLU.GLU_TESS_WINDING_NEGATIVE ||
|
||||
windingRule == GLU.GLU_TESS_WINDING_ABS_GEQ_TWO);
|
||||
value[value_offset] = windingRule;
|
||||
break;
|
||||
case GLU.GLU_TESS_BOUNDARY_ONLY:
|
||||
assert (boundaryOnly == true || boundaryOnly == false);
|
||||
value[value_offset] = boundaryOnly ? 1 : 0;
|
||||
break;
|
||||
default:
|
||||
value[value_offset] = 0.0;
|
||||
callErrorOrErrorData(GLU.GLU_INVALID_ENUM);
|
||||
break;
|
||||
}
|
||||
} /* gluGetTessProperty() */
|
||||
|
||||
public void gluTessNormal(double x, double y, double z) {
|
||||
normal[0] = x;
|
||||
normal[1] = y;
|
||||
normal[2] = z;
|
||||
}
|
||||
|
||||
public void gluTessCallback(int which, GLUtessellatorCallback aCallback) {
|
||||
switch (which) {
|
||||
case GLU.GLU_TESS_BEGIN:
|
||||
callBegin = aCallback == null ? NULL_CB : aCallback;
|
||||
return;
|
||||
case GLU.GLU_TESS_BEGIN_DATA:
|
||||
callBeginData = aCallback == null ? NULL_CB : aCallback;
|
||||
return;
|
||||
case GLU.GLU_TESS_EDGE_FLAG:
|
||||
callEdgeFlag = aCallback == null ? NULL_CB : aCallback;
|
||||
/* If the client wants boundary edges to be flagged,
|
||||
* we render everything as separate triangles (no strips or fans).
|
||||
*/
|
||||
flagBoundary = aCallback != null;
|
||||
return;
|
||||
case GLU.GLU_TESS_EDGE_FLAG_DATA:
|
||||
callEdgeFlagData = callBegin = aCallback == null ? NULL_CB : aCallback;
|
||||
/* If the client wants boundary edges to be flagged,
|
||||
* we render everything as separate triangles (no strips or fans).
|
||||
*/
|
||||
flagBoundary = (aCallback != null);
|
||||
return;
|
||||
case GLU.GLU_TESS_VERTEX:
|
||||
callVertex = aCallback == null ? NULL_CB : aCallback;
|
||||
return;
|
||||
case GLU.GLU_TESS_VERTEX_DATA:
|
||||
callVertexData = aCallback == null ? NULL_CB : aCallback;
|
||||
return;
|
||||
case GLU.GLU_TESS_END:
|
||||
callEnd = aCallback == null ? NULL_CB : aCallback;
|
||||
return;
|
||||
case GLU.GLU_TESS_END_DATA:
|
||||
callEndData = aCallback == null ? NULL_CB : aCallback;
|
||||
return;
|
||||
case GLU.GLU_TESS_ERROR:
|
||||
callError = aCallback == null ? NULL_CB : aCallback;
|
||||
return;
|
||||
case GLU.GLU_TESS_ERROR_DATA:
|
||||
callErrorData = aCallback == null ? NULL_CB : aCallback;
|
||||
return;
|
||||
case GLU.GLU_TESS_COMBINE:
|
||||
callCombine = aCallback == null ? NULL_CB : aCallback;
|
||||
return;
|
||||
case GLU.GLU_TESS_COMBINE_DATA:
|
||||
callCombineData = aCallback == null ? NULL_CB : aCallback;
|
||||
return;
|
||||
// case GLU_TESS_MESH:
|
||||
// callMesh = aCallback == null ? NULL_CB : aCallback;
|
||||
// return;
|
||||
default:
|
||||
callErrorOrErrorData(GLU.GLU_INVALID_ENUM);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean addVertex(double[] coords, Object vertexData) {
|
||||
GLUhalfEdge e;
|
||||
|
||||
e = lastEdge;
|
||||
if (e == null) {
|
||||
/* Make a self-loop (one vertex, one edge). */
|
||||
|
||||
e = Mesh.__gl_meshMakeEdge(mesh);
|
||||
if (e == null) return false;
|
||||
if (!Mesh.__gl_meshSplice(e, e.Sym)) return false;
|
||||
} else {
|
||||
/* Create a new vertex and edge which immediately follow e
|
||||
* in the ordering around the left face.
|
||||
*/
|
||||
if (Mesh.__gl_meshSplitEdge(e) == null) return false;
|
||||
e = e.Lnext;
|
||||
}
|
||||
|
||||
/* The new vertex is now e.Org. */
|
||||
e.Org.data = vertexData;
|
||||
e.Org.coords[0] = coords[0];
|
||||
e.Org.coords[1] = coords[1];
|
||||
e.Org.coords[2] = coords[2];
|
||||
|
||||
/* The winding of an edge says how the winding number changes as we
|
||||
* cross from the edge''s right face to its left face. We add the
|
||||
* vertices in such an order that a CCW contour will add +1 to
|
||||
* the winding number of the region inside the contour.
|
||||
*/
|
||||
e.winding = 1;
|
||||
e.Sym.winding = -1;
|
||||
|
||||
lastEdge = e;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void cacheVertex(double[] coords, Object vertexData) {
|
||||
if (cache[cacheCount] == null) {
|
||||
cache[cacheCount] = new CachedVertex();
|
||||
}
|
||||
|
||||
CachedVertex v = cache[cacheCount];
|
||||
|
||||
v.data = vertexData;
|
||||
v.coords[0] = coords[0];
|
||||
v.coords[1] = coords[1];
|
||||
v.coords[2] = coords[2];
|
||||
++cacheCount;
|
||||
}
|
||||
|
||||
|
||||
private boolean flushCache() {
|
||||
CachedVertex[] v = cache;
|
||||
|
||||
mesh = Mesh.__gl_meshNewMesh();
|
||||
if (mesh == null) return false;
|
||||
|
||||
for (int i = 0; i < cacheCount; i++) {
|
||||
CachedVertex vertex = v[i];
|
||||
if (!addVertex(vertex.coords, vertex.data)) return false;
|
||||
}
|
||||
cacheCount = 0;
|
||||
flushCacheOnNextVertex = false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void gluTessVertex(double[] coords, int coords_offset, Object vertexData) {
|
||||
int i;
|
||||
boolean tooLarge = false;
|
||||
double x;
|
||||
double[] clamped = new double[3];
|
||||
|
||||
requireState(TessState.T_IN_CONTOUR);
|
||||
|
||||
if (flushCacheOnNextVertex) {
|
||||
if (!flushCache()) {
|
||||
callErrorOrErrorData(GLU.GLU_OUT_OF_MEMORY);
|
||||
return;
|
||||
}
|
||||
lastEdge = null;
|
||||
}
|
||||
for (i = 0; i < 3; ++i) {
|
||||
x = coords[i+coords_offset];
|
||||
if (x < -GLU.GLU_TESS_MAX_COORD) {
|
||||
x = -GLU.GLU_TESS_MAX_COORD;
|
||||
tooLarge = true;
|
||||
}
|
||||
if (x > GLU.GLU_TESS_MAX_COORD) {
|
||||
x = GLU.GLU_TESS_MAX_COORD;
|
||||
tooLarge = true;
|
||||
}
|
||||
clamped[i] = x;
|
||||
}
|
||||
if (tooLarge) {
|
||||
callErrorOrErrorData(GLU.GLU_TESS_COORD_TOO_LARGE);
|
||||
}
|
||||
|
||||
if (mesh == null) {
|
||||
if (cacheCount < TESS_MAX_CACHE) {
|
||||
cacheVertex(clamped, vertexData);
|
||||
return;
|
||||
}
|
||||
if (!flushCache()) {
|
||||
callErrorOrErrorData(GLU.GLU_OUT_OF_MEMORY);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!addVertex(clamped, vertexData)) {
|
||||
callErrorOrErrorData(GLU.GLU_OUT_OF_MEMORY);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void gluTessBeginPolygon(Object data) {
|
||||
requireState(TessState.T_DORMANT);
|
||||
|
||||
state = TessState.T_IN_POLYGON;
|
||||
cacheCount = 0;
|
||||
flushCacheOnNextVertex = false;
|
||||
mesh = null;
|
||||
|
||||
polygonData = data;
|
||||
}
|
||||
|
||||
|
||||
public void gluTessBeginContour() {
|
||||
requireState(TessState.T_IN_POLYGON);
|
||||
|
||||
state = TessState.T_IN_CONTOUR;
|
||||
lastEdge = null;
|
||||
if (cacheCount > 0) {
|
||||
/* Just set a flag so we don't get confused by empty contours
|
||||
* -- these can be generated accidentally with the obsolete
|
||||
* NextContour() interface.
|
||||
*/
|
||||
flushCacheOnNextVertex = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void gluTessEndContour() {
|
||||
requireState(TessState.T_IN_CONTOUR);
|
||||
state = TessState.T_IN_POLYGON;
|
||||
}
|
||||
|
||||
public void gluTessEndPolygon() {
|
||||
GLUmesh mesh;
|
||||
|
||||
try {
|
||||
requireState(TessState.T_IN_POLYGON);
|
||||
state = TessState.T_DORMANT;
|
||||
|
||||
if (this.mesh == null) {
|
||||
if (!flagBoundary /*&& callMesh == NULL_CB*/) {
|
||||
|
||||
/* Try some special code to make the easy cases go quickly
|
||||
* (eg. convex polygons). This code does NOT handle multiple contours,
|
||||
* intersections, edge flags, and of course it does not generate
|
||||
* an explicit mesh either.
|
||||
*/
|
||||
if (Render.__gl_renderCache(this)) {
|
||||
polygonData = null;
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (!flushCache()) throw new RuntimeException(); /* could've used a label*/
|
||||
}
|
||||
|
||||
/* Determine the polygon normal and project vertices onto the plane
|
||||
* of the polygon.
|
||||
*/
|
||||
Normal.__gl_projectPolygon(this);
|
||||
|
||||
/* __gl_computeInterior( tess ) computes the planar arrangement specified
|
||||
* by the given contours, and further subdivides this arrangement
|
||||
* into regions. Each region is marked "inside" if it belongs
|
||||
* to the polygon, according to the rule given by windingRule.
|
||||
* Each interior region is guaranteed be monotone.
|
||||
*/
|
||||
if (!Sweep.__gl_computeInterior(this)) {
|
||||
throw new RuntimeException(); /* could've used a label */
|
||||
}
|
||||
|
||||
mesh = this.mesh;
|
||||
if (!fatalError) {
|
||||
boolean rc = true;
|
||||
|
||||
/* If the user wants only the boundary contours, we throw away all edges
|
||||
* except those which separate the interior from the exterior.
|
||||
* Otherwise we tessellate all the regions marked "inside".
|
||||
*/
|
||||
if (boundaryOnly) {
|
||||
rc = TessMono.__gl_meshSetWindingNumber(mesh, 1, true);
|
||||
} else {
|
||||
rc = TessMono.__gl_meshTessellateInterior(mesh);
|
||||
}
|
||||
if (!rc) throw new RuntimeException(); /* could've used a label */
|
||||
|
||||
Mesh.__gl_meshCheckMesh(mesh);
|
||||
|
||||
if (callBegin != NULL_CB || callEnd != NULL_CB
|
||||
|| callVertex != NULL_CB || callEdgeFlag != NULL_CB
|
||||
|| callBeginData != NULL_CB
|
||||
|| callEndData != NULL_CB
|
||||
|| callVertexData != NULL_CB
|
||||
|| callEdgeFlagData != NULL_CB) {
|
||||
if (boundaryOnly) {
|
||||
Render.__gl_renderBoundary(this, mesh); /* output boundary contours */
|
||||
} else {
|
||||
Render.__gl_renderMesh(this, mesh); /* output strips and fans */
|
||||
}
|
||||
}
|
||||
// if (callMesh != NULL_CB) {
|
||||
//
|
||||
///* Throw away the exterior faces, so that all faces are interior.
|
||||
// * This way the user doesn't have to check the "inside" flag,
|
||||
// * and we don't need to even reveal its existence. It also leaves
|
||||
// * the freedom for an implementation to not generate the exterior
|
||||
// * faces in the first place.
|
||||
// */
|
||||
// TessMono.__gl_meshDiscardExterior(mesh);
|
||||
// callMesh.mesh(mesh); /* user wants the mesh itself */
|
||||
// mesh = null;
|
||||
// polygonData = null;
|
||||
// return;
|
||||
// }
|
||||
}
|
||||
Mesh.__gl_meshDeleteMesh(mesh);
|
||||
polygonData = null;
|
||||
mesh = null;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
callErrorOrErrorData(GLU.GLU_OUT_OF_MEMORY);
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************/
|
||||
|
||||
/* Obsolete calls -- for backward compatibility */
|
||||
|
||||
public void gluBeginPolygon() {
|
||||
gluTessBeginPolygon(null);
|
||||
gluTessBeginContour();
|
||||
}
|
||||
|
||||
|
||||
/*ARGSUSED*/
|
||||
public void gluNextContour(int type) {
|
||||
gluTessEndContour();
|
||||
gluTessBeginContour();
|
||||
}
|
||||
|
||||
|
||||
public void gluEndPolygon() {
|
||||
gluTessEndContour();
|
||||
gluTessEndPolygon();
|
||||
}
|
||||
|
||||
void callBeginOrBeginData(int a) {
|
||||
if (callBeginData != NULL_CB)
|
||||
callBeginData.beginData(a, polygonData);
|
||||
else
|
||||
callBegin.begin(a);
|
||||
}
|
||||
|
||||
void callVertexOrVertexData(Object a) {
|
||||
if (callVertexData != NULL_CB)
|
||||
callVertexData.vertexData(a, polygonData);
|
||||
else
|
||||
callVertex.vertex(a);
|
||||
}
|
||||
|
||||
void callEdgeFlagOrEdgeFlagData(boolean a) {
|
||||
if (callEdgeFlagData != NULL_CB)
|
||||
callEdgeFlagData.edgeFlagData(a, polygonData);
|
||||
else
|
||||
callEdgeFlag.edgeFlag(a);
|
||||
}
|
||||
|
||||
void callEndOrEndData() {
|
||||
if (callEndData != NULL_CB)
|
||||
callEndData.endData(polygonData);
|
||||
else
|
||||
callEnd.end();
|
||||
}
|
||||
|
||||
void callCombineOrCombineData(double[] coords, Object[] vertexData, float[] weights, Object[] outData) {
|
||||
if (callCombineData != NULL_CB)
|
||||
callCombineData.combineData(coords, vertexData, weights, outData, polygonData);
|
||||
else
|
||||
callCombine.combine(coords, vertexData, weights, outData);
|
||||
}
|
||||
|
||||
void callErrorOrErrorData(int a) {
|
||||
if (callErrorData != NULL_CB)
|
||||
callErrorData.errorData(a, polygonData);
|
||||
else
|
||||
callError.error(a);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,97 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2008 LWJGL Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * 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.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "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 THE COPYRIGHT OWNER 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Portions Copyright (C) 2003-2006 Sun Microsystems, Inc.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/*
|
||||
** License Applicability. Except to the extent portions of this file are
|
||||
** made subject to an alternative license as permitted in the SGI Free
|
||||
** Software License B, Version 1.1 (the "License"), the contents of this
|
||||
** file are subject only to the provisions of the License. You may not use
|
||||
** this file except in compliance with the License. You may obtain a copy
|
||||
** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
|
||||
** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
|
||||
**
|
||||
** http://oss.sgi.com/projects/FreeB
|
||||
**
|
||||
** Note that, as provided in the License, the Software is distributed on an
|
||||
** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
|
||||
** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
|
||||
** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
|
||||
** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
|
||||
**
|
||||
** NOTE: The Original Code (as defined below) has been licensed to Sun
|
||||
** Microsystems, Inc. ("Sun") under the SGI Free Software License B
|
||||
** (Version 1.1), shown above ("SGI License"). Pursuant to Section
|
||||
** 3.2(3) of the SGI License, Sun is distributing the Covered Code to
|
||||
** you under an alternative license ("Alternative License"). This
|
||||
** Alternative License includes all of the provisions of the SGI License
|
||||
** except that Section 2.2 and 11 are omitted. Any differences between
|
||||
** the Alternative License and the SGI License are offered solely by Sun
|
||||
** and not by SGI.
|
||||
**
|
||||
** Original Code. The Original Code is: OpenGL Sample Implementation,
|
||||
** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
|
||||
** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
|
||||
** Copyright in any portions created by third parties is as indicated
|
||||
** elsewhere herein. All Rights Reserved.
|
||||
**
|
||||
** Additional Notice Provisions: The application programming interfaces
|
||||
** established by SGI in conjunction with the Original Code are The
|
||||
** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
|
||||
** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
|
||||
** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
|
||||
** Window System(R) (Version 1.3), released October 19, 1998. This software
|
||||
** was created using the OpenGL(R) version 1.2.1 Sample Implementation
|
||||
** published by SGI, but has not been independently verified as being
|
||||
** compliant with the OpenGL(R) version 1.2.1 Specification.
|
||||
**
|
||||
** Author: Eric Veach, July 1994
|
||||
** Java Port: Pepijn Van Eeckhoudt, July 2003
|
||||
** Java Port: Nathan Parker Burg, August 2003
|
||||
*/
|
||||
package org.lwjgl.util.glu.tessellation;
|
||||
|
||||
class GLUvertex {
|
||||
public GLUvertex next; /* next vertex (never NULL) */
|
||||
public GLUvertex prev; /* previous vertex (never NULL) */
|
||||
public GLUhalfEdge anEdge; /* a half-edge with this origin */
|
||||
public Object data; /* client's data */
|
||||
|
||||
/* Internal data (keep hidden) */
|
||||
public double[] coords = new double[3]; /* vertex location in 3D */
|
||||
public double s, t; /* projection onto the sweep plane */
|
||||
public int pqHandle; /* to allow deletion from priority queue */
|
||||
}
|
|
@ -0,0 +1,350 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2008 LWJGL Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * 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.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "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 THE COPYRIGHT OWNER 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Portions Copyright (C) 2003-2006 Sun Microsystems, Inc.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/*
|
||||
** License Applicability. Except to the extent portions of this file are
|
||||
** made subject to an alternative license as permitted in the SGI Free
|
||||
** Software License B, Version 1.1 (the "License"), the contents of this
|
||||
** file are subject only to the provisions of the License. You may not use
|
||||
** this file except in compliance with the License. You may obtain a copy
|
||||
** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
|
||||
** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
|
||||
**
|
||||
** http://oss.sgi.com/projects/FreeB
|
||||
**
|
||||
** Note that, as provided in the License, the Software is distributed on an
|
||||
** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
|
||||
** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
|
||||
** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
|
||||
** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
|
||||
**
|
||||
** NOTE: The Original Code (as defined below) has been licensed to Sun
|
||||
** Microsystems, Inc. ("Sun") under the SGI Free Software License B
|
||||
** (Version 1.1), shown above ("SGI License"). Pursuant to Section
|
||||
** 3.2(3) of the SGI License, Sun is distributing the Covered Code to
|
||||
** you under an alternative license ("Alternative License"). This
|
||||
** Alternative License includes all of the provisions of the SGI License
|
||||
** except that Section 2.2 and 11 are omitted. Any differences between
|
||||
** the Alternative License and the SGI License are offered solely by Sun
|
||||
** and not by SGI.
|
||||
**
|
||||
** Original Code. The Original Code is: OpenGL Sample Implementation,
|
||||
** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
|
||||
** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
|
||||
** Copyright in any portions created by third parties is as indicated
|
||||
** elsewhere herein. All Rights Reserved.
|
||||
**
|
||||
** Additional Notice Provisions: The application programming interfaces
|
||||
** established by SGI in conjunction with the Original Code are The
|
||||
** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
|
||||
** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
|
||||
** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
|
||||
** Window System(R) (Version 1.3), released October 19, 1998. This software
|
||||
** was created using the OpenGL(R) version 1.2.1 Sample Implementation
|
||||
** published by SGI, but has not been independently verified as being
|
||||
** compliant with the OpenGL(R) version 1.2.1 Specification.
|
||||
**
|
||||
** Author: Eric Veach, July 1994
|
||||
** Java Port: Pepijn Van Eeckhoudt, July 2003
|
||||
** Java Port: Nathan Parker Burg, August 2003
|
||||
*/
|
||||
package org.lwjgl.util.glu.tessellation;
|
||||
|
||||
class Geom {
|
||||
private Geom() {
|
||||
}
|
||||
|
||||
/* Given three vertices u,v,w such that VertLeq(u,v) && VertLeq(v,w),
|
||||
* evaluates the t-coord of the edge uw at the s-coord of the vertex v.
|
||||
* Returns v->t - (uw)(v->s), ie. the signed distance from uw to v.
|
||||
* If uw is vertical (and thus passes thru v), the result is zero.
|
||||
*
|
||||
* The calculation is extremely accurate and stable, even when v
|
||||
* is very close to u or w. In particular if we set v->t = 0 and
|
||||
* let r be the negated result (this evaluates (uw)(v->s)), then
|
||||
* r is guaranteed to satisfy MIN(u->t,w->t) <= r <= MAX(u->t,w->t).
|
||||
*/
|
||||
static double EdgeEval(GLUvertex u, GLUvertex v, GLUvertex w) {
|
||||
double gapL, gapR;
|
||||
|
||||
assert (VertLeq(u, v) && VertLeq(v, w));
|
||||
|
||||
gapL = v.s - u.s;
|
||||
gapR = w.s - v.s;
|
||||
|
||||
if (gapL + gapR > 0) {
|
||||
if (gapL < gapR) {
|
||||
return (v.t - u.t) + (u.t - w.t) * (gapL / (gapL + gapR));
|
||||
} else {
|
||||
return (v.t - w.t) + (w.t - u.t) * (gapR / (gapL + gapR));
|
||||
}
|
||||
}
|
||||
/* vertical line */
|
||||
return 0;
|
||||
}
|
||||
|
||||
static double EdgeSign(GLUvertex u, GLUvertex v, GLUvertex w) {
|
||||
double gapL, gapR;
|
||||
|
||||
assert (VertLeq(u, v) && VertLeq(v, w));
|
||||
|
||||
gapL = v.s - u.s;
|
||||
gapR = w.s - v.s;
|
||||
|
||||
if (gapL + gapR > 0) {
|
||||
return (v.t - w.t) * gapL + (v.t - u.t) * gapR;
|
||||
}
|
||||
/* vertical line */
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
* Define versions of EdgeSign, EdgeEval with s and t transposed.
|
||||
*/
|
||||
|
||||
static double TransEval(GLUvertex u, GLUvertex v, GLUvertex w) {
|
||||
/* Given three vertices u,v,w such that TransLeq(u,v) && TransLeq(v,w),
|
||||
* evaluates the t-coord of the edge uw at the s-coord of the vertex v.
|
||||
* Returns v->s - (uw)(v->t), ie. the signed distance from uw to v.
|
||||
* If uw is vertical (and thus passes thru v), the result is zero.
|
||||
*
|
||||
* The calculation is extremely accurate and stable, even when v
|
||||
* is very close to u or w. In particular if we set v->s = 0 and
|
||||
* let r be the negated result (this evaluates (uw)(v->t)), then
|
||||
* r is guaranteed to satisfy MIN(u->s,w->s) <= r <= MAX(u->s,w->s).
|
||||
*/
|
||||
double gapL, gapR;
|
||||
|
||||
assert (TransLeq(u, v) && TransLeq(v, w));
|
||||
|
||||
gapL = v.t - u.t;
|
||||
gapR = w.t - v.t;
|
||||
|
||||
if (gapL + gapR > 0) {
|
||||
if (gapL < gapR) {
|
||||
return (v.s - u.s) + (u.s - w.s) * (gapL / (gapL + gapR));
|
||||
} else {
|
||||
return (v.s - w.s) + (w.s - u.s) * (gapR / (gapL + gapR));
|
||||
}
|
||||
}
|
||||
/* vertical line */
|
||||
return 0;
|
||||
}
|
||||
|
||||
static double TransSign(GLUvertex u, GLUvertex v, GLUvertex w) {
|
||||
/* Returns a number whose sign matches TransEval(u,v,w) but which
|
||||
* is cheaper to evaluate. Returns > 0, == 0 , or < 0
|
||||
* as v is above, on, or below the edge uw.
|
||||
*/
|
||||
double gapL, gapR;
|
||||
|
||||
assert (TransLeq(u, v) && TransLeq(v, w));
|
||||
|
||||
gapL = v.t - u.t;
|
||||
gapR = w.t - v.t;
|
||||
|
||||
if (gapL + gapR > 0) {
|
||||
return (v.s - w.s) * gapL + (v.s - u.s) * gapR;
|
||||
}
|
||||
/* vertical line */
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static boolean VertCCW(GLUvertex u, GLUvertex v, GLUvertex w) {
|
||||
/* For almost-degenerate situations, the results are not reliable.
|
||||
* Unless the floating-point arithmetic can be performed without
|
||||
* rounding errors, *any* implementation will give incorrect results
|
||||
* on some degenerate inputs, so the client must have some way to
|
||||
* handle this situation.
|
||||
*/
|
||||
return (u.s * (v.t - w.t) + v.s * (w.t - u.t) + w.s * (u.t - v.t)) >= 0;
|
||||
}
|
||||
|
||||
/* Given parameters a,x,b,y returns the value (b*x+a*y)/(a+b),
|
||||
* or (x+y)/2 if a==b==0. It requires that a,b >= 0, and enforces
|
||||
* this in the rare case that one argument is slightly negative.
|
||||
* The implementation is extremely stable numerically.
|
||||
* In particular it guarantees that the result r satisfies
|
||||
* MIN(x,y) <= r <= MAX(x,y), and the results are very accurate
|
||||
* even when a and b differ greatly in magnitude.
|
||||
*/
|
||||
static double Interpolate(double a, double x, double b, double y) {
|
||||
a = (a < 0) ? 0 : a;
|
||||
b = (b < 0) ? 0 : b;
|
||||
if (a <= b) {
|
||||
if (b == 0) {
|
||||
return (x + y) / 2.0;
|
||||
} else {
|
||||
return (x + (y - x) * (a / (a + b)));
|
||||
}
|
||||
} else {
|
||||
return (y + (x - y) * (b / (a + b)));
|
||||
}
|
||||
}
|
||||
|
||||
static void EdgeIntersect(GLUvertex o1, GLUvertex d1,
|
||||
GLUvertex o2, GLUvertex d2,
|
||||
GLUvertex v)
|
||||
/* Given edges (o1,d1) and (o2,d2), compute their point of intersection.
|
||||
* The computed point is guaranteed to lie in the intersection of the
|
||||
* bounding rectangles defined by each edge.
|
||||
*/ {
|
||||
double z1, z2;
|
||||
|
||||
/* This is certainly not the most efficient way to find the intersection
|
||||
* of two line segments, but it is very numerically stable.
|
||||
*
|
||||
* Strategy: find the two middle vertices in the VertLeq ordering,
|
||||
* and interpolate the intersection s-value from these. Then repeat
|
||||
* using the TransLeq ordering to find the intersection t-value.
|
||||
*/
|
||||
|
||||
if (!VertLeq(o1, d1)) {
|
||||
GLUvertex temp = o1;
|
||||
o1 = d1;
|
||||
d1 = temp;
|
||||
}
|
||||
if (!VertLeq(o2, d2)) {
|
||||
GLUvertex temp = o2;
|
||||
o2 = d2;
|
||||
d2 = temp;
|
||||
}
|
||||
if (!VertLeq(o1, o2)) {
|
||||
GLUvertex temp = o1;
|
||||
o1 = o2;
|
||||
o2 = temp;
|
||||
temp = d1;
|
||||
d1 = d2;
|
||||
d2 = temp;
|
||||
}
|
||||
|
||||
if (!VertLeq(o2, d1)) {
|
||||
/* Technically, no intersection -- do our best */
|
||||
v.s = (o2.s + d1.s) / 2.0;
|
||||
} else if (VertLeq(d1, d2)) {
|
||||
/* Interpolate between o2 and d1 */
|
||||
z1 = EdgeEval(o1, o2, d1);
|
||||
z2 = EdgeEval(o2, d1, d2);
|
||||
if (z1 + z2 < 0) {
|
||||
z1 = -z1;
|
||||
z2 = -z2;
|
||||
}
|
||||
v.s = Interpolate(z1, o2.s, z2, d1.s);
|
||||
} else {
|
||||
/* Interpolate between o2 and d2 */
|
||||
z1 = EdgeSign(o1, o2, d1);
|
||||
z2 = -EdgeSign(o1, d2, d1);
|
||||
if (z1 + z2 < 0) {
|
||||
z1 = -z1;
|
||||
z2 = -z2;
|
||||
}
|
||||
v.s = Interpolate(z1, o2.s, z2, d2.s);
|
||||
}
|
||||
|
||||
/* Now repeat the process for t */
|
||||
|
||||
if (!TransLeq(o1, d1)) {
|
||||
GLUvertex temp = o1;
|
||||
o1 = d1;
|
||||
d1 = temp;
|
||||
}
|
||||
if (!TransLeq(o2, d2)) {
|
||||
GLUvertex temp = o2;
|
||||
o2 = d2;
|
||||
d2 = temp;
|
||||
}
|
||||
if (!TransLeq(o1, o2)) {
|
||||
GLUvertex temp = o2;
|
||||
o2 = o1;
|
||||
o1 = temp;
|
||||
temp = d2;
|
||||
d2 = d1;
|
||||
d1 = temp;
|
||||
}
|
||||
|
||||
if (!TransLeq(o2, d1)) {
|
||||
/* Technically, no intersection -- do our best */
|
||||
v.t = (o2.t + d1.t) / 2.0;
|
||||
} else if (TransLeq(d1, d2)) {
|
||||
/* Interpolate between o2 and d1 */
|
||||
z1 = TransEval(o1, o2, d1);
|
||||
z2 = TransEval(o2, d1, d2);
|
||||
if (z1 + z2 < 0) {
|
||||
z1 = -z1;
|
||||
z2 = -z2;
|
||||
}
|
||||
v.t = Interpolate(z1, o2.t, z2, d1.t);
|
||||
} else {
|
||||
/* Interpolate between o2 and d2 */
|
||||
z1 = TransSign(o1, o2, d1);
|
||||
z2 = -TransSign(o1, d2, d1);
|
||||
if (z1 + z2 < 0) {
|
||||
z1 = -z1;
|
||||
z2 = -z2;
|
||||
}
|
||||
v.t = Interpolate(z1, o2.t, z2, d2.t);
|
||||
}
|
||||
}
|
||||
|
||||
static boolean VertEq(GLUvertex u, GLUvertex v) {
|
||||
return u.s == v.s && u.t == v.t;
|
||||
}
|
||||
|
||||
static boolean VertLeq(GLUvertex u, GLUvertex v) {
|
||||
return u.s < v.s || (u.s == v.s && u.t <= v.t);
|
||||
}
|
||||
|
||||
/* Versions of VertLeq, EdgeSign, EdgeEval with s and t transposed. */
|
||||
|
||||
static boolean TransLeq(GLUvertex u, GLUvertex v) {
|
||||
return u.t < v.t || (u.t == v.t && u.s <= v.s);
|
||||
}
|
||||
|
||||
static boolean EdgeGoesLeft(GLUhalfEdge e) {
|
||||
return VertLeq(e.Sym.Org, e.Org);
|
||||
}
|
||||
|
||||
static boolean EdgeGoesRight(GLUhalfEdge e) {
|
||||
return VertLeq(e.Org, e.Sym.Org);
|
||||
}
|
||||
|
||||
static double VertL1dist(GLUvertex u, GLUvertex v) {
|
||||
return Math.abs(u.s - v.s) + Math.abs(u.t - v.t);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,766 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2008 LWJGL Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * 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.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "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 THE COPYRIGHT OWNER 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Portions Copyright (C) 2003-2006 Sun Microsystems, Inc.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/*
|
||||
** License Applicability. Except to the extent portions of this file are
|
||||
** made subject to an alternative license as permitted in the SGI Free
|
||||
** Software License B, Version 1.1 (the "License"), the contents of this
|
||||
** file are subject only to the provisions of the License. You may not use
|
||||
** this file except in compliance with the License. You may obtain a copy
|
||||
** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
|
||||
** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
|
||||
**
|
||||
** http://oss.sgi.com/projects/FreeB
|
||||
**
|
||||
** Note that, as provided in the License, the Software is distributed on an
|
||||
** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
|
||||
** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
|
||||
** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
|
||||
** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
|
||||
**
|
||||
** NOTE: The Original Code (as defined below) has been licensed to Sun
|
||||
** Microsystems, Inc. ("Sun") under the SGI Free Software License B
|
||||
** (Version 1.1), shown above ("SGI License"). Pursuant to Section
|
||||
** 3.2(3) of the SGI License, Sun is distributing the Covered Code to
|
||||
** you under an alternative license ("Alternative License"). This
|
||||
** Alternative License includes all of the provisions of the SGI License
|
||||
** except that Section 2.2 and 11 are omitted. Any differences between
|
||||
** the Alternative License and the SGI License are offered solely by Sun
|
||||
** and not by SGI.
|
||||
**
|
||||
** Original Code. The Original Code is: OpenGL Sample Implementation,
|
||||
** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
|
||||
** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
|
||||
** Copyright in any portions created by third parties is as indicated
|
||||
** elsewhere herein. All Rights Reserved.
|
||||
**
|
||||
** Additional Notice Provisions: The application programming interfaces
|
||||
** established by SGI in conjunction with the Original Code are The
|
||||
** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
|
||||
** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
|
||||
** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
|
||||
** Window System(R) (Version 1.3), released October 19, 1998. This software
|
||||
** was created using the OpenGL(R) version 1.2.1 Sample Implementation
|
||||
** published by SGI, but has not been independently verified as being
|
||||
** compliant with the OpenGL(R) version 1.2.1 Specification.
|
||||
**
|
||||
** Author: Eric Veach, July 1994
|
||||
** Java Port: Pepijn Van Eeckhoudt, July 2003
|
||||
** Java Port: Nathan Parker Burg, August 2003
|
||||
*/
|
||||
package org.lwjgl.util.glu.tessellation;
|
||||
|
||||
class Mesh {
|
||||
private Mesh() {
|
||||
}
|
||||
|
||||
/************************ Utility Routines ************************/
|
||||
/* MakeEdge creates a new pair of half-edges which form their own loop.
|
||||
* No vertex or face structures are allocated, but these must be assigned
|
||||
* before the current edge operation is completed.
|
||||
*/
|
||||
static GLUhalfEdge MakeEdge(GLUhalfEdge eNext) {
|
||||
GLUhalfEdge e;
|
||||
GLUhalfEdge eSym;
|
||||
GLUhalfEdge ePrev;
|
||||
|
||||
// EdgePair * pair = (EdgePair *)
|
||||
// memAlloc(sizeof(EdgePair));
|
||||
// if (pair == NULL) return NULL;
|
||||
//
|
||||
// e = &pair - > e;
|
||||
e = new GLUhalfEdge(true);
|
||||
// eSym = &pair - > eSym;
|
||||
eSym = new GLUhalfEdge(false);
|
||||
|
||||
|
||||
/* Make sure eNext points to the first edge of the edge pair */
|
||||
if (!eNext.first) {
|
||||
eNext = eNext.Sym;
|
||||
}
|
||||
|
||||
/* Insert in circular doubly-linked list before eNext.
|
||||
* Note that the prev pointer is stored in Sym->next.
|
||||
*/
|
||||
ePrev = eNext.Sym.next;
|
||||
eSym.next = ePrev;
|
||||
ePrev.Sym.next = e;
|
||||
e.next = eNext;
|
||||
eNext.Sym.next = eSym;
|
||||
|
||||
e.Sym = eSym;
|
||||
e.Onext = e;
|
||||
e.Lnext = eSym;
|
||||
e.Org = null;
|
||||
e.Lface = null;
|
||||
e.winding = 0;
|
||||
e.activeRegion = null;
|
||||
|
||||
eSym.Sym = e;
|
||||
eSym.Onext = eSym;
|
||||
eSym.Lnext = e;
|
||||
eSym.Org = null;
|
||||
eSym.Lface = null;
|
||||
eSym.winding = 0;
|
||||
eSym.activeRegion = null;
|
||||
|
||||
return e;
|
||||
}
|
||||
|
||||
/* Splice( a, b ) is best described by the Guibas/Stolfi paper or the
|
||||
* CS348a notes (see mesh.h). Basically it modifies the mesh so that
|
||||
* a->Onext and b->Onext are exchanged. This can have various effects
|
||||
* depending on whether a and b belong to different face or vertex rings.
|
||||
* For more explanation see __gl_meshSplice() below.
|
||||
*/
|
||||
static void Splice(GLUhalfEdge a, GLUhalfEdge b) {
|
||||
GLUhalfEdge aOnext = a.Onext;
|
||||
GLUhalfEdge bOnext = b.Onext;
|
||||
|
||||
aOnext.Sym.Lnext = b;
|
||||
bOnext.Sym.Lnext = a;
|
||||
a.Onext = bOnext;
|
||||
b.Onext = aOnext;
|
||||
}
|
||||
|
||||
/* MakeVertex( newVertex, eOrig, vNext ) attaches a new vertex and makes it the
|
||||
* origin of all edges in the vertex loop to which eOrig belongs. "vNext" gives
|
||||
* a place to insert the new vertex in the global vertex list. We insert
|
||||
* the new vertex *before* vNext so that algorithms which walk the vertex
|
||||
* list will not see the newly created vertices.
|
||||
*/
|
||||
static void MakeVertex(GLUvertex newVertex,
|
||||
GLUhalfEdge eOrig, GLUvertex vNext) {
|
||||
GLUhalfEdge e;
|
||||
GLUvertex vPrev;
|
||||
GLUvertex vNew = newVertex;
|
||||
|
||||
assert (vNew != null);
|
||||
|
||||
/* insert in circular doubly-linked list before vNext */
|
||||
vPrev = vNext.prev;
|
||||
vNew.prev = vPrev;
|
||||
vPrev.next = vNew;
|
||||
vNew.next = vNext;
|
||||
vNext.prev = vNew;
|
||||
|
||||
vNew.anEdge = eOrig;
|
||||
vNew.data = null;
|
||||
/* leave coords, s, t undefined */
|
||||
|
||||
/* fix other edges on this vertex loop */
|
||||
e = eOrig;
|
||||
do {
|
||||
e.Org = vNew;
|
||||
e = e.Onext;
|
||||
} while (e != eOrig);
|
||||
}
|
||||
|
||||
/* MakeFace( newFace, eOrig, fNext ) attaches a new face and makes it the left
|
||||
* face of all edges in the face loop to which eOrig belongs. "fNext" gives
|
||||
* a place to insert the new face in the global face list. We insert
|
||||
* the new face *before* fNext so that algorithms which walk the face
|
||||
* list will not see the newly created faces.
|
||||
*/
|
||||
static void MakeFace(GLUface newFace, GLUhalfEdge eOrig, GLUface fNext) {
|
||||
GLUhalfEdge e;
|
||||
GLUface fPrev;
|
||||
GLUface fNew = newFace;
|
||||
|
||||
assert (fNew != null);
|
||||
|
||||
/* insert in circular doubly-linked list before fNext */
|
||||
fPrev = fNext.prev;
|
||||
fNew.prev = fPrev;
|
||||
fPrev.next = fNew;
|
||||
fNew.next = fNext;
|
||||
fNext.prev = fNew;
|
||||
|
||||
fNew.anEdge = eOrig;
|
||||
fNew.data = null;
|
||||
fNew.trail = null;
|
||||
fNew.marked = false;
|
||||
|
||||
/* The new face is marked "inside" if the old one was. This is a
|
||||
* convenience for the common case where a face has been split in two.
|
||||
*/
|
||||
fNew.inside = fNext.inside;
|
||||
|
||||
/* fix other edges on this face loop */
|
||||
e = eOrig;
|
||||
do {
|
||||
e.Lface = fNew;
|
||||
e = e.Lnext;
|
||||
} while (e != eOrig);
|
||||
}
|
||||
|
||||
/* KillEdge( eDel ) destroys an edge (the half-edges eDel and eDel->Sym),
|
||||
* and removes from the global edge list.
|
||||
*/
|
||||
static void KillEdge(GLUhalfEdge eDel) {
|
||||
GLUhalfEdge ePrev, eNext;
|
||||
|
||||
/* Half-edges are allocated in pairs, see EdgePair above */
|
||||
if (!eDel.first) {
|
||||
eDel = eDel.Sym;
|
||||
}
|
||||
|
||||
/* delete from circular doubly-linked list */
|
||||
eNext = eDel.next;
|
||||
ePrev = eDel.Sym.next;
|
||||
eNext.Sym.next = ePrev;
|
||||
ePrev.Sym.next = eNext;
|
||||
}
|
||||
|
||||
|
||||
/* KillVertex( vDel ) destroys a vertex and removes it from the global
|
||||
* vertex list. It updates the vertex loop to point to a given new vertex.
|
||||
*/
|
||||
static void KillVertex(GLUvertex vDel, GLUvertex newOrg) {
|
||||
GLUhalfEdge e, eStart = vDel.anEdge;
|
||||
GLUvertex vPrev, vNext;
|
||||
|
||||
/* change the origin of all affected edges */
|
||||
e = eStart;
|
||||
do {
|
||||
e.Org = newOrg;
|
||||
e = e.Onext;
|
||||
} while (e != eStart);
|
||||
|
||||
/* delete from circular doubly-linked list */
|
||||
vPrev = vDel.prev;
|
||||
vNext = vDel.next;
|
||||
vNext.prev = vPrev;
|
||||
vPrev.next = vNext;
|
||||
}
|
||||
|
||||
/* KillFace( fDel ) destroys a face and removes it from the global face
|
||||
* list. It updates the face loop to point to a given new face.
|
||||
*/
|
||||
static void KillFace(GLUface fDel, GLUface newLface) {
|
||||
GLUhalfEdge e, eStart = fDel.anEdge;
|
||||
GLUface fPrev, fNext;
|
||||
|
||||
/* change the left face of all affected edges */
|
||||
e = eStart;
|
||||
do {
|
||||
e.Lface = newLface;
|
||||
e = e.Lnext;
|
||||
} while (e != eStart);
|
||||
|
||||
/* delete from circular doubly-linked list */
|
||||
fPrev = fDel.prev;
|
||||
fNext = fDel.next;
|
||||
fNext.prev = fPrev;
|
||||
fPrev.next = fNext;
|
||||
}
|
||||
|
||||
|
||||
/****************** Basic Edge Operations **********************/
|
||||
|
||||
/* __gl_meshMakeEdge creates one edge, two vertices, and a loop (face).
|
||||
* The loop consists of the two new half-edges.
|
||||
*/
|
||||
public static GLUhalfEdge __gl_meshMakeEdge(GLUmesh mesh) {
|
||||
GLUvertex newVertex1 = new GLUvertex();
|
||||
GLUvertex newVertex2 = new GLUvertex();
|
||||
GLUface newFace = new GLUface();
|
||||
GLUhalfEdge e;
|
||||
|
||||
e = MakeEdge(mesh.eHead);
|
||||
if (e == null) return null;
|
||||
|
||||
MakeVertex(newVertex1, e, mesh.vHead);
|
||||
MakeVertex(newVertex2, e.Sym, mesh.vHead);
|
||||
MakeFace(newFace, e, mesh.fHead);
|
||||
return e;
|
||||
}
|
||||
|
||||
|
||||
/* __gl_meshSplice( eOrg, eDst ) is the basic operation for changing the
|
||||
* mesh connectivity and topology. It changes the mesh so that
|
||||
* eOrg->Onext <- OLD( eDst->Onext )
|
||||
* eDst->Onext <- OLD( eOrg->Onext )
|
||||
* where OLD(...) means the value before the meshSplice operation.
|
||||
*
|
||||
* This can have two effects on the vertex structure:
|
||||
* - if eOrg->Org != eDst->Org, the two vertices are merged together
|
||||
* - if eOrg->Org == eDst->Org, the origin is split into two vertices
|
||||
* In both cases, eDst->Org is changed and eOrg->Org is untouched.
|
||||
*
|
||||
* Similarly (and independently) for the face structure,
|
||||
* - if eOrg->Lface == eDst->Lface, one loop is split into two
|
||||
* - if eOrg->Lface != eDst->Lface, two distinct loops are joined into one
|
||||
* In both cases, eDst->Lface is changed and eOrg->Lface is unaffected.
|
||||
*
|
||||
* Some special cases:
|
||||
* If eDst == eOrg, the operation has no effect.
|
||||
* If eDst == eOrg->Lnext, the new face will have a single edge.
|
||||
* If eDst == eOrg->Lprev, the old face will have a single edge.
|
||||
* If eDst == eOrg->Onext, the new vertex will have a single edge.
|
||||
* If eDst == eOrg->Oprev, the old vertex will have a single edge.
|
||||
*/
|
||||
public static boolean __gl_meshSplice(GLUhalfEdge eOrg, GLUhalfEdge eDst) {
|
||||
boolean joiningLoops = false;
|
||||
boolean joiningVertices = false;
|
||||
|
||||
if (eOrg == eDst) return true;
|
||||
|
||||
if (eDst.Org != eOrg.Org) {
|
||||
/* We are merging two disjoint vertices -- destroy eDst->Org */
|
||||
joiningVertices = true;
|
||||
KillVertex(eDst.Org, eOrg.Org);
|
||||
}
|
||||
if (eDst.Lface != eOrg.Lface) {
|
||||
/* We are connecting two disjoint loops -- destroy eDst.Lface */
|
||||
joiningLoops = true;
|
||||
KillFace(eDst.Lface, eOrg.Lface);
|
||||
}
|
||||
|
||||
/* Change the edge structure */
|
||||
Splice(eDst, eOrg);
|
||||
|
||||
if (!joiningVertices) {
|
||||
GLUvertex newVertex = new GLUvertex();
|
||||
|
||||
/* We split one vertex into two -- the new vertex is eDst.Org.
|
||||
* Make sure the old vertex points to a valid half-edge.
|
||||
*/
|
||||
MakeVertex(newVertex, eDst, eOrg.Org);
|
||||
eOrg.Org.anEdge = eOrg;
|
||||
}
|
||||
if (!joiningLoops) {
|
||||
GLUface newFace = new GLUface();
|
||||
|
||||
/* We split one loop into two -- the new loop is eDst.Lface.
|
||||
* Make sure the old face points to a valid half-edge.
|
||||
*/
|
||||
MakeFace(newFace, eDst, eOrg.Lface);
|
||||
eOrg.Lface.anEdge = eOrg;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/* __gl_meshDelete( eDel ) removes the edge eDel. There are several cases:
|
||||
* if (eDel.Lface != eDel.Rface), we join two loops into one; the loop
|
||||
* eDel.Lface is deleted. Otherwise, we are splitting one loop into two;
|
||||
* the newly created loop will contain eDel.Dst. If the deletion of eDel
|
||||
* would create isolated vertices, those are deleted as well.
|
||||
*
|
||||
* This function could be implemented as two calls to __gl_meshSplice
|
||||
* plus a few calls to memFree, but this would allocate and delete
|
||||
* unnecessary vertices and faces.
|
||||
*/
|
||||
static boolean __gl_meshDelete(GLUhalfEdge eDel) {
|
||||
GLUhalfEdge eDelSym = eDel.Sym;
|
||||
boolean joiningLoops = false;
|
||||
|
||||
/* First step: disconnect the origin vertex eDel.Org. We make all
|
||||
* changes to get a consistent mesh in this "intermediate" state.
|
||||
*/
|
||||
if (eDel.Lface != eDel.Sym.Lface) {
|
||||
/* We are joining two loops into one -- remove the left face */
|
||||
joiningLoops = true;
|
||||
KillFace(eDel.Lface, eDel.Sym.Lface);
|
||||
}
|
||||
|
||||
if (eDel.Onext == eDel) {
|
||||
KillVertex(eDel.Org, null);
|
||||
} else {
|
||||
/* Make sure that eDel.Org and eDel.Sym.Lface point to valid half-edges */
|
||||
eDel.Sym.Lface.anEdge = eDel.Sym.Lnext;
|
||||
eDel.Org.anEdge = eDel.Onext;
|
||||
|
||||
Splice(eDel, eDel.Sym.Lnext);
|
||||
if (!joiningLoops) {
|
||||
GLUface newFace = new GLUface();
|
||||
|
||||
/* We are splitting one loop into two -- create a new loop for eDel. */
|
||||
MakeFace(newFace, eDel, eDel.Lface);
|
||||
}
|
||||
}
|
||||
|
||||
/* Claim: the mesh is now in a consistent state, except that eDel.Org
|
||||
* may have been deleted. Now we disconnect eDel.Dst.
|
||||
*/
|
||||
if (eDelSym.Onext == eDelSym) {
|
||||
KillVertex(eDelSym.Org, null);
|
||||
KillFace(eDelSym.Lface, null);
|
||||
} else {
|
||||
/* Make sure that eDel.Dst and eDel.Lface point to valid half-edges */
|
||||
eDel.Lface.anEdge = eDelSym.Sym.Lnext;
|
||||
eDelSym.Org.anEdge = eDelSym.Onext;
|
||||
Splice(eDelSym, eDelSym.Sym.Lnext);
|
||||
}
|
||||
|
||||
/* Any isolated vertices or faces have already been freed. */
|
||||
KillEdge(eDel);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/******************** Other Edge Operations **********************/
|
||||
|
||||
/* All these routines can be implemented with the basic edge
|
||||
* operations above. They are provided for convenience and efficiency.
|
||||
*/
|
||||
|
||||
|
||||
/* __gl_meshAddEdgeVertex( eOrg ) creates a new edge eNew such that
|
||||
* eNew == eOrg.Lnext, and eNew.Dst is a newly created vertex.
|
||||
* eOrg and eNew will have the same left face.
|
||||
*/
|
||||
static GLUhalfEdge __gl_meshAddEdgeVertex(GLUhalfEdge eOrg) {
|
||||
GLUhalfEdge eNewSym;
|
||||
GLUhalfEdge eNew = MakeEdge(eOrg);
|
||||
|
||||
eNewSym = eNew.Sym;
|
||||
|
||||
/* Connect the new edge appropriately */
|
||||
Splice(eNew, eOrg.Lnext);
|
||||
|
||||
/* Set the vertex and face information */
|
||||
eNew.Org = eOrg.Sym.Org;
|
||||
{
|
||||
GLUvertex newVertex = new GLUvertex();
|
||||
|
||||
MakeVertex(newVertex, eNewSym, eNew.Org);
|
||||
}
|
||||
eNew.Lface = eNewSym.Lface = eOrg.Lface;
|
||||
|
||||
return eNew;
|
||||
}
|
||||
|
||||
|
||||
/* __gl_meshSplitEdge( eOrg ) splits eOrg into two edges eOrg and eNew,
|
||||
* such that eNew == eOrg.Lnext. The new vertex is eOrg.Sym.Org == eNew.Org.
|
||||
* eOrg and eNew will have the same left face.
|
||||
*/
|
||||
public static GLUhalfEdge __gl_meshSplitEdge(GLUhalfEdge eOrg) {
|
||||
GLUhalfEdge eNew;
|
||||
GLUhalfEdge tempHalfEdge = __gl_meshAddEdgeVertex(eOrg);
|
||||
|
||||
eNew = tempHalfEdge.Sym;
|
||||
|
||||
/* Disconnect eOrg from eOrg.Sym.Org and connect it to eNew.Org */
|
||||
Splice(eOrg.Sym, eOrg.Sym.Sym.Lnext);
|
||||
Splice(eOrg.Sym, eNew);
|
||||
|
||||
/* Set the vertex and face information */
|
||||
eOrg.Sym.Org = eNew.Org;
|
||||
eNew.Sym.Org.anEdge = eNew.Sym; /* may have pointed to eOrg.Sym */
|
||||
eNew.Sym.Lface = eOrg.Sym.Lface;
|
||||
eNew.winding = eOrg.winding; /* copy old winding information */
|
||||
eNew.Sym.winding = eOrg.Sym.winding;
|
||||
|
||||
return eNew;
|
||||
}
|
||||
|
||||
|
||||
/* __gl_meshConnect( eOrg, eDst ) creates a new edge from eOrg.Sym.Org
|
||||
* to eDst.Org, and returns the corresponding half-edge eNew.
|
||||
* If eOrg.Lface == eDst.Lface, this splits one loop into two,
|
||||
* and the newly created loop is eNew.Lface. Otherwise, two disjoint
|
||||
* loops are merged into one, and the loop eDst.Lface is destroyed.
|
||||
*
|
||||
* If (eOrg == eDst), the new face will have only two edges.
|
||||
* If (eOrg.Lnext == eDst), the old face is reduced to a single edge.
|
||||
* If (eOrg.Lnext.Lnext == eDst), the old face is reduced to two edges.
|
||||
*/
|
||||
static GLUhalfEdge __gl_meshConnect(GLUhalfEdge eOrg, GLUhalfEdge eDst) {
|
||||
GLUhalfEdge eNewSym;
|
||||
boolean joiningLoops = false;
|
||||
GLUhalfEdge eNew = MakeEdge(eOrg);
|
||||
|
||||
eNewSym = eNew.Sym;
|
||||
|
||||
if (eDst.Lface != eOrg.Lface) {
|
||||
/* We are connecting two disjoint loops -- destroy eDst.Lface */
|
||||
joiningLoops = true;
|
||||
KillFace(eDst.Lface, eOrg.Lface);
|
||||
}
|
||||
|
||||
/* Connect the new edge appropriately */
|
||||
Splice(eNew, eOrg.Lnext);
|
||||
Splice(eNewSym, eDst);
|
||||
|
||||
/* Set the vertex and face information */
|
||||
eNew.Org = eOrg.Sym.Org;
|
||||
eNewSym.Org = eDst.Org;
|
||||
eNew.Lface = eNewSym.Lface = eOrg.Lface;
|
||||
|
||||
/* Make sure the old face points to a valid half-edge */
|
||||
eOrg.Lface.anEdge = eNewSym;
|
||||
|
||||
if (!joiningLoops) {
|
||||
GLUface newFace = new GLUface();
|
||||
|
||||
/* We split one loop into two -- the new loop is eNew.Lface */
|
||||
MakeFace(newFace, eNew, eOrg.Lface);
|
||||
}
|
||||
return eNew;
|
||||
}
|
||||
|
||||
|
||||
/******************** Other Operations **********************/
|
||||
|
||||
/* __gl_meshZapFace( fZap ) destroys a face and removes it from the
|
||||
* global face list. All edges of fZap will have a null pointer as their
|
||||
* left face. Any edges which also have a null pointer as their right face
|
||||
* are deleted entirely (along with any isolated vertices this produces).
|
||||
* An entire mesh can be deleted by zapping its faces, one at a time,
|
||||
* in any order. Zapped faces cannot be used in further mesh operations!
|
||||
*/
|
||||
static void __gl_meshZapFace(GLUface fZap) {
|
||||
GLUhalfEdge eStart = fZap.anEdge;
|
||||
GLUhalfEdge e, eNext, eSym;
|
||||
GLUface fPrev, fNext;
|
||||
|
||||
/* walk around face, deleting edges whose right face is also null */
|
||||
eNext = eStart.Lnext;
|
||||
do {
|
||||
e = eNext;
|
||||
eNext = e.Lnext;
|
||||
|
||||
e.Lface = null;
|
||||
if (e.Sym.Lface == null) {
|
||||
/* delete the edge -- see __gl_MeshDelete above */
|
||||
|
||||
if (e.Onext == e) {
|
||||
KillVertex(e.Org, null);
|
||||
} else {
|
||||
/* Make sure that e.Org points to a valid half-edge */
|
||||
e.Org.anEdge = e.Onext;
|
||||
Splice(e, e.Sym.Lnext);
|
||||
}
|
||||
eSym = e.Sym;
|
||||
if (eSym.Onext == eSym) {
|
||||
KillVertex(eSym.Org, null);
|
||||
} else {
|
||||
/* Make sure that eSym.Org points to a valid half-edge */
|
||||
eSym.Org.anEdge = eSym.Onext;
|
||||
Splice(eSym, eSym.Sym.Lnext);
|
||||
}
|
||||
KillEdge(e);
|
||||
}
|
||||
} while (e != eStart);
|
||||
|
||||
/* delete from circular doubly-linked list */
|
||||
fPrev = fZap.prev;
|
||||
fNext = fZap.next;
|
||||
fNext.prev = fPrev;
|
||||
fPrev.next = fNext;
|
||||
}
|
||||
|
||||
|
||||
/* __gl_meshNewMesh() creates a new mesh with no edges, no vertices,
|
||||
* and no loops (what we usually call a "face").
|
||||
*/
|
||||
public static GLUmesh __gl_meshNewMesh() {
|
||||
GLUvertex v;
|
||||
GLUface f;
|
||||
GLUhalfEdge e;
|
||||
GLUhalfEdge eSym;
|
||||
GLUmesh mesh = new GLUmesh();
|
||||
|
||||
v = mesh.vHead;
|
||||
f = mesh.fHead;
|
||||
e = mesh.eHead;
|
||||
eSym = mesh.eHeadSym;
|
||||
|
||||
v.next = v.prev = v;
|
||||
v.anEdge = null;
|
||||
v.data = null;
|
||||
|
||||
f.next = f.prev = f;
|
||||
f.anEdge = null;
|
||||
f.data = null;
|
||||
f.trail = null;
|
||||
f.marked = false;
|
||||
f.inside = false;
|
||||
|
||||
e.next = e;
|
||||
e.Sym = eSym;
|
||||
e.Onext = null;
|
||||
e.Lnext = null;
|
||||
e.Org = null;
|
||||
e.Lface = null;
|
||||
e.winding = 0;
|
||||
e.activeRegion = null;
|
||||
|
||||
eSym.next = eSym;
|
||||
eSym.Sym = e;
|
||||
eSym.Onext = null;
|
||||
eSym.Lnext = null;
|
||||
eSym.Org = null;
|
||||
eSym.Lface = null;
|
||||
eSym.winding = 0;
|
||||
eSym.activeRegion = null;
|
||||
|
||||
return mesh;
|
||||
}
|
||||
|
||||
|
||||
/* __gl_meshUnion( mesh1, mesh2 ) forms the union of all structures in
|
||||
* both meshes, and returns the new mesh (the old meshes are destroyed).
|
||||
*/
|
||||
static GLUmesh __gl_meshUnion(GLUmesh mesh1, GLUmesh mesh2) {
|
||||
GLUface f1 = mesh1.fHead;
|
||||
GLUvertex v1 = mesh1.vHead;
|
||||
GLUhalfEdge e1 = mesh1.eHead;
|
||||
GLUface f2 = mesh2.fHead;
|
||||
GLUvertex v2 = mesh2.vHead;
|
||||
GLUhalfEdge e2 = mesh2.eHead;
|
||||
|
||||
/* Add the faces, vertices, and edges of mesh2 to those of mesh1 */
|
||||
if (f2.next != f2) {
|
||||
f1.prev.next = f2.next;
|
||||
f2.next.prev = f1.prev;
|
||||
f2.prev.next = f1;
|
||||
f1.prev = f2.prev;
|
||||
}
|
||||
|
||||
if (v2.next != v2) {
|
||||
v1.prev.next = v2.next;
|
||||
v2.next.prev = v1.prev;
|
||||
v2.prev.next = v1;
|
||||
v1.prev = v2.prev;
|
||||
}
|
||||
|
||||
if (e2.next != e2) {
|
||||
e1.Sym.next.Sym.next = e2.next;
|
||||
e2.next.Sym.next = e1.Sym.next;
|
||||
e2.Sym.next.Sym.next = e1;
|
||||
e1.Sym.next = e2.Sym.next;
|
||||
}
|
||||
|
||||
return mesh1;
|
||||
}
|
||||
|
||||
|
||||
/* __gl_meshDeleteMesh( mesh ) will free all storage for any valid mesh.
|
||||
*/
|
||||
static void __gl_meshDeleteMeshZap(GLUmesh mesh) {
|
||||
GLUface fHead = mesh.fHead;
|
||||
|
||||
while (fHead.next != fHead) {
|
||||
__gl_meshZapFace(fHead.next);
|
||||
}
|
||||
assert (mesh.vHead.next == mesh.vHead);
|
||||
}
|
||||
|
||||
/* __gl_meshDeleteMesh( mesh ) will free all storage for any valid mesh.
|
||||
*/
|
||||
public static void __gl_meshDeleteMesh(GLUmesh mesh) {
|
||||
GLUface f, fNext;
|
||||
GLUvertex v, vNext;
|
||||
GLUhalfEdge e, eNext;
|
||||
|
||||
for (f = mesh.fHead.next; f != mesh.fHead; f = fNext) {
|
||||
fNext = f.next;
|
||||
}
|
||||
|
||||
for (v = mesh.vHead.next; v != mesh.vHead; v = vNext) {
|
||||
vNext = v.next;
|
||||
}
|
||||
|
||||
for (e = mesh.eHead.next; e != mesh.eHead; e = eNext) {
|
||||
/* One call frees both e and e.Sym (see EdgePair above) */
|
||||
eNext = e.next;
|
||||
}
|
||||
}
|
||||
|
||||
/* __gl_meshCheckMesh( mesh ) checks a mesh for self-consistency.
|
||||
*/
|
||||
public static void __gl_meshCheckMesh(GLUmesh mesh) {
|
||||
GLUface fHead = mesh.fHead;
|
||||
GLUvertex vHead = mesh.vHead;
|
||||
GLUhalfEdge eHead = mesh.eHead;
|
||||
GLUface f, fPrev;
|
||||
GLUvertex v, vPrev;
|
||||
GLUhalfEdge e, ePrev;
|
||||
|
||||
fPrev = fHead;
|
||||
for (fPrev = fHead; (f = fPrev.next) != fHead; fPrev = f) {
|
||||
assert (f.prev == fPrev);
|
||||
e = f.anEdge;
|
||||
do {
|
||||
assert (e.Sym != e);
|
||||
assert (e.Sym.Sym == e);
|
||||
assert (e.Lnext.Onext.Sym == e);
|
||||
assert (e.Onext.Sym.Lnext == e);
|
||||
assert (e.Lface == f);
|
||||
e = e.Lnext;
|
||||
} while (e != f.anEdge);
|
||||
}
|
||||
assert (f.prev == fPrev && f.anEdge == null && f.data == null);
|
||||
|
||||
vPrev = vHead;
|
||||
for (vPrev = vHead; (v = vPrev.next) != vHead; vPrev = v) {
|
||||
assert (v.prev == vPrev);
|
||||
e = v.anEdge;
|
||||
do {
|
||||
assert (e.Sym != e);
|
||||
assert (e.Sym.Sym == e);
|
||||
assert (e.Lnext.Onext.Sym == e);
|
||||
assert (e.Onext.Sym.Lnext == e);
|
||||
assert (e.Org == v);
|
||||
e = e.Onext;
|
||||
} while (e != v.anEdge);
|
||||
}
|
||||
assert (v.prev == vPrev && v.anEdge == null && v.data == null);
|
||||
|
||||
ePrev = eHead;
|
||||
for (ePrev = eHead; (e = ePrev.next) != eHead; ePrev = e) {
|
||||
assert (e.Sym.next == ePrev.Sym);
|
||||
assert (e.Sym != e);
|
||||
assert (e.Sym.Sym == e);
|
||||
assert (e.Org != null);
|
||||
assert (e.Sym.Org != null);
|
||||
assert (e.Lnext.Onext.Sym == e);
|
||||
assert (e.Onext.Sym.Lnext == e);
|
||||
}
|
||||
assert (e.Sym.next == ePrev.Sym
|
||||
&& e.Sym == mesh.eHeadSym
|
||||
&& e.Sym.Sym == e
|
||||
&& e.Org == null && e.Sym.Org == null
|
||||
&& e.Lface == null && e.Sym.Lface == null);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,319 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2008 LWJGL Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * 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.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "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 THE COPYRIGHT OWNER 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Portions Copyright (C) 2003-2006 Sun Microsystems, Inc.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/*
|
||||
** License Applicability. Except to the extent portions of this file are
|
||||
** made subject to an alternative license as permitted in the SGI Free
|
||||
** Software License B, Version 1.1 (the "License"), the contents of this
|
||||
** file are subject only to the provisions of the License. You may not use
|
||||
** this file except in compliance with the License. You may obtain a copy
|
||||
** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
|
||||
** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
|
||||
**
|
||||
** http://oss.sgi.com/projects/FreeB
|
||||
**
|
||||
** Note that, as provided in the License, the Software is distributed on an
|
||||
** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
|
||||
** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
|
||||
** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
|
||||
** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
|
||||
**
|
||||
** NOTE: The Original Code (as defined below) has been licensed to Sun
|
||||
** Microsystems, Inc. ("Sun") under the SGI Free Software License B
|
||||
** (Version 1.1), shown above ("SGI License"). Pursuant to Section
|
||||
** 3.2(3) of the SGI License, Sun is distributing the Covered Code to
|
||||
** you under an alternative license ("Alternative License"). This
|
||||
** Alternative License includes all of the provisions of the SGI License
|
||||
** except that Section 2.2 and 11 are omitted. Any differences between
|
||||
** the Alternative License and the SGI License are offered solely by Sun
|
||||
** and not by SGI.
|
||||
**
|
||||
** Original Code. The Original Code is: OpenGL Sample Implementation,
|
||||
** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
|
||||
** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
|
||||
** Copyright in any portions created by third parties is as indicated
|
||||
** elsewhere herein. All Rights Reserved.
|
||||
**
|
||||
** Additional Notice Provisions: The application programming interfaces
|
||||
** established by SGI in conjunction with the Original Code are The
|
||||
** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
|
||||
** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
|
||||
** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
|
||||
** Window System(R) (Version 1.3), released October 19, 1998. This software
|
||||
** was created using the OpenGL(R) version 1.2.1 Sample Implementation
|
||||
** published by SGI, but has not been independently verified as being
|
||||
** compliant with the OpenGL(R) version 1.2.1 Specification.
|
||||
**
|
||||
** Author: Eric Veach, July 1994
|
||||
** Java Port: Pepijn Van Eeckhoudt, July 2003
|
||||
** Java Port: Nathan Parker Burg, August 2003
|
||||
*/
|
||||
package org.lwjgl.util.glu.tessellation;
|
||||
|
||||
import org.lwjgl.util.glu.GLU;
|
||||
|
||||
class Normal {
|
||||
private Normal() {
|
||||
}
|
||||
|
||||
static boolean SLANTED_SWEEP = false;
|
||||
static double S_UNIT_X; /* Pre-normalized */
|
||||
static double S_UNIT_Y;
|
||||
private static final boolean TRUE_PROJECT = false;
|
||||
|
||||
static {
|
||||
if (SLANTED_SWEEP) {
|
||||
/* The "feature merging" is not intended to be complete. There are
|
||||
* special cases where edges are nearly parallel to the sweep line
|
||||
* which are not implemented. The algorithm should still behave
|
||||
* robustly (ie. produce a reasonable tesselation) in the presence
|
||||
* of such edges, however it may miss features which could have been
|
||||
* merged. We could minimize this effect by choosing the sweep line
|
||||
* direction to be something unusual (ie. not parallel to one of the
|
||||
* coordinate axes).
|
||||
*/
|
||||
S_UNIT_X = 0.50941539564955385; /* Pre-normalized */
|
||||
S_UNIT_Y = 0.86052074622010633;
|
||||
} else {
|
||||
S_UNIT_X = 1.0;
|
||||
S_UNIT_Y = 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
private static double Dot(double[] u, double[] v) {
|
||||
return (u[0] * v[0] + u[1] * v[1] + u[2] * v[2]);
|
||||
}
|
||||
|
||||
static void Normalize(double[] v) {
|
||||
double len = v[0] * v[0] + v[1] * v[1] + v[2] * v[2];
|
||||
|
||||
assert (len > 0);
|
||||
len = Math.sqrt(len);
|
||||
v[0] /= len;
|
||||
v[1] /= len;
|
||||
v[2] /= len;
|
||||
}
|
||||
|
||||
static int LongAxis(double[] v) {
|
||||
int i = 0;
|
||||
|
||||
if (Math.abs(v[1]) > Math.abs(v[0])) {
|
||||
i = 1;
|
||||
}
|
||||
if (Math.abs(v[2]) > Math.abs(v[i])) {
|
||||
i = 2;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
static void ComputeNormal(GLUtessellatorImpl tess, double[] norm) {
|
||||
GLUvertex v, v1, v2;
|
||||
double c, tLen2, maxLen2;
|
||||
double[] maxVal, minVal, d1, d2, tNorm;
|
||||
GLUvertex[] maxVert, minVert;
|
||||
GLUvertex vHead = tess.mesh.vHead;
|
||||
int i;
|
||||
|
||||
maxVal = new double[3];
|
||||
minVal = new double[3];
|
||||
minVert = new GLUvertex[3];
|
||||
maxVert = new GLUvertex[3];
|
||||
d1 = new double[3];
|
||||
d2 = new double[3];
|
||||
tNorm = new double[3];
|
||||
|
||||
maxVal[0] = maxVal[1] = maxVal[2] = -2 * GLU.TESS_MAX_COORD;
|
||||
minVal[0] = minVal[1] = minVal[2] = 2 * GLU.TESS_MAX_COORD;
|
||||
|
||||
for (v = vHead.next; v != vHead; v = v.next) {
|
||||
for (i = 0; i < 3; ++i) {
|
||||
c = v.coords[i];
|
||||
if (c < minVal[i]) {
|
||||
minVal[i] = c;
|
||||
minVert[i] = v;
|
||||
}
|
||||
if (c > maxVal[i]) {
|
||||
maxVal[i] = c;
|
||||
maxVert[i] = v;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Find two vertices separated by at least 1/sqrt(3) of the maximum
|
||||
* distance between any two vertices
|
||||
*/
|
||||
i = 0;
|
||||
if (maxVal[1] - minVal[1] > maxVal[0] - minVal[0]) {
|
||||
i = 1;
|
||||
}
|
||||
if (maxVal[2] - minVal[2] > maxVal[i] - minVal[i]) {
|
||||
i = 2;
|
||||
}
|
||||
if (minVal[i] >= maxVal[i]) {
|
||||
/* All vertices are the same -- normal doesn't matter */
|
||||
norm[0] = 0;
|
||||
norm[1] = 0;
|
||||
norm[2] = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
/* Look for a third vertex which forms the triangle with maximum area
|
||||
* (Length of normal == twice the triangle area)
|
||||
*/
|
||||
maxLen2 = 0;
|
||||
v1 = minVert[i];
|
||||
v2 = maxVert[i];
|
||||
d1[0] = v1.coords[0] - v2.coords[0];
|
||||
d1[1] = v1.coords[1] - v2.coords[1];
|
||||
d1[2] = v1.coords[2] - v2.coords[2];
|
||||
for (v = vHead.next; v != vHead; v = v.next) {
|
||||
d2[0] = v.coords[0] - v2.coords[0];
|
||||
d2[1] = v.coords[1] - v2.coords[1];
|
||||
d2[2] = v.coords[2] - v2.coords[2];
|
||||
tNorm[0] = d1[1] * d2[2] - d1[2] * d2[1];
|
||||
tNorm[1] = d1[2] * d2[0] - d1[0] * d2[2];
|
||||
tNorm[2] = d1[0] * d2[1] - d1[1] * d2[0];
|
||||
tLen2 = tNorm[0] * tNorm[0] + tNorm[1] * tNorm[1] + tNorm[2] * tNorm[2];
|
||||
if (tLen2 > maxLen2) {
|
||||
maxLen2 = tLen2;
|
||||
norm[0] = tNorm[0];
|
||||
norm[1] = tNorm[1];
|
||||
norm[2] = tNorm[2];
|
||||
}
|
||||
}
|
||||
|
||||
if (maxLen2 <= 0) {
|
||||
/* All points lie on a single line -- any decent normal will do */
|
||||
norm[0] = norm[1] = norm[2] = 0;
|
||||
norm[LongAxis(d1)] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
static void CheckOrientation(GLUtessellatorImpl tess) {
|
||||
double area;
|
||||
GLUface f, fHead = tess.mesh.fHead;
|
||||
GLUvertex v, vHead = tess.mesh.vHead;
|
||||
GLUhalfEdge e;
|
||||
|
||||
/* When we compute the normal automatically, we choose the orientation
|
||||
* so that the the sum of the signed areas of all contours is non-negative.
|
||||
*/
|
||||
area = 0;
|
||||
for (f = fHead.next; f != fHead; f = f.next) {
|
||||
e = f.anEdge;
|
||||
if (e.winding <= 0) continue;
|
||||
do {
|
||||
area += (e.Org.s - e.Sym.Org.s) * (e.Org.t + e.Sym.Org.t);
|
||||
e = e.Lnext;
|
||||
} while (e != f.anEdge);
|
||||
}
|
||||
if (area < 0) {
|
||||
/* Reverse the orientation by flipping all the t-coordinates */
|
||||
for (v = vHead.next; v != vHead; v = v.next) {
|
||||
v.t = -v.t;
|
||||
}
|
||||
tess.tUnit[0] = -tess.tUnit[0];
|
||||
tess.tUnit[1] = -tess.tUnit[1];
|
||||
tess.tUnit[2] = -tess.tUnit[2];
|
||||
}
|
||||
}
|
||||
|
||||
/* Determine the polygon normal and project vertices onto the plane
|
||||
* of the polygon.
|
||||
*/
|
||||
public static void __gl_projectPolygon(GLUtessellatorImpl tess) {
|
||||
GLUvertex v, vHead = tess.mesh.vHead;
|
||||
double w;
|
||||
double[] norm = new double[3];
|
||||
double[] sUnit, tUnit;
|
||||
int i;
|
||||
boolean computedNormal = false;
|
||||
|
||||
norm[0] = tess.normal[0];
|
||||
norm[1] = tess.normal[1];
|
||||
norm[2] = tess.normal[2];
|
||||
if (norm[0] == 0 && norm[1] == 0 && norm[2] == 0) {
|
||||
ComputeNormal(tess, norm);
|
||||
computedNormal = true;
|
||||
}
|
||||
sUnit = tess.sUnit;
|
||||
tUnit = tess.tUnit;
|
||||
i = LongAxis(norm);
|
||||
|
||||
if (TRUE_PROJECT) {
|
||||
/* Choose the initial sUnit vector to be approximately perpendicular
|
||||
* to the normal.
|
||||
*/
|
||||
Normalize(norm);
|
||||
|
||||
sUnit[i] = 0;
|
||||
sUnit[(i + 1) % 3] = S_UNIT_X;
|
||||
sUnit[(i + 2) % 3] = S_UNIT_Y;
|
||||
|
||||
/* Now make it exactly perpendicular */
|
||||
w = Dot(sUnit, norm);
|
||||
sUnit[0] -= w * norm[0];
|
||||
sUnit[1] -= w * norm[1];
|
||||
sUnit[2] -= w * norm[2];
|
||||
Normalize(sUnit);
|
||||
|
||||
/* Choose tUnit so that (sUnit,tUnit,norm) form a right-handed frame */
|
||||
tUnit[0] = norm[1] * sUnit[2] - norm[2] * sUnit[1];
|
||||
tUnit[1] = norm[2] * sUnit[0] - norm[0] * sUnit[2];
|
||||
tUnit[2] = norm[0] * sUnit[1] - norm[1] * sUnit[0];
|
||||
Normalize(tUnit);
|
||||
} else {
|
||||
/* Project perpendicular to a coordinate axis -- better numerically */
|
||||
sUnit[i] = 0;
|
||||
sUnit[(i + 1) % 3] = S_UNIT_X;
|
||||
sUnit[(i + 2) % 3] = S_UNIT_Y;
|
||||
|
||||
tUnit[i] = 0;
|
||||
tUnit[(i + 1) % 3] = (norm[i] > 0) ? -S_UNIT_Y : S_UNIT_Y;
|
||||
tUnit[(i + 2) % 3] = (norm[i] > 0) ? S_UNIT_X : -S_UNIT_X;
|
||||
}
|
||||
|
||||
/* Project the vertices onto the sweep plane */
|
||||
for (v = vHead.next; v != vHead; v = v.next) {
|
||||
v.s = Dot(v.coords, sUnit);
|
||||
v.t = Dot(v.coords, tUnit);
|
||||
}
|
||||
if (computedNormal) {
|
||||
CheckOrientation(tess);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,132 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2008 LWJGL Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * 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.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "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 THE COPYRIGHT OWNER 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Portions Copyright (C) 2003-2006 Sun Microsystems, Inc.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/*
|
||||
** License Applicability. Except to the extent portions of this file are
|
||||
** made subject to an alternative license as permitted in the SGI Free
|
||||
** Software License B, Version 1.1 (the "License"), the contents of this
|
||||
** file are subject only to the provisions of the License. You may not use
|
||||
** this file except in compliance with the License. You may obtain a copy
|
||||
** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
|
||||
** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
|
||||
**
|
||||
** http://oss.sgi.com/projects/FreeB
|
||||
**
|
||||
** Note that, as provided in the License, the Software is distributed on an
|
||||
** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
|
||||
** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
|
||||
** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
|
||||
** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
|
||||
**
|
||||
** NOTE: The Original Code (as defined below) has been licensed to Sun
|
||||
** Microsystems, Inc. ("Sun") under the SGI Free Software License B
|
||||
** (Version 1.1), shown above ("SGI License"). Pursuant to Section
|
||||
** 3.2(3) of the SGI License, Sun is distributing the Covered Code to
|
||||
** you under an alternative license ("Alternative License"). This
|
||||
** Alternative License includes all of the provisions of the SGI License
|
||||
** except that Section 2.2 and 11 are omitted. Any differences between
|
||||
** the Alternative License and the SGI License are offered solely by Sun
|
||||
** and not by SGI.
|
||||
**
|
||||
** Original Code. The Original Code is: OpenGL Sample Implementation,
|
||||
** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
|
||||
** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
|
||||
** Copyright in any portions created by third parties is as indicated
|
||||
** elsewhere herein. All Rights Reserved.
|
||||
**
|
||||
** Additional Notice Provisions: The application programming interfaces
|
||||
** established by SGI in conjunction with the Original Code are The
|
||||
** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
|
||||
** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
|
||||
** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
|
||||
** Window System(R) (Version 1.3), released October 19, 1998. This software
|
||||
** was created using the OpenGL(R) version 1.2.1 Sample Implementation
|
||||
** published by SGI, but has not been independently verified as being
|
||||
** compliant with the OpenGL(R) version 1.2.1 Specification.
|
||||
**
|
||||
** Author: Eric Veach, July 1994
|
||||
** Java Port: Pepijn Van Eeckhoudt, July 2003
|
||||
** Java Port: Nathan Parker Burg, August 2003
|
||||
*/
|
||||
package org.lwjgl.util.glu.tessellation;
|
||||
|
||||
abstract class PriorityQ {
|
||||
public static final int INIT_SIZE = 32;
|
||||
|
||||
public static class PQnode {
|
||||
int handle;
|
||||
}
|
||||
|
||||
public static class PQhandleElem {
|
||||
Object key;
|
||||
int node;
|
||||
}
|
||||
|
||||
public static interface Leq {
|
||||
boolean leq(Object key1, Object key2);
|
||||
}
|
||||
|
||||
// #ifdef FOR_TRITE_TEST_PROGRAM
|
||||
// private static boolean LEQ(PriorityQCommon.Leq leq, Object x,Object y) {
|
||||
// return pq.leq.leq(x,y);
|
||||
// }
|
||||
// #else
|
||||
/* Violates modularity, but a little faster */
|
||||
// #include "geom.h"
|
||||
public static boolean LEQ(Leq leq, Object x, Object y) {
|
||||
return Geom.VertLeq((GLUvertex) x, (GLUvertex) y);
|
||||
}
|
||||
|
||||
static PriorityQ pqNewPriorityQ(Leq leq) {
|
||||
return new PriorityQSort(leq);
|
||||
}
|
||||
|
||||
abstract void pqDeletePriorityQ();
|
||||
|
||||
abstract boolean pqInit();
|
||||
|
||||
abstract int pqInsert(Object keyNew);
|
||||
|
||||
abstract Object pqExtractMin();
|
||||
|
||||
abstract void pqDelete(int hCurr);
|
||||
|
||||
abstract Object pqMinimum();
|
||||
|
||||
abstract boolean pqIsEmpty();
|
||||
// #endif
|
||||
}
|
|
@ -0,0 +1,296 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2008 LWJGL Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * 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.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "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 THE COPYRIGHT OWNER 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Portions Copyright (C) 2003-2006 Sun Microsystems, Inc.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/*
|
||||
** License Applicability. Except to the extent portions of this file are
|
||||
** made subject to an alternative license as permitted in the SGI Free
|
||||
** Software License B, Version 1.1 (the "License"), the contents of this
|
||||
** file are subject only to the provisions of the License. You may not use
|
||||
** this file except in compliance with the License. You may obtain a copy
|
||||
** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
|
||||
** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
|
||||
**
|
||||
** http://oss.sgi.com/projects/FreeB
|
||||
**
|
||||
** Note that, as provided in the License, the Software is distributed on an
|
||||
** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
|
||||
** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
|
||||
** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
|
||||
** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
|
||||
**
|
||||
** NOTE: The Original Code (as defined below) has been licensed to Sun
|
||||
** Microsystems, Inc. ("Sun") under the SGI Free Software License B
|
||||
** (Version 1.1), shown above ("SGI License"). Pursuant to Section
|
||||
** 3.2(3) of the SGI License, Sun is distributing the Covered Code to
|
||||
** you under an alternative license ("Alternative License"). This
|
||||
** Alternative License includes all of the provisions of the SGI License
|
||||
** except that Section 2.2 and 11 are omitted. Any differences between
|
||||
** the Alternative License and the SGI License are offered solely by Sun
|
||||
** and not by SGI.
|
||||
**
|
||||
** Original Code. The Original Code is: OpenGL Sample Implementation,
|
||||
** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
|
||||
** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
|
||||
** Copyright in any portions created by third parties is as indicated
|
||||
** elsewhere herein. All Rights Reserved.
|
||||
**
|
||||
** Additional Notice Provisions: The application programming interfaces
|
||||
** established by SGI in conjunction with the Original Code are The
|
||||
** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
|
||||
** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
|
||||
** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
|
||||
** Window System(R) (Version 1.3), released October 19, 1998. This software
|
||||
** was created using the OpenGL(R) version 1.2.1 Sample Implementation
|
||||
** published by SGI, but has not been independently verified as being
|
||||
** compliant with the OpenGL(R) version 1.2.1 Specification.
|
||||
**
|
||||
** Author: Eric Veach, July 1994
|
||||
** Java Port: Pepijn Van Eeckhoudt, July 2003
|
||||
** Java Port: Nathan Parker Burg, August 2003
|
||||
*/
|
||||
package org.lwjgl.util.glu.tessellation;
|
||||
|
||||
|
||||
|
||||
class PriorityQHeap extends PriorityQ {
|
||||
PriorityQ.PQnode[] nodes;
|
||||
PriorityQ.PQhandleElem[] handles;
|
||||
int size, max;
|
||||
int freeList;
|
||||
boolean initialized;
|
||||
PriorityQ.Leq leq;
|
||||
|
||||
/* really __gl_pqHeapNewPriorityQ */
|
||||
public PriorityQHeap(PriorityQ.Leq leq) {
|
||||
size = 0;
|
||||
max = PriorityQ.INIT_SIZE;
|
||||
nodes = new PriorityQ.PQnode[PriorityQ.INIT_SIZE + 1];
|
||||
for (int i = 0; i < nodes.length; i++) {
|
||||
nodes[i] = new PQnode();
|
||||
}
|
||||
handles = new PriorityQ.PQhandleElem[PriorityQ.INIT_SIZE + 1];
|
||||
for (int i = 0; i < handles.length; i++) {
|
||||
handles[i] = new PQhandleElem();
|
||||
}
|
||||
initialized = false;
|
||||
freeList = 0;
|
||||
this.leq = leq;
|
||||
|
||||
nodes[1].handle = 1; /* so that Minimum() returns NULL */
|
||||
handles[1].key = null;
|
||||
}
|
||||
|
||||
/* really __gl_pqHeapDeletePriorityQ */
|
||||
void pqDeletePriorityQ() {
|
||||
handles = null;
|
||||
nodes = null;
|
||||
}
|
||||
|
||||
void FloatDown(int curr) {
|
||||
PriorityQ.PQnode[] n = nodes;
|
||||
PriorityQ.PQhandleElem[] h = handles;
|
||||
int hCurr, hChild;
|
||||
int child;
|
||||
|
||||
hCurr = n[curr].handle;
|
||||
for (; ;) {
|
||||
child = curr << 1;
|
||||
if (child < size && LEQ(leq, h[n[child + 1].handle].key,
|
||||
h[n[child].handle].key)) {
|
||||
++child;
|
||||
}
|
||||
|
||||
assert (child <= max);
|
||||
|
||||
hChild = n[child].handle;
|
||||
if (child > size || LEQ(leq, h[hCurr].key, h[hChild].key)) {
|
||||
n[curr].handle = hCurr;
|
||||
h[hCurr].node = curr;
|
||||
break;
|
||||
}
|
||||
n[curr].handle = hChild;
|
||||
h[hChild].node = curr;
|
||||
curr = child;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void FloatUp(int curr) {
|
||||
PriorityQ.PQnode[] n = nodes;
|
||||
PriorityQ.PQhandleElem[] h = handles;
|
||||
int hCurr, hParent;
|
||||
int parent;
|
||||
|
||||
hCurr = n[curr].handle;
|
||||
for (; ;) {
|
||||
parent = curr >> 1;
|
||||
hParent = n[parent].handle;
|
||||
if (parent == 0 || LEQ(leq, h[hParent].key, h[hCurr].key)) {
|
||||
n[curr].handle = hCurr;
|
||||
h[hCurr].node = curr;
|
||||
break;
|
||||
}
|
||||
n[curr].handle = hParent;
|
||||
h[hParent].node = curr;
|
||||
curr = parent;
|
||||
}
|
||||
}
|
||||
|
||||
/* really __gl_pqHeapInit */
|
||||
boolean pqInit() {
|
||||
int i;
|
||||
|
||||
/* This method of building a heap is O(n), rather than O(n lg n). */
|
||||
|
||||
for (i = size; i >= 1; --i) {
|
||||
FloatDown(i);
|
||||
}
|
||||
initialized = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/* really __gl_pqHeapInsert */
|
||||
/* returns LONG_MAX iff out of memory */
|
||||
int pqInsert(Object keyNew) {
|
||||
int curr;
|
||||
int free;
|
||||
|
||||
curr = ++size;
|
||||
if ((curr * 2) > max) {
|
||||
PriorityQ.PQnode[] saveNodes = nodes;
|
||||
PriorityQ.PQhandleElem[] saveHandles = handles;
|
||||
|
||||
/* If the heap overflows, double its size. */
|
||||
max <<= 1;
|
||||
// pq->nodes = (PQnode *)memRealloc( pq->nodes, (size_t) ((pq->max + 1) * sizeof( pq->nodes[0] )));
|
||||
PriorityQ.PQnode[] pqNodes = new PriorityQ.PQnode[max + 1];
|
||||
System.arraycopy( nodes, 0, pqNodes, 0, nodes.length );
|
||||
for (int i = nodes.length; i < pqNodes.length; i++) {
|
||||
pqNodes[i] = new PQnode();
|
||||
}
|
||||
nodes = pqNodes;
|
||||
if (nodes == null) {
|
||||
nodes = saveNodes; /* restore ptr to free upon return */
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
|
||||
// pq->handles = (PQhandleElem *)memRealloc( pq->handles,(size_t)((pq->max + 1) * sizeof( pq->handles[0] )));
|
||||
PriorityQ.PQhandleElem[] pqHandles = new PriorityQ.PQhandleElem[max + 1];
|
||||
System.arraycopy( handles, 0, pqHandles, 0, handles.length );
|
||||
for (int i = handles.length; i < pqHandles.length; i++) {
|
||||
pqHandles[i] = new PQhandleElem();
|
||||
}
|
||||
handles = pqHandles;
|
||||
if (handles == null) {
|
||||
handles = saveHandles; /* restore ptr to free upon return */
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
}
|
||||
|
||||
if (freeList == 0) {
|
||||
free = curr;
|
||||
} else {
|
||||
free = freeList;
|
||||
freeList = handles[free].node;
|
||||
}
|
||||
|
||||
nodes[curr].handle = free;
|
||||
handles[free].node = curr;
|
||||
handles[free].key = keyNew;
|
||||
|
||||
if (initialized) {
|
||||
FloatUp(curr);
|
||||
}
|
||||
assert (free != Integer.MAX_VALUE);
|
||||
return free;
|
||||
}
|
||||
|
||||
/* really __gl_pqHeapExtractMin */
|
||||
Object pqExtractMin() {
|
||||
PriorityQ.PQnode[] n = nodes;
|
||||
PriorityQ.PQhandleElem[] h = handles;
|
||||
int hMin = n[1].handle;
|
||||
Object min = h[hMin].key;
|
||||
|
||||
if (size > 0) {
|
||||
n[1].handle = n[size].handle;
|
||||
h[n[1].handle].node = 1;
|
||||
|
||||
h[hMin].key = null;
|
||||
h[hMin].node = freeList;
|
||||
freeList = hMin;
|
||||
|
||||
if (--size > 0) {
|
||||
FloatDown(1);
|
||||
}
|
||||
}
|
||||
return min;
|
||||
}
|
||||
|
||||
/* really __gl_pqHeapDelete */
|
||||
void pqDelete(int hCurr) {
|
||||
PriorityQ.PQnode[] n = nodes;
|
||||
PriorityQ.PQhandleElem[] h = handles;
|
||||
int curr;
|
||||
|
||||
assert (hCurr >= 1 && hCurr <= max && h[hCurr].key != null);
|
||||
|
||||
curr = h[hCurr].node;
|
||||
n[curr].handle = n[size].handle;
|
||||
h[n[curr].handle].node = curr;
|
||||
|
||||
if (curr <= --size) {
|
||||
if (curr <= 1 || LEQ(leq, h[n[curr >> 1].handle].key, h[n[curr].handle].key)) {
|
||||
FloatDown(curr);
|
||||
} else {
|
||||
FloatUp(curr);
|
||||
}
|
||||
}
|
||||
h[hCurr].key = null;
|
||||
h[hCurr].node = freeList;
|
||||
freeList = hCurr;
|
||||
}
|
||||
|
||||
Object pqMinimum() {
|
||||
return handles[nodes[1].handle].key;
|
||||
}
|
||||
|
||||
boolean pqIsEmpty() {
|
||||
return size == 0;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,312 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2008 LWJGL Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * 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.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "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 THE COPYRIGHT OWNER 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
** License Applicability. Except to the extent portions of this file are
|
||||
** made subject to an alternative license as permitted in the SGI Free
|
||||
** Software License B, Version 1.1 (the "License"), the contents of this
|
||||
** file are subject only to the provisions of the License. You may not use
|
||||
** this file except in compliance with the License. You may obtain a copy
|
||||
** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
|
||||
** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
|
||||
**
|
||||
** http://oss.sgi.com/projects/FreeB
|
||||
**
|
||||
** Note that, as provided in the License, the Software is distributed on an
|
||||
** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
|
||||
** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
|
||||
** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
|
||||
** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
|
||||
**
|
||||
** NOTE: The Original Code (as defined below) has been licensed to Sun
|
||||
** Microsystems, Inc. ("Sun") under the SGI Free Software License B
|
||||
** (Version 1.1), shown above ("SGI License"). Pursuant to Section
|
||||
** 3.2(3) of the SGI License, Sun is distributing the Covered Code to
|
||||
** you under an alternative license ("Alternative License"). This
|
||||
** Alternative License includes all of the provisions of the SGI License
|
||||
** except that Section 2.2 and 11 are omitted. Any differences between
|
||||
** the Alternative License and the SGI License are offered solely by Sun
|
||||
** and not by SGI.
|
||||
**
|
||||
** Original Code. The Original Code is: OpenGL Sample Implementation,
|
||||
** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
|
||||
** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
|
||||
** Copyright in any portions created by third parties is as indicated
|
||||
** elsewhere herein. All Rights Reserved.
|
||||
**
|
||||
** Additional Notice Provisions: The application programming interfaces
|
||||
** established by SGI in conjunction with the Original Code are The
|
||||
** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
|
||||
** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
|
||||
** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
|
||||
** Window System(R) (Version 1.3), released October 19, 1998. This software
|
||||
** was created using the OpenGL(R) version 1.2.1 Sample Implementation
|
||||
** published by SGI, but has not been independently verified as being
|
||||
** compliant with the OpenGL(R) version 1.2.1 Specification.
|
||||
**
|
||||
** Author: Eric Veach, July 1994
|
||||
** Java Port: Pepijn Van Eeckhoudt, July 2003
|
||||
** Java Port: Nathan Parker Burg, August 2003
|
||||
*/
|
||||
package org.lwjgl.util.glu.tessellation;
|
||||
|
||||
|
||||
|
||||
class PriorityQSort extends PriorityQ {
|
||||
PriorityQHeap heap;
|
||||
Object[] keys;
|
||||
|
||||
// JAVA: 'order' contains indices into the keys array.
|
||||
// This simulates the indirect pointers used in the original C code
|
||||
// (from Frank Suykens, Luciad.com).
|
||||
int[] order;
|
||||
int size, max;
|
||||
boolean initialized;
|
||||
PriorityQ.Leq leq;
|
||||
|
||||
public PriorityQSort(PriorityQ.Leq leq) {
|
||||
heap = new PriorityQHeap(leq);
|
||||
|
||||
keys = new Object[PriorityQ.INIT_SIZE];
|
||||
|
||||
size = 0;
|
||||
max = PriorityQ.INIT_SIZE;
|
||||
initialized = false;
|
||||
this.leq = leq;
|
||||
}
|
||||
|
||||
/* really __gl_pqSortDeletePriorityQ */
|
||||
void pqDeletePriorityQ() {
|
||||
if (heap != null) heap.pqDeletePriorityQ();
|
||||
order = null;
|
||||
keys = null;
|
||||
}
|
||||
|
||||
private static boolean LT(PriorityQ.Leq leq, Object x, Object y) {
|
||||
return (!PriorityQHeap.LEQ(leq, y, x));
|
||||
}
|
||||
|
||||
private static boolean GT(PriorityQ.Leq leq, Object x, Object y) {
|
||||
return (!PriorityQHeap.LEQ(leq, x, y));
|
||||
}
|
||||
|
||||
private static void Swap(int[] array, int a, int b) {
|
||||
if (true) {
|
||||
int tmp = array[a];
|
||||
array[a] = array[b];
|
||||
array[b] = tmp;
|
||||
} else {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private static class Stack {
|
||||
int p, r;
|
||||
}
|
||||
|
||||
/* really __gl_pqSortInit */
|
||||
boolean pqInit() {
|
||||
int p, r, i, j;
|
||||
int piv;
|
||||
Stack[] stack = new Stack[50];
|
||||
for (int k = 0; k < stack.length; k++) {
|
||||
stack[k] = new Stack();
|
||||
}
|
||||
int top = 0;
|
||||
|
||||
int seed = 2016473283;
|
||||
|
||||
/* Create an array of indirect pointers to the keys, so that we
|
||||
* the handles we have returned are still valid.
|
||||
*/
|
||||
order = new int[size + 1];
|
||||
/* the previous line is a patch to compensate for the fact that IBM */
|
||||
/* machines return a null on a malloc of zero bytes (unlike SGI), */
|
||||
/* so we have to put in this defense to guard against a memory */
|
||||
/* fault four lines down. from fossum@austin.ibm.com. */
|
||||
p = 0;
|
||||
r = size - 1;
|
||||
for (piv = 0, i = p; i <= r; ++piv, ++i) {
|
||||
// indirect pointers: keep an index into the keys array, not a direct pointer to its contents
|
||||
order[i] = piv;
|
||||
}
|
||||
|
||||
/* Sort the indirect pointers in descending order,
|
||||
* using randomized Quicksort
|
||||
*/
|
||||
stack[top].p = p;
|
||||
stack[top].r = r;
|
||||
++top;
|
||||
while (--top >= 0) {
|
||||
p = stack[top].p;
|
||||
r = stack[top].r;
|
||||
while (r > p + 10) {
|
||||
seed = Math.abs( seed * 1539415821 + 1 );
|
||||
i = p + seed % (r - p + 1);
|
||||
piv = order[i];
|
||||
order[i] = order[p];
|
||||
order[p] = piv;
|
||||
i = p - 1;
|
||||
j = r + 1;
|
||||
do {
|
||||
do {
|
||||
++i;
|
||||
} while (GT(leq, keys[order[i]], keys[piv]));
|
||||
do {
|
||||
--j;
|
||||
} while (LT(leq, keys[order[j]], keys[piv]));
|
||||
Swap(order, i, j);
|
||||
} while (i < j);
|
||||
Swap(order, i, j); /* Undo last swap */
|
||||
if (i - p < r - j) {
|
||||
stack[top].p = j + 1;
|
||||
stack[top].r = r;
|
||||
++top;
|
||||
r = i - 1;
|
||||
} else {
|
||||
stack[top].p = p;
|
||||
stack[top].r = i - 1;
|
||||
++top;
|
||||
p = j + 1;
|
||||
}
|
||||
}
|
||||
/* Insertion sort small lists */
|
||||
for (i = p + 1; i <= r; ++i) {
|
||||
piv = order[i];
|
||||
for (j = i; j > p && LT(leq, keys[order[j - 1]], keys[piv]); --j) {
|
||||
order[j] = order[j - 1];
|
||||
}
|
||||
order[j] = piv;
|
||||
}
|
||||
}
|
||||
max = size;
|
||||
initialized = true;
|
||||
heap.pqInit(); /* always succeeds */
|
||||
|
||||
/* #ifndef NDEBUG
|
||||
p = order;
|
||||
r = p + size - 1;
|
||||
for (i = p; i < r; ++i) {
|
||||
Assertion.doAssert(LEQ( * * (i + 1), **i ));
|
||||
}
|
||||
#endif*/
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/* really __gl_pqSortInsert */
|
||||
/* returns LONG_MAX iff out of memory */
|
||||
int pqInsert(Object keyNew) {
|
||||
int curr;
|
||||
|
||||
if (initialized) {
|
||||
return heap.pqInsert(keyNew);
|
||||
}
|
||||
curr = size;
|
||||
if (++size >= max) {
|
||||
Object[] saveKey = keys;
|
||||
|
||||
/* If the heap overflows, double its size. */
|
||||
max <<= 1;
|
||||
// pq->keys = (PQHeapKey *)memRealloc( pq->keys,(size_t)(pq->max * sizeof( pq->keys[0] )));
|
||||
Object[] pqKeys = new Object[max];
|
||||
System.arraycopy( keys, 0, pqKeys, 0, keys.length );
|
||||
keys = pqKeys;
|
||||
if (keys == null) {
|
||||
keys = saveKey; /* restore ptr to free upon return */
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
}
|
||||
assert curr != Integer.MAX_VALUE;
|
||||
keys[curr] = keyNew;
|
||||
|
||||
/* Negative handles index the sorted array. */
|
||||
return -(curr + 1);
|
||||
}
|
||||
|
||||
/* really __gl_pqSortExtractMin */
|
||||
Object pqExtractMin() {
|
||||
Object sortMin, heapMin;
|
||||
|
||||
if (size == 0) {
|
||||
return heap.pqExtractMin();
|
||||
}
|
||||
sortMin = keys[order[size - 1]];
|
||||
if (!heap.pqIsEmpty()) {
|
||||
heapMin = heap.pqMinimum();
|
||||
if (LEQ(leq, heapMin, sortMin)) {
|
||||
return heap.pqExtractMin();
|
||||
}
|
||||
}
|
||||
do {
|
||||
--size;
|
||||
} while (size > 0 && keys[order[size - 1]] == null);
|
||||
return sortMin;
|
||||
}
|
||||
|
||||
/* really __gl_pqSortMinimum */
|
||||
Object pqMinimum() {
|
||||
Object sortMin, heapMin;
|
||||
|
||||
if (size == 0) {
|
||||
return heap.pqMinimum();
|
||||
}
|
||||
sortMin = keys[order[size - 1]];
|
||||
if (!heap.pqIsEmpty()) {
|
||||
heapMin = heap.pqMinimum();
|
||||
if (PriorityQHeap.LEQ(leq, heapMin, sortMin)) {
|
||||
return heapMin;
|
||||
}
|
||||
}
|
||||
return sortMin;
|
||||
}
|
||||
|
||||
/* really __gl_pqSortIsEmpty */
|
||||
boolean pqIsEmpty() {
|
||||
return (size == 0) && heap.pqIsEmpty();
|
||||
}
|
||||
|
||||
/* really __gl_pqSortDelete */
|
||||
void pqDelete(int curr) {
|
||||
if (curr >= 0) {
|
||||
heap.pqDelete(curr);
|
||||
return;
|
||||
}
|
||||
curr = -(curr + 1);
|
||||
assert curr < max && keys[curr] != null;
|
||||
|
||||
keys[curr] = null;
|
||||
while (size > 0 && keys[order[size - 1]] == null) {
|
||||
--size;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,589 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2008 LWJGL Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * 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.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "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 THE COPYRIGHT OWNER 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Portions Copyright (C) 2003-2006 Sun Microsystems, Inc.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/*
|
||||
** License Applicability. Except to the extent portions of this file are
|
||||
** made subject to an alternative license as permitted in the SGI Free
|
||||
** Software License B, Version 1.1 (the "License"), the contents of this
|
||||
** file are subject only to the provisions of the License. You may not use
|
||||
** this file except in compliance with the License. You may obtain a copy
|
||||
** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
|
||||
** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
|
||||
**
|
||||
** http://oss.sgi.com/projects/FreeB
|
||||
**
|
||||
** Note that, as provided in the License, the Software is distributed on an
|
||||
** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
|
||||
** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
|
||||
** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
|
||||
** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
|
||||
**
|
||||
** NOTE: The Original Code (as defined below) has been licensed to Sun
|
||||
** Microsystems, Inc. ("Sun") under the SGI Free Software License B
|
||||
** (Version 1.1), shown above ("SGI License"). Pursuant to Section
|
||||
** 3.2(3) of the SGI License, Sun is distributing the Covered Code to
|
||||
** you under an alternative license ("Alternative License"). This
|
||||
** Alternative License includes all of the provisions of the SGI License
|
||||
** except that Section 2.2 and 11 are omitted. Any differences between
|
||||
** the Alternative License and the SGI License are offered solely by Sun
|
||||
** and not by SGI.
|
||||
**
|
||||
** Original Code. The Original Code is: OpenGL Sample Implementation,
|
||||
** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
|
||||
** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
|
||||
** Copyright in any portions created by third parties is as indicated
|
||||
** elsewhere herein. All Rights Reserved.
|
||||
**
|
||||
** Additional Notice Provisions: The application programming interfaces
|
||||
** established by SGI in conjunction with the Original Code are The
|
||||
** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
|
||||
** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
|
||||
** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
|
||||
** Window System(R) (Version 1.3), released October 19, 1998. This software
|
||||
** was created using the OpenGL(R) version 1.2.1 Sample Implementation
|
||||
** published by SGI, but has not been independently verified as being
|
||||
** compliant with the OpenGL(R) version 1.2.1 Specification.
|
||||
**
|
||||
** Author: Eric Veach, July 1994
|
||||
** Java Port: Pepijn Van Eeckhoudt, July 2003
|
||||
** Java Port: Nathan Parker Burg, August 2003
|
||||
*/
|
||||
package org.lwjgl.util.glu.tessellation;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.util.glu.GLU;
|
||||
|
||||
class Render {
|
||||
private static final boolean USE_OPTIMIZED_CODE_PATH = false;
|
||||
|
||||
private Render() {
|
||||
}
|
||||
|
||||
private static final RenderFan renderFan = new RenderFan();
|
||||
private static final RenderStrip renderStrip = new RenderStrip();
|
||||
private static final RenderTriangle renderTriangle = new RenderTriangle();
|
||||
|
||||
/* This structure remembers the information we need about a primitive
|
||||
* to be able to render it later, once we have determined which
|
||||
* primitive is able to use the most triangles.
|
||||
*/
|
||||
private static class FaceCount {
|
||||
public FaceCount() {
|
||||
}
|
||||
|
||||
public FaceCount(long size, GLUhalfEdge eStart, renderCallBack render) {
|
||||
this.size = size;
|
||||
this.eStart = eStart;
|
||||
this.render = render;
|
||||
}
|
||||
|
||||
long size; /* number of triangles used */
|
||||
GLUhalfEdge eStart; /* edge where this primitive starts */
|
||||
renderCallBack render;
|
||||
};
|
||||
|
||||
private static interface renderCallBack {
|
||||
void render(GLUtessellatorImpl tess, GLUhalfEdge e, long size);
|
||||
}
|
||||
|
||||
/************************ Strips and Fans decomposition ******************/
|
||||
|
||||
/* __gl_renderMesh( tess, mesh ) takes a mesh and breaks it into triangle
|
||||
* fans, strips, and separate triangles. A substantial effort is made
|
||||
* to use as few rendering primitives as possible (ie. to make the fans
|
||||
* and strips as large as possible).
|
||||
*
|
||||
* The rendering output is provided as callbacks (see the api).
|
||||
*/
|
||||
public static void __gl_renderMesh(GLUtessellatorImpl tess, GLUmesh mesh) {
|
||||
GLUface f;
|
||||
|
||||
/* Make a list of separate triangles so we can render them all at once */
|
||||
tess.lonelyTriList = null;
|
||||
|
||||
for (f = mesh.fHead.next; f != mesh.fHead; f = f.next) {
|
||||
f.marked = false;
|
||||
}
|
||||
for (f = mesh.fHead.next; f != mesh.fHead; f = f.next) {
|
||||
|
||||
/* We examine all faces in an arbitrary order. Whenever we find
|
||||
* an unprocessed face F, we output a group of faces including F
|
||||
* whose size is maximum.
|
||||
*/
|
||||
if (f.inside && !f.marked) {
|
||||
RenderMaximumFaceGroup(tess, f);
|
||||
assert (f.marked);
|
||||
}
|
||||
}
|
||||
if (tess.lonelyTriList != null) {
|
||||
RenderLonelyTriangles(tess, tess.lonelyTriList);
|
||||
tess.lonelyTriList = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void RenderMaximumFaceGroup(GLUtessellatorImpl tess, GLUface fOrig) {
|
||||
/* We want to find the largest triangle fan or strip of unmarked faces
|
||||
* which includes the given face fOrig. There are 3 possible fans
|
||||
* passing through fOrig (one centered at each vertex), and 3 possible
|
||||
* strips (one for each CCW permutation of the vertices). Our strategy
|
||||
* is to try all of these, and take the primitive which uses the most
|
||||
* triangles (a greedy approach).
|
||||
*/
|
||||
GLUhalfEdge e = fOrig.anEdge;
|
||||
FaceCount max = new FaceCount();
|
||||
FaceCount newFace = new FaceCount();
|
||||
|
||||
max.size = 1;
|
||||
max.eStart = e;
|
||||
max.render = renderTriangle;
|
||||
|
||||
if (!tess.flagBoundary) {
|
||||
newFace = MaximumFan(e);
|
||||
if (newFace.size > max.size) {
|
||||
max = newFace;
|
||||
}
|
||||
newFace = MaximumFan(e.Lnext);
|
||||
if (newFace.size > max.size) {
|
||||
max = newFace;
|
||||
}
|
||||
newFace = MaximumFan(e.Onext.Sym);
|
||||
if (newFace.size > max.size) {
|
||||
max = newFace;
|
||||
}
|
||||
|
||||
newFace = MaximumStrip(e);
|
||||
if (newFace.size > max.size) {
|
||||
max = newFace;
|
||||
}
|
||||
newFace = MaximumStrip(e.Lnext);
|
||||
if (newFace.size > max.size) {
|
||||
max = newFace;
|
||||
}
|
||||
newFace = MaximumStrip(e.Onext.Sym);
|
||||
if (newFace.size > max.size) {
|
||||
max = newFace;
|
||||
}
|
||||
}
|
||||
max.render.render(tess, max.eStart, max.size);
|
||||
}
|
||||
|
||||
|
||||
/* Macros which keep track of faces we have marked temporarily, and allow
|
||||
* us to backtrack when necessary. With triangle fans, this is not
|
||||
* really necessary, since the only awkward case is a loop of triangles
|
||||
* around a single origin vertex. However with strips the situation is
|
||||
* more complicated, and we need a general tracking method like the
|
||||
* one here.
|
||||
*/
|
||||
private static boolean Marked(GLUface f) {
|
||||
return !f.inside || f.marked;
|
||||
}
|
||||
|
||||
private static GLUface AddToTrail(GLUface f, GLUface t) {
|
||||
f.trail = t;
|
||||
f.marked = true;
|
||||
return f;
|
||||
}
|
||||
|
||||
private static void FreeTrail(GLUface t) {
|
||||
if (true) {
|
||||
while (t != null) {
|
||||
t.marked = false;
|
||||
t = t.trail;
|
||||
}
|
||||
} else {
|
||||
/* absorb trailing semicolon */
|
||||
}
|
||||
}
|
||||
|
||||
static FaceCount MaximumFan(GLUhalfEdge eOrig) {
|
||||
/* eOrig.Lface is the face we want to render. We want to find the size
|
||||
* of a maximal fan around eOrig.Org. To do this we just walk around
|
||||
* the origin vertex as far as possible in both directions.
|
||||
*/
|
||||
FaceCount newFace = new FaceCount(0, null, renderFan);
|
||||
GLUface trail = null;
|
||||
GLUhalfEdge e;
|
||||
|
||||
for (e = eOrig; !Marked(e.Lface); e = e.Onext) {
|
||||
trail = AddToTrail(e.Lface, trail);
|
||||
++newFace.size;
|
||||
}
|
||||
for (e = eOrig; !Marked(e.Sym.Lface); e = e.Sym.Lnext) {
|
||||
trail = AddToTrail(e.Sym.Lface, trail);
|
||||
++newFace.size;
|
||||
}
|
||||
newFace.eStart = e;
|
||||
/*LINTED*/
|
||||
FreeTrail(trail);
|
||||
return newFace;
|
||||
}
|
||||
|
||||
|
||||
private static boolean IsEven(long n) {
|
||||
return (n & 0x1L) == 0;
|
||||
}
|
||||
|
||||
static FaceCount MaximumStrip(GLUhalfEdge eOrig) {
|
||||
/* Here we are looking for a maximal strip that contains the vertices
|
||||
* eOrig.Org, eOrig.Dst, eOrig.Lnext.Dst (in that order or the
|
||||
* reverse, such that all triangles are oriented CCW).
|
||||
*
|
||||
* Again we walk forward and backward as far as possible. However for
|
||||
* strips there is a twist: to get CCW orientations, there must be
|
||||
* an *even* number of triangles in the strip on one side of eOrig.
|
||||
* We walk the strip starting on a side with an even number of triangles;
|
||||
* if both side have an odd number, we are forced to shorten one side.
|
||||
*/
|
||||
FaceCount newFace = new FaceCount(0, null, renderStrip);
|
||||
long headSize = 0, tailSize = 0;
|
||||
GLUface trail = null;
|
||||
GLUhalfEdge e, eTail, eHead;
|
||||
|
||||
for (e = eOrig; !Marked(e.Lface); ++tailSize, e = e.Onext) {
|
||||
trail = AddToTrail(e.Lface, trail);
|
||||
++tailSize;
|
||||
e = e.Lnext.Sym;
|
||||
if (Marked(e.Lface)) break;
|
||||
trail = AddToTrail(e.Lface, trail);
|
||||
}
|
||||
eTail = e;
|
||||
|
||||
for (e = eOrig; !Marked(e.Sym.Lface); ++headSize, e = e.Sym.Onext.Sym) {
|
||||
trail = AddToTrail(e.Sym.Lface, trail);
|
||||
++headSize;
|
||||
e = e.Sym.Lnext;
|
||||
if (Marked(e.Sym.Lface)) break;
|
||||
trail = AddToTrail(e.Sym.Lface, trail);
|
||||
}
|
||||
eHead = e;
|
||||
|
||||
newFace.size = tailSize + headSize;
|
||||
if (IsEven(tailSize)) {
|
||||
newFace.eStart = eTail.Sym;
|
||||
} else if (IsEven(headSize)) {
|
||||
newFace.eStart = eHead;
|
||||
} else {
|
||||
/* Both sides have odd length, we must shorten one of them. In fact,
|
||||
* we must start from eHead to guarantee inclusion of eOrig.Lface.
|
||||
*/
|
||||
--newFace.size;
|
||||
newFace.eStart = eHead.Onext;
|
||||
}
|
||||
/*LINTED*/
|
||||
FreeTrail(trail);
|
||||
return newFace;
|
||||
}
|
||||
|
||||
private static class RenderTriangle implements renderCallBack {
|
||||
public void render(GLUtessellatorImpl tess, GLUhalfEdge e, long size) {
|
||||
/* Just add the triangle to a triangle list, so we can render all
|
||||
* the separate triangles at once.
|
||||
*/
|
||||
assert (size == 1);
|
||||
tess.lonelyTriList = AddToTrail(e.Lface, tess.lonelyTriList);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void RenderLonelyTriangles(GLUtessellatorImpl tess, GLUface f) {
|
||||
/* Now we render all the separate triangles which could not be
|
||||
* grouped into a triangle fan or strip.
|
||||
*/
|
||||
GLUhalfEdge e;
|
||||
int newState;
|
||||
int edgeState = -1; /* force edge state output for first vertex */
|
||||
|
||||
tess.callBeginOrBeginData(GL11.GL_TRIANGLES);
|
||||
|
||||
for (; f != null; f = f.trail) {
|
||||
/* Loop once for each edge (there will always be 3 edges) */
|
||||
|
||||
e = f.anEdge;
|
||||
do {
|
||||
if (tess.flagBoundary) {
|
||||
/* Set the "edge state" to true just before we output the
|
||||
* first vertex of each edge on the polygon boundary.
|
||||
*/
|
||||
newState = (!e.Sym.Lface.inside) ? 1 : 0;
|
||||
if (edgeState != newState) {
|
||||
edgeState = newState;
|
||||
tess.callEdgeFlagOrEdgeFlagData( edgeState != 0);
|
||||
}
|
||||
}
|
||||
tess.callVertexOrVertexData( e.Org.data);
|
||||
|
||||
e = e.Lnext;
|
||||
} while (e != f.anEdge);
|
||||
}
|
||||
tess.callEndOrEndData();
|
||||
}
|
||||
|
||||
private static class RenderFan implements renderCallBack {
|
||||
public void render(GLUtessellatorImpl tess, GLUhalfEdge e, long size) {
|
||||
/* Render as many CCW triangles as possible in a fan starting from
|
||||
* edge "e". The fan *should* contain exactly "size" triangles
|
||||
* (otherwise we've goofed up somewhere).
|
||||
*/
|
||||
tess.callBeginOrBeginData(GL11.GL_TRIANGLE_FAN);
|
||||
tess.callVertexOrVertexData( e.Org.data);
|
||||
tess.callVertexOrVertexData( e.Sym.Org.data);
|
||||
|
||||
while (!Marked(e.Lface)) {
|
||||
e.Lface.marked = true;
|
||||
--size;
|
||||
e = e.Onext;
|
||||
tess.callVertexOrVertexData( e.Sym.Org.data);
|
||||
}
|
||||
|
||||
assert (size == 0);
|
||||
tess.callEndOrEndData();
|
||||
}
|
||||
}
|
||||
|
||||
private static class RenderStrip implements renderCallBack {
|
||||
public void render(GLUtessellatorImpl tess, GLUhalfEdge e, long size) {
|
||||
/* Render as many CCW triangles as possible in a strip starting from
|
||||
* edge "e". The strip *should* contain exactly "size" triangles
|
||||
* (otherwise we've goofed up somewhere).
|
||||
*/
|
||||
tess.callBeginOrBeginData(GL11.GL_TRIANGLE_STRIP);
|
||||
tess.callVertexOrVertexData( e.Org.data);
|
||||
tess.callVertexOrVertexData( e.Sym.Org.data);
|
||||
|
||||
while (!Marked(e.Lface)) {
|
||||
e.Lface.marked = true;
|
||||
--size;
|
||||
e = e.Lnext.Sym;
|
||||
tess.callVertexOrVertexData( e.Org.data);
|
||||
if (Marked(e.Lface)) break;
|
||||
|
||||
e.Lface.marked = true;
|
||||
--size;
|
||||
e = e.Onext;
|
||||
tess.callVertexOrVertexData( e.Sym.Org.data);
|
||||
}
|
||||
|
||||
assert (size == 0);
|
||||
tess.callEndOrEndData();
|
||||
}
|
||||
}
|
||||
|
||||
/************************ Boundary contour decomposition ******************/
|
||||
|
||||
/* __gl_renderBoundary( tess, mesh ) takes a mesh, and outputs one
|
||||
* contour for each face marked "inside". The rendering output is
|
||||
* provided as callbacks (see the api).
|
||||
*/
|
||||
public static void __gl_renderBoundary(GLUtessellatorImpl tess, GLUmesh mesh) {
|
||||
GLUface f;
|
||||
GLUhalfEdge e;
|
||||
|
||||
for (f = mesh.fHead.next; f != mesh.fHead; f = f.next) {
|
||||
if (f.inside) {
|
||||
tess.callBeginOrBeginData(GL11.GL_LINE_LOOP);
|
||||
e = f.anEdge;
|
||||
do {
|
||||
tess.callVertexOrVertexData( e.Org.data);
|
||||
e = e.Lnext;
|
||||
} while (e != f.anEdge);
|
||||
tess.callEndOrEndData();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/************************ Quick-and-dirty decomposition ******************/
|
||||
|
||||
private static final int SIGN_INCONSISTENT = 2;
|
||||
|
||||
static int ComputeNormal(GLUtessellatorImpl tess, double[] norm, boolean check)
|
||||
/*
|
||||
* If check==false, we compute the polygon normal and place it in norm[].
|
||||
* If check==true, we check that each triangle in the fan from v0 has a
|
||||
* consistent orientation with respect to norm[]. If triangles are
|
||||
* consistently oriented CCW, return 1; if CW, return -1; if all triangles
|
||||
* are degenerate return 0; otherwise (no consistent orientation) return
|
||||
* SIGN_INCONSISTENT.
|
||||
*/ {
|
||||
CachedVertex[] v = tess.cache;
|
||||
// CachedVertex vn = v0 + tess.cacheCount;
|
||||
int vn = tess.cacheCount;
|
||||
// CachedVertex vc;
|
||||
int vc;
|
||||
double dot, xc, yc, zc, xp, yp, zp;
|
||||
double[] n = new double[3];
|
||||
int sign = 0;
|
||||
|
||||
/* Find the polygon normal. It is important to get a reasonable
|
||||
* normal even when the polygon is self-intersecting (eg. a bowtie).
|
||||
* Otherwise, the computed normal could be very tiny, but perpendicular
|
||||
* to the true plane of the polygon due to numerical noise. Then all
|
||||
* the triangles would appear to be degenerate and we would incorrectly
|
||||
* decompose the polygon as a fan (or simply not render it at all).
|
||||
*
|
||||
* We use a sum-of-triangles normal algorithm rather than the more
|
||||
* efficient sum-of-trapezoids method (used in CheckOrientation()
|
||||
* in normal.c). This lets us explicitly reverse the signed area
|
||||
* of some triangles to get a reasonable normal in the self-intersecting
|
||||
* case.
|
||||
*/
|
||||
if (!check) {
|
||||
norm[0] = norm[1] = norm[2] = 0.0;
|
||||
}
|
||||
|
||||
vc = 1;
|
||||
xc = v[vc].coords[0] - v[0].coords[0];
|
||||
yc = v[vc].coords[1] - v[0].coords[1];
|
||||
zc = v[vc].coords[2] - v[0].coords[2];
|
||||
while (++vc < vn) {
|
||||
xp = xc;
|
||||
yp = yc;
|
||||
zp = zc;
|
||||
xc = v[vc].coords[0] - v[0].coords[0];
|
||||
yc = v[vc].coords[1] - v[0].coords[1];
|
||||
zc = v[vc].coords[2] - v[0].coords[2];
|
||||
|
||||
/* Compute (vp - v0) cross (vc - v0) */
|
||||
n[0] = yp * zc - zp * yc;
|
||||
n[1] = zp * xc - xp * zc;
|
||||
n[2] = xp * yc - yp * xc;
|
||||
|
||||
dot = n[0] * norm[0] + n[1] * norm[1] + n[2] * norm[2];
|
||||
if (!check) {
|
||||
/* Reverse the contribution of back-facing triangles to get
|
||||
* a reasonable normal for self-intersecting polygons (see above)
|
||||
*/
|
||||
if (dot >= 0) {
|
||||
norm[0] += n[0];
|
||||
norm[1] += n[1];
|
||||
norm[2] += n[2];
|
||||
} else {
|
||||
norm[0] -= n[0];
|
||||
norm[1] -= n[1];
|
||||
norm[2] -= n[2];
|
||||
}
|
||||
} else if (dot != 0) {
|
||||
/* Check the new orientation for consistency with previous triangles */
|
||||
if (dot > 0) {
|
||||
if (sign < 0) return SIGN_INCONSISTENT;
|
||||
sign = 1;
|
||||
} else {
|
||||
if (sign > 0) return SIGN_INCONSISTENT;
|
||||
sign = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return sign;
|
||||
}
|
||||
|
||||
/* __gl_renderCache( tess ) takes a single contour and tries to render it
|
||||
* as a triangle fan. This handles convex polygons, as well as some
|
||||
* non-convex polygons if we get lucky.
|
||||
*
|
||||
* Returns true if the polygon was successfully rendered. The rendering
|
||||
* output is provided as callbacks (see the api).
|
||||
*/
|
||||
public static boolean __gl_renderCache(GLUtessellatorImpl tess) {
|
||||
CachedVertex[] v = tess.cache;
|
||||
// CachedVertex vn = v0 + tess.cacheCount;
|
||||
int vn = tess.cacheCount;
|
||||
// CachedVertex vc;
|
||||
int vc;
|
||||
double[] norm = new double[3];
|
||||
int sign;
|
||||
|
||||
if (tess.cacheCount < 3) {
|
||||
/* Degenerate contour -- no output */
|
||||
return true;
|
||||
}
|
||||
|
||||
norm[0] = tess.normal[0];
|
||||
norm[1] = tess.normal[1];
|
||||
norm[2] = tess.normal[2];
|
||||
if (norm[0] == 0 && norm[1] == 0 && norm[2] == 0) {
|
||||
ComputeNormal( tess, norm, false);
|
||||
}
|
||||
|
||||
sign = ComputeNormal( tess, norm, true);
|
||||
if (sign == SIGN_INCONSISTENT) {
|
||||
/* Fan triangles did not have a consistent orientation */
|
||||
return false;
|
||||
}
|
||||
if (sign == 0) {
|
||||
/* All triangles were degenerate */
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( !USE_OPTIMIZED_CODE_PATH ) {
|
||||
return false;
|
||||
} else {
|
||||
/* Make sure we do the right thing for each winding rule */
|
||||
switch (tess.windingRule) {
|
||||
case GLU.GLU_TESS_WINDING_ODD:
|
||||
case GLU.GLU_TESS_WINDING_NONZERO:
|
||||
break;
|
||||
case GLU.GLU_TESS_WINDING_POSITIVE:
|
||||
if (sign < 0) return true;
|
||||
break;
|
||||
case GLU.GLU_TESS_WINDING_NEGATIVE:
|
||||
if (sign > 0) return true;
|
||||
break;
|
||||
case GLU.GLU_TESS_WINDING_ABS_GEQ_TWO:
|
||||
return true;
|
||||
}
|
||||
|
||||
tess.callBeginOrBeginData( tess.boundaryOnly ? GL11.GL_LINE_LOOP
|
||||
: (tess.cacheCount > 3) ? GL11.GL_TRIANGLE_FAN
|
||||
: GL11.GL_TRIANGLES);
|
||||
|
||||
tess.callVertexOrVertexData( v[0].data);
|
||||
if (sign > 0) {
|
||||
for (vc = 1; vc < vn; ++vc) {
|
||||
tess.callVertexOrVertexData( v[vc].data);
|
||||
}
|
||||
} else {
|
||||
for (vc = vn - 1; vc > 0; --vc) {
|
||||
tess.callVertexOrVertexData( v[vc].data);
|
||||
}
|
||||
}
|
||||
tess.callEndOrEndData();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,241 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2008 LWJGL Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * 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.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "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 THE COPYRIGHT OWNER 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Portions Copyright (C) 2003-2006 Sun Microsystems, Inc.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/*
|
||||
** License Applicability. Except to the extent portions of this file are
|
||||
** made subject to an alternative license as permitted in the SGI Free
|
||||
** Software License B, Version 1.1 (the "License"), the contents of this
|
||||
** file are subject only to the provisions of the License. You may not use
|
||||
** this file except in compliance with the License. You may obtain a copy
|
||||
** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
|
||||
** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
|
||||
**
|
||||
** http://oss.sgi.com/projects/FreeB
|
||||
**
|
||||
** Note that, as provided in the License, the Software is distributed on an
|
||||
** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
|
||||
** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
|
||||
** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
|
||||
** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
|
||||
**
|
||||
** NOTE: The Original Code (as defined below) has been licensed to Sun
|
||||
** Microsystems, Inc. ("Sun") under the SGI Free Software License B
|
||||
** (Version 1.1), shown above ("SGI License"). Pursuant to Section
|
||||
** 3.2(3) of the SGI License, Sun is distributing the Covered Code to
|
||||
** you under an alternative license ("Alternative License"). This
|
||||
** Alternative License includes all of the provisions of the SGI License
|
||||
** except that Section 2.2 and 11 are omitted. Any differences between
|
||||
** the Alternative License and the SGI License are offered solely by Sun
|
||||
** and not by SGI.
|
||||
**
|
||||
** Original Code. The Original Code is: OpenGL Sample Implementation,
|
||||
** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
|
||||
** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
|
||||
** Copyright in any portions created by third parties is as indicated
|
||||
** elsewhere herein. All Rights Reserved.
|
||||
**
|
||||
** Additional Notice Provisions: The application programming interfaces
|
||||
** established by SGI in conjunction with the Original Code are The
|
||||
** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
|
||||
** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
|
||||
** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
|
||||
** Window System(R) (Version 1.3), released October 19, 1998. This software
|
||||
** was created using the OpenGL(R) version 1.2.1 Sample Implementation
|
||||
** published by SGI, but has not been independently verified as being
|
||||
** compliant with the OpenGL(R) version 1.2.1 Specification.
|
||||
**
|
||||
** Author: Eric Veach, July 1994
|
||||
** Java Port: Pepijn Van Eeckhoudt, July 2003
|
||||
** Java Port: Nathan Parker Burg, August 2003
|
||||
*/
|
||||
package org.lwjgl.util.glu.tessellation;
|
||||
|
||||
class TessMono {
|
||||
/* __gl_meshTessellateMonoRegion( face ) tessellates a monotone region
|
||||
* (what else would it do??) The region must consist of a single
|
||||
* loop of half-edges (see mesh.h) oriented CCW. "Monotone" in this
|
||||
* case means that any vertical line intersects the interior of the
|
||||
* region in a single interval.
|
||||
*
|
||||
* Tessellation consists of adding interior edges (actually pairs of
|
||||
* half-edges), to split the region into non-overlapping triangles.
|
||||
*
|
||||
* The basic idea is explained in Preparata and Shamos (which I don''t
|
||||
* have handy right now), although their implementation is more
|
||||
* complicated than this one. The are two edge chains, an upper chain
|
||||
* and a lower chain. We process all vertices from both chains in order,
|
||||
* from right to left.
|
||||
*
|
||||
* The algorithm ensures that the following invariant holds after each
|
||||
* vertex is processed: the untessellated region consists of two
|
||||
* chains, where one chain (say the upper) is a single edge, and
|
||||
* the other chain is concave. The left vertex of the single edge
|
||||
* is always to the left of all vertices in the concave chain.
|
||||
*
|
||||
* Each step consists of adding the rightmost unprocessed vertex to one
|
||||
* of the two chains, and forming a fan of triangles from the rightmost
|
||||
* of two chain endpoints. Determining whether we can add each triangle
|
||||
* to the fan is a simple orientation test. By making the fan as large
|
||||
* as possible, we restore the invariant (check it yourself).
|
||||
*/
|
||||
static boolean __gl_meshTessellateMonoRegion(GLUface face) {
|
||||
GLUhalfEdge up, lo;
|
||||
|
||||
/* All edges are oriented CCW around the boundary of the region.
|
||||
* First, find the half-edge whose origin vertex is rightmost.
|
||||
* Since the sweep goes from left to right, face->anEdge should
|
||||
* be close to the edge we want.
|
||||
*/
|
||||
up = face.anEdge;
|
||||
assert (up.Lnext != up && up.Lnext.Lnext != up);
|
||||
|
||||
for (; Geom.VertLeq(up.Sym.Org, up.Org); up = up.Onext.Sym)
|
||||
;
|
||||
for (; Geom.VertLeq(up.Org, up.Sym.Org); up = up.Lnext)
|
||||
;
|
||||
lo = up.Onext.Sym;
|
||||
|
||||
while (up.Lnext != lo) {
|
||||
if (Geom.VertLeq(up.Sym.Org, lo.Org)) {
|
||||
/* up.Sym.Org is on the left. It is safe to form triangles from lo.Org.
|
||||
* The EdgeGoesLeft test guarantees progress even when some triangles
|
||||
* are CW, given that the upper and lower chains are truly monotone.
|
||||
*/
|
||||
while (lo.Lnext != up && (Geom.EdgeGoesLeft(lo.Lnext)
|
||||
|| Geom.EdgeSign(lo.Org, lo.Sym.Org, lo.Lnext.Sym.Org) <= 0)) {
|
||||
GLUhalfEdge tempHalfEdge = Mesh.__gl_meshConnect(lo.Lnext, lo);
|
||||
if (tempHalfEdge == null) return false;
|
||||
lo = tempHalfEdge.Sym;
|
||||
}
|
||||
lo = lo.Onext.Sym;
|
||||
} else {
|
||||
/* lo.Org is on the left. We can make CCW triangles from up.Sym.Org. */
|
||||
while (lo.Lnext != up && (Geom.EdgeGoesRight(up.Onext.Sym)
|
||||
|| Geom.EdgeSign(up.Sym.Org, up.Org, up.Onext.Sym.Org) >= 0)) {
|
||||
GLUhalfEdge tempHalfEdge = Mesh.__gl_meshConnect(up, up.Onext.Sym);
|
||||
if (tempHalfEdge == null) return false;
|
||||
up = tempHalfEdge.Sym;
|
||||
}
|
||||
up = up.Lnext;
|
||||
}
|
||||
}
|
||||
|
||||
/* Now lo.Org == up.Sym.Org == the leftmost vertex. The remaining region
|
||||
* can be tessellated in a fan from this leftmost vertex.
|
||||
*/
|
||||
assert (lo.Lnext != up);
|
||||
while (lo.Lnext.Lnext != up) {
|
||||
GLUhalfEdge tempHalfEdge = Mesh.__gl_meshConnect(lo.Lnext, lo);
|
||||
if (tempHalfEdge == null) return false;
|
||||
lo = tempHalfEdge.Sym;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/* __gl_meshTessellateInterior( mesh ) tessellates each region of
|
||||
* the mesh which is marked "inside" the polygon. Each such region
|
||||
* must be monotone.
|
||||
*/
|
||||
public static boolean __gl_meshTessellateInterior(GLUmesh mesh) {
|
||||
GLUface f, next;
|
||||
|
||||
/*LINTED*/
|
||||
for (f = mesh.fHead.next; f != mesh.fHead; f = next) {
|
||||
/* Make sure we don''t try to tessellate the new triangles. */
|
||||
next = f.next;
|
||||
if (f.inside) {
|
||||
if (!__gl_meshTessellateMonoRegion(f)) return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/* __gl_meshDiscardExterior( mesh ) zaps (ie. sets to NULL) all faces
|
||||
* which are not marked "inside" the polygon. Since further mesh operations
|
||||
* on NULL faces are not allowed, the main purpose is to clean up the
|
||||
* mesh so that exterior loops are not represented in the data structure.
|
||||
*/
|
||||
public static void __gl_meshDiscardExterior(GLUmesh mesh) {
|
||||
GLUface f, next;
|
||||
|
||||
/*LINTED*/
|
||||
for (f = mesh.fHead.next; f != mesh.fHead; f = next) {
|
||||
/* Since f will be destroyed, save its next pointer. */
|
||||
next = f.next;
|
||||
if (!f.inside) {
|
||||
Mesh.__gl_meshZapFace(f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// private static final int MARKED_FOR_DELETION = 0x7fffffff;
|
||||
|
||||
/* __gl_meshSetWindingNumber( mesh, value, keepOnlyBoundary ) resets the
|
||||
* winding numbers on all edges so that regions marked "inside" the
|
||||
* polygon have a winding number of "value", and regions outside
|
||||
* have a winding number of 0.
|
||||
*
|
||||
* If keepOnlyBoundary is TRUE, it also deletes all edges which do not
|
||||
* separate an interior region from an exterior one.
|
||||
*/
|
||||
public static boolean __gl_meshSetWindingNumber(GLUmesh mesh, int value, boolean keepOnlyBoundary) {
|
||||
GLUhalfEdge e, eNext;
|
||||
|
||||
for (e = mesh.eHead.next; e != mesh.eHead; e = eNext) {
|
||||
eNext = e.next;
|
||||
if (e.Sym.Lface.inside != e.Lface.inside) {
|
||||
|
||||
/* This is a boundary edge (one side is interior, one is exterior). */
|
||||
e.winding = (e.Lface.inside) ? value : -value;
|
||||
} else {
|
||||
|
||||
/* Both regions are interior, or both are exterior. */
|
||||
if (!keepOnlyBoundary) {
|
||||
e.winding = 0;
|
||||
} else {
|
||||
if (!Mesh.__gl_meshDelete(e)) return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,91 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2008 LWJGL Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * 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.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "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 THE COPYRIGHT OWNER 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Portions Copyright (C) 2003-2006 Sun Microsystems, Inc.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/*
|
||||
** License Applicability. Except to the extent portions of this file are
|
||||
** made subject to an alternative license as permitted in the SGI Free
|
||||
** Software License B, Version 1.1 (the "License"), the contents of this
|
||||
** file are subject only to the provisions of the License. You may not use
|
||||
** this file except in compliance with the License. You may obtain a copy
|
||||
** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
|
||||
** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
|
||||
**
|
||||
** http://oss.sgi.com/projects/FreeB
|
||||
**
|
||||
** Note that, as provided in the License, the Software is distributed on an
|
||||
** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
|
||||
** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
|
||||
** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
|
||||
** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
|
||||
**
|
||||
** NOTE: The Original Code (as defined below) has been licensed to Sun
|
||||
** Microsystems, Inc. ("Sun") under the SGI Free Software License B
|
||||
** (Version 1.1), shown above ("SGI License"). Pursuant to Section
|
||||
** 3.2(3) of the SGI License, Sun is distributing the Covered Code to
|
||||
** you under an alternative license ("Alternative License"). This
|
||||
** Alternative License includes all of the provisions of the SGI License
|
||||
** except that Section 2.2 and 11 are omitted. Any differences between
|
||||
** the Alternative License and the SGI License are offered solely by Sun
|
||||
** and not by SGI.
|
||||
**
|
||||
** Original Code. The Original Code is: OpenGL Sample Implementation,
|
||||
** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
|
||||
** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
|
||||
** Copyright in any portions created by third parties is as indicated
|
||||
** elsewhere herein. All Rights Reserved.
|
||||
**
|
||||
** Additional Notice Provisions: The application programming interfaces
|
||||
** established by SGI in conjunction with the Original Code are The
|
||||
** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
|
||||
** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
|
||||
** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
|
||||
** Window System(R) (Version 1.3), released October 19, 1998. This software
|
||||
** was created using the OpenGL(R) version 1.2.1 Sample Implementation
|
||||
** published by SGI, but has not been independently verified as being
|
||||
** compliant with the OpenGL(R) version 1.2.1 Specification.
|
||||
**
|
||||
** Author: Eric Veach, July 1994
|
||||
** Java Port: Pepijn Van Eeckhoudt, July 2003
|
||||
** Java Port: Nathan Parker Burg, August 2003
|
||||
*/
|
||||
package org.lwjgl.util.glu.tessellation;
|
||||
|
||||
class TessState {
|
||||
public static final int T_DORMANT = 0;
|
||||
public static final int T_IN_POLYGON = 1;
|
||||
public static final int T_IN_CONTOUR = 2;
|
||||
}
|
Loading…
Reference in New Issue