[Bprocessor-commit] gl/src/net/sourceforge/bprocessor/gl/view View.java, 1.231, 1.232 Display.java,
Status: Pre-Alpha
Brought to you by:
henryml
From: Michael L. <he...@us...> - 2007-09-23 16:02:21
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/view In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv17396/src/net/sourceforge/bprocessor/gl/view Modified Files: View.java Display.java Log Message: Progress on new display implementation Index: Display.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/view/Display.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Display.java 22 Sep 2007 17:16:26 -0000 1.1 --- Display.java 23 Sep 2007 16:02:08 -0000 1.2 *************** *** 8,16 **** --- 8,45 ---- package net.sourceforge.bprocessor.gl.view; + import java.util.Collection; + import java.util.HashSet; + import java.util.LinkedList; + import java.util.List; + import java.util.Set; + + import javax.media.opengl.GL; + import javax.media.opengl.GLAutoDrawable; + import javax.media.opengl.glu.GLU; + import javax.media.opengl.glu.GLUtessellator; + import javax.media.opengl.glu.GLUtessellatorCallback; + import javax.media.opengl.glu.GLUtessellatorCallbackAdapter; + + import net.sourceforge.bprocessor.model.Camera; + import net.sourceforge.bprocessor.model.Edge; + import net.sourceforge.bprocessor.model.Geometric; + import net.sourceforge.bprocessor.model.Project; + import net.sourceforge.bprocessor.model.Space; + import net.sourceforge.bprocessor.model.Surface; + import net.sourceforge.bprocessor.model.Vertex; + /** * */ public class Display { + private static boolean initialized; private static boolean selecting; + private static GLUtessellator tesselator; + private static GL gl; + private static GLU glu; + + private static float[] white = new float[] {1.0f, 1.0f, 1.0f}; + private static float[] black = new float[] {0.0f, 0.0f, 0.0f}; + /** *************** *** 24,27 **** --- 53,92 ---- /** * + * + */ + public static void initialize() { + if (!initialized) { + glu = new GLU(); + tesselator = glu.gluNewTess(); + GLUtessellatorCallback callback = new TesselatorCallback(); + glu.gluTessCallback(tesselator, GLU.GLU_TESS_BEGIN, callback); + glu.gluTessCallback(tesselator, GLU.GLU_TESS_END, callback); + glu.gluTessCallback(tesselator, GLU.GLU_TESS_VERTEX, callback); + glu.gluTessProperty(tesselator, GLU.GLU_TESS_WINDING_RULE, GLU.GLU_TESS_WINDING_ODD); + initialized = true; + } + } + + private static class TesselatorCallback extends GLUtessellatorCallbackAdapter { + + /** {@inheritDoc} */ + public void begin(int type) { + gl.glBegin(type); + } + + /** {@inheritDoc} */ + public void end() { + gl.glEnd(); + } + + /** {@inheritDoc} */ + public void vertex(Object object) { + Vertex vertex = (Vertex) object; + gl.glVertex3d(vertex.getX(), vertex.getY(), vertex.getZ()); + } + } + + /** + * * @param value selecting */ *************** *** 30,38 **** } /** * */ ! public static void draw() { } } --- 95,244 ---- } + private static void drawSurfaces(Collection<Surface> surfaces) { + gl.glColor3fv(white, 0); + gl.glEnable(GL.GL_POLYGON_OFFSET_FILL); + gl.glPolygonOffset(0.5f, 0.5f); + for (Surface current : surfaces) { + draw(current); + } + gl.glDisable(GL.GL_POLYGON_OFFSET_FILL); + } + + private static void draw(Surface surface) { + glu.gluTessBeginPolygon(tesselator, null); + drawContour(surface); + for (Surface current : surface.getHoles()) { + drawContour(current); + } + glu.gluTessEndPolygon(tesselator); + } + + private static void drawContour(Surface surface) { + List<Vertex> vertices = surface.getVertices(); + if (vertices.size() > 2) { + vertices.add(vertices.get(0)); + glu.gluTessBeginContour(tesselator); + for (Vertex current : vertices) { + glu.gluTessVertex(tesselator, current.values(), 0, current); + } + glu.gluTessEndContour(tesselator); + } + } + + private static void drawEdges(Collection<Edge> edges) { + gl.glColor3fv(black, 0); + for (Edge current : edges) { + draw(current); + } + } + + private static void draw(Edge edge) { + Vertex to = edge.getTo(); + Vertex from = edge.getFrom(); + gl.glBegin(GL.GL_LINE_STRIP); + gl.glVertex3d(to.getX(), to.getY(), to.getZ()); + gl.glVertex3d(from.getX(), from.getY(), from.getZ()); + gl.glEnd(); + } + + private static boolean transparent(Space space) { + return (space.isFunctionalSpace() || space.isTransparent() || !space.getSurfaces().isEmpty()); + } + + private static boolean transparent(Surface surface) { + Space front = surface.getFrontDomain(); + Space back = surface.getBackDomain(); + if (front == back) { + return true; + } + if (transparent(front) && transparent(back)) { + return true; + } + return false; + } + + private static void draw(Space space) { + Project project = Project.getInstance(); + Camera camera = project.getCurrentCamera(); + Set<Geometric> hidden = new HashSet(); + hidden.addAll(camera.getHiddenGeometrics()); + Collection<Space> elements = new LinkedList(); + for (Space current : space.getElements()) { + if (hidden.contains(current)) { + if (!transparent(current)) { + for (Surface surface : current.getEnvelope()) { + Space front = surface.getFrontDomain(); + Space back = surface.getBackDomain(); + if (front == back) { + hidden.add(surface); + } else { + Space other = null; + if (front == current) { + other = back; + } else { + other = front; + } + if (hidden.contains(other) || transparent(other)) { + hidden.add(surface); + } + } + } + } + } else { + elements.add(current); + } + } + + Collection<Surface> surfaces = new LinkedList(); + + Set<Edge> mark = new HashSet(); + Set<Edge> visible = new HashSet(); + for (Surface current : space.getSurfaces()) { + mark.addAll(current.getEdges()); + if (!hidden.contains(current)) { + if (!transparent(current)) { + surfaces.add(current); + visible.addAll(current.getEdges()); + for (Surface hole : current.getHoles()) { + visible.addAll(hole.getEdges()); + } + } + } + } + + Collection<Edge> edges = new LinkedList(); + for (Edge current : space.getEdges()) { + if (mark.contains(current)) { + if (visible.contains(current)) { + edges.add(current); + } + } else { + edges.add(current); + } + } + + + + + + + gl.glEnable(GL.GL_DEPTH_TEST); + drawSurfaces(surfaces); + drawEdges(edges); + for (Space current : elements) { + draw(current); + } + } + /** * + * @param gld GLAutoDrawable */ ! public static void draw(GLAutoDrawable gld) { ! gl = gld.getGL(); ! initialize(); ! Space world = Project.getInstance().world(); + draw(world); } } Index: View.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/view/View.java,v retrieving revision 1.231 retrieving revision 1.232 diff -C2 -d -r1.231 -r1.232 *** View.java 22 Sep 2007 17:16:25 -0000 1.231 --- View.java 23 Sep 2007 16:02:08 -0000 1.232 *************** *** 691,695 **** Display.selecting(hitdetection); initNames(gl); ! Display.draw(); Display.selecting(false); } else { --- 691,695 ---- Display.selecting(hitdetection); initNames(gl); ! Display.draw(gld); Display.selecting(false); } else { |