[Bprocessor-commit] gl/src/net/sourceforge/bprocessor/gl/view AbstractView.java,1.13,1.14
Status: Pre-Alpha
Brought to you by:
henryml
From: Nordholt <nor...@us...> - 2005-08-30 13:06:02
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/view In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5456 Modified Files: AbstractView.java Log Message: Added tesselation of surfaces to allow concave surfaces and holes Index: AbstractView.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/view/AbstractView.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** AbstractView.java 30 Aug 2005 08:22:35 -0000 1.13 --- AbstractView.java 30 Aug 2005 13:05:54 -0000 1.14 *************** *** 28,31 **** --- 28,34 ---- import net.java.games.jogl.GLU; import net.java.games.jogl.util.BufferUtils; + import net.java.games.jogl.GLUtesselatorCallbackAdapter; + import net.java.games.jogl.GLUtesselatorCallback; + import net.java.games.jogl.GLUtesselator; import org.apache.log4j.Logger; *************** *** 449,453 **** List l = s.getEdges(); if (l != null) { ! gl.glBegin(GL.GL_POLYGON); if (drawMode == LIGHTING_MODE) { Vertex norm = s.normal(); --- 452,470 ---- List l = s.getEdges(); if (l != null) { ! //Setting up tessellation ! GLUtesselator tess = glu.gluNewTess(); ! GLUtesselatorCallback cb = new Callback(); ! ! //Setting callbacks ! glu.gluTessCallback(tess, GLU.GLU_TESS_BEGIN, cb); ! glu.gluTessCallback(tess, GLU.GLU_TESS_END, cb); ! glu.gluTessCallback(tess, GLU.GLU_TESS_VERTEX, cb); ! ! //Contours contained in an even number of contours are filled ! glu.gluTessProperty(tess, GLU.GLU_TESS_WINDING_RULE, GLU.GLU_TESS_WINDING_ODD); ! ! //begining the polygon, we are not using userdata for now (hence the null) ! glu.gluTessBeginPolygon(tess, null); ! //light stuff if (drawMode == LIGHTING_MODE) { Vertex norm = s.normal(); *************** *** 455,494 **** gl.glNormal3d(norm.getX(), norm.getY(), norm.getZ()); } ! Vertex previous = null; ! Edge previousEdge = null; ! for (int i = 0; i < l.size(); i++) { ! Edge e = (Edge)l.get(i); ! if (previous == null) { ! previous = e.getTo(); ! // will be drawn with the secound vertex as to find out if it is to or from that counts } else { ! Vertex temp = e.otherVertex(previous); ! if (temp != null) { ! gl.glVertex3d(previous.getX(), previous.getY(), previous.getZ()); ! previous = temp; ! if (i == l.size() - 1) { ! gl.glVertex3d(previous.getX(), previous.getY(), previous.getZ()); ! } ! } else { ! temp = previousEdge.otherVertex(previous); ! gl.glVertex3d(temp.getX(), temp.getY(), temp.getZ()); ! previous = e.otherVertex(temp); ! if (i == l.size() - 1) { ! if (previous == null) { ! log.warn("[drawSurface] could not find vertex " + temp + " on " + e); ! } else { ! gl.glVertex3d(previous.getX(), previous.getY(), previous.getZ()); ! } } } } - previousEdge = e; } ! gl.glEnd(); } ! //gl.glDisable(GL.GL_POLYGON_STIPPLE); ! //gl.glEnable(GL.GL_DEPTH_TEST); } ! /** * Draw an Edge --- 472,548 ---- gl.glNormal3d(norm.getX(), norm.getY(), norm.getZ()); } ! //drawing the outer contour ! drawContour(l, tess); ! ! //drawing the inner conturs ! Set innerSurfaces = s.getInnerSurfaces(); ! if (innerSurfaces != null) { ! Iterator innerIt = innerSurfaces.iterator(); ! while (innerIt.hasNext()) { ! Surface surface = (Surface)innerIt.next(); ! List innerEdges = surface.getEdges(); ! if (innerEdges != null) { ! drawContour(innerEdges, tess); ! } ! } ! } ! ! glu.gluTessEndPolygon(tess); ! glu.gluDeleteTess(tess); ! } ! } ! ! /** ! * Draws contours of a surface using the tessellator. ! * @param edges a non-null list of edges describing the contour ! * @param tess the tessellator object ! */ ! private void drawContour(List edges, GLUtesselator tess) { ! //beginning the contour. ! glu.gluTessBeginContour(tess); ! ! Vertex previous = null; ! Edge previousEdge = null; ! double[] coords; ! for (int i = 0; i < edges.size(); i++) { ! Edge e = (Edge)edges.get(i); ! if (previous == null) { ! previous = e.getTo(); ! // will be drawn with the second vertex as to find out if it is to or from that counts ! } else { ! Vertex temp = e.otherVertex(previous); ! if (temp != null) { ! coords = new double[] {previous.getX(), previous.getY(), previous.getZ()}; ! glu.gluTessVertex(tess, coords, new Point(coords[0], coords[1], coords[2])); ! //gl.glVertex3d(previous.getX(), previous.getY(), previous.getZ()); ! previous = temp; ! if (i == edges.size() - 1) { ! coords = new double[] {previous.getX(), previous.getY(), previous.getZ()}; ! glu.gluTessVertex(tess, coords, new Point(coords[0], coords[1], coords[2])); ! //gl.glVertex3d(previous.getX(), previous.getY(), previous.getZ()); ! } } else { ! temp = previousEdge.otherVertex(previous); ! coords = new double[] {temp.getX(), temp.getY(), temp.getZ()}; ! glu.gluTessVertex(tess, coords, new Point(coords[0], coords[1], coords[2])); ! //gl.glVertex3d(temp.getX(), temp.getY(), temp.getZ()); ! previous = e.otherVertex(temp); ! if (i == edges.size() - 1) { ! if (previous == null) { ! log.warn("[drawSurface] could not find vertex " + temp + " on " + e); ! } else { ! coords = new double[] {previous.getX(), previous.getY(), previous.getZ()}; ! glu.gluTessVertex(tess, coords, new Point(coords[0], coords[1], coords[2])); ! //gl.glVertex3d(previous.getX(), previous.getY(), previous.getZ()); } } } } ! previousEdge = e; } ! //Ending contour ! glu.gluTessEndContour(tess); } ! /** * Draw an Edge *************** *** 831,834 **** --- 885,975 ---- /** + * representation of a 3D point. + */ + private class Point { + /** the x coordinate*/ + private double x; + /** the y coordinate */ + private double y; + /** the z coordinate */ + private double z; + + /** + * Constructor for a point + * @param x the x coordinate. + * @param y the y coordinate. + * @param z the z coordinate. + */ + public Point(double x, double y, double z) { + this.x = x; + this.y = y; + this.z = z; + } + + /** + * Gets x + * @return x value + */ + public double getX() { + return x; + } + /** + * Gets y + * @return y value + */ + public double getY() { + return y; + } + /** + * Gets y + * @return y value + */ + public double getZ() { + return z; + } + } + + /** + * Inner class that defines the callbacks for tessellation + */ + private class Callback extends GLUtesselatorCallbackAdapter { + + /** + * Constructor + */ + public Callback() { + super(); + } + + /** + * The begin callback. + * @param type the type of begin + */ + public void begin(int type) { + gl.glBegin(type); + } + + /** + * The end callback. + */ + public void end() { + gl.glEnd(); + } + + /** + * The vertex callback. + * @param vertex an object representing the vertex. + */ + public void vertex(Object vertex) { + if (vertex instanceof Point) { + Point p = (Point)vertex; + gl.glVertex3d(p.x, p.y, p.z); + } else { + log.error("A none-point object was passed to the tessellator"); + } + } + } + + /** * Get transformation for model to screen coordinates * @return The transformation |