Thread: [Bprocessor-commit] gl/src/net/sourceforge/bprocessor/gl/view View.java,1.67,1.68
Status: Pre-Alpha
Brought to you by:
henryml
|
From: Michael L. <he...@us...> - 2006-03-03 12:13:39
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/view In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16857/src/net/sourceforge/bprocessor/gl/view Modified Files: View.java Log Message: Refactoring of drawAll Index: View.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/view/View.java,v retrieving revision 1.67 retrieving revision 1.68 diff -C2 -d -r1.67 -r1.68 *** View.java 26 Feb 2006 23:56:45 -0000 1.67 --- View.java 3 Mar 2006 12:13:34 -0000 1.68 *************** *** 450,454 **** glu = gld.getGLU(); - int[] mode = new int[1]; gl.glViewport(0, 0, (int)width, (int)height); View.height = height; --- 450,453 ---- *************** *** 480,484 **** gl.glLineWidth(1.0f); ! drawAll(gld); gl.glEnable(GL.GL_DEPTH_TEST); --- 479,483 ---- gl.glLineWidth(1.0f); ! drawAll(gld, hitdetection); gl.glEnable(GL.GL_DEPTH_TEST); *************** *** 497,501 **** } - gl.glGetIntegerv(GL.GL_RENDER_MODE, mode); if (glv.getTool() instanceof SpaceTool) { --- 496,499 ---- *************** *** 503,507 **** gl.glPushMatrix(); gl.glLoadIdentity(); ! if (mode[0] == GL.GL_SELECT) { int[] viewport = new int[] {0, 0, (int)width, (int)height}; glu.gluPickMatrix(x, viewport[3] - y, 5, 5, viewport); --- 501,505 ---- gl.glPushMatrix(); gl.glLoadIdentity(); ! if (hitdetection) { int[] viewport = new int[] {0, 0, (int)width, (int)height}; glu.gluPickMatrix(x, viewport[3] - y, 5, 5, viewport); *************** *** 511,515 **** gl.glPushMatrix(); gl.glLoadIdentity(); ! labelSelection(mode[0] == GL.GL_SELECT); gl.glMatrixMode(GL.GL_PROJECTION); gl.glPopMatrix(); --- 509,513 ---- gl.glPushMatrix(); gl.glLoadIdentity(); ! labelSelection(hitdetection); gl.glMatrixMode(GL.GL_PROJECTION); gl.glPopMatrix(); *************** *** 519,523 **** } gl.glPopMatrix(); ! if (mode[0] == GL.GL_SELECT) { gl.glFlush(); hits = gl.glRenderMode(GL.GL_RENDER); --- 517,521 ---- } gl.glPopMatrix(); ! if (hitdetection) { gl.glFlush(); hits = gl.glRenderMode(GL.GL_RENDER); *************** *** 659,835 **** * Draw all the existing elements * @param gld The GLDrawable */ ! protected void drawAll(GLDrawable gld) { ! Collection surfaces = Project.getInstance().getSurfaces(); ! Collection edges = Project.getInstance().getEdges(); ! Collection vertices = Project.getInstance().getVertices(); Collection selection = glv.getTool().getSelection(); ! ! int[] mode = new int[1]; ! gl.glGetIntegerv(GL.GL_RENDER_MODE, mode); ! ! gl = gld.getGL(); ! glu = gld.getGLU(); ! ! initNames(gl); ! if (mode[0] != GL.GL_SELECT) { ! gl.glEnable(GL.GL_DEPTH_TEST); ! // draw selection ! gl.glColor3fv(SELECTED_COLOR); ! Iterator selit = selection.iterator(); ! while (selit.hasNext()) { ! Object o = selit.next(); ! if (o instanceof Surface) { ! drawObject(o); ! } } ! ! { ! if (DRAW_LONE_VERTICES) { ! // Draw any Vertex that are not part of an edge ! gl.glColor3fv(lineColor); ! Iterator it = vertices.iterator(); ! while (it.hasNext()) { ! Vertex v = (Vertex)it.next(); ! if (v.getEdges().isEmpty()) { ! gl.glColor3fv(lineColor); ! gl.glPointSize(5.0f); ! gl.glBegin(GL.GL_POINTS); ! gl.glVertex3d(v.getX(), v.getY(), v.getZ()); ! gl.glEnd(); ! gl.glPointSize(1.0f); ! } } ! // Draw any temporary vertex not part of an edge ! gl.glColor3fv(lineColor); ! it = tempVertices.iterator(); ! while (it.hasNext()) { ! Vertex v = (Vertex)it.next(); ! if (v.getEdges().isEmpty()) { ! gl.glColor3fv(lineColor); ! gl.glPointSize(5.0f); ! gl.glBegin(GL.GL_POINTS); ! gl.glVertex3d(v.getX(), v.getY(), v.getZ()); ! gl.glEnd(); ! gl.glPointSize(1.0f); ! } } } } ! ! // Fill surfaces ! switch (drawMode) { ! case LIGHTING_MODE: { ! gl.glEnable(GL.GL_LIGHTING); ! gl.glEnable(GL.GL_POLYGON_OFFSET_FILL); ! gl.glPolygonOffset(0.5f, 0.5f); ! gl.glEnable(GL.GL_CULL_FACE); ! ! gl.glCullFace(GL.GL_BACK); ! gl.glColor3fv(Defaults.getFrontColor()); ! drawSurfaces(gld, FRONT); ! ! gl.glCullFace(GL.GL_FRONT); ! gl.glColor3fv(Defaults.getBackColor()); ! drawSurfaces(gld, BACK); ! gl.glDisable(GL.GL_CULL_FACE); ! gl.glDisable(GL.GL_POLYGON_OFFSET_FILL); ! gl.glDisable(GL.GL_LIGHTING); ! break; ! } ! case WIREFRAME_MODE: { ! // NOTHING TO DO ! break; ! } ! case SOLID_MODE: { ! gl.glEnable(GL.GL_POLYGON_OFFSET_FILL); ! gl.glPolygonOffset(1.0f, 1.0f); ! gl.glColor3fv(SURFACE_COLOR); ! drawSurfaces(gld, BOTH); ! gl.glDisable(GL.GL_POLYGON_OFFSET_FILL); ! break; ! } ! } ! //Draw edges ! if (doDrawEdges) { ! drawEdges(gld); ! } ! ! gl.glColor3fv(SELECTED_COLOR); ! selit = selection.iterator(); ! while (selit.hasNext()) { ! Object o = selit.next(); ! if (!(o instanceof Surface)) { ! drawObject(o); ! } ! } ! ! // draw target ! gl.glColor3fv(TARGET_COLOR); ! if (target != null) { ! drawObject(target); ! } ! gl.glDisable(GL.GL_DEPTH_TEST); ! Vertex to = null; ! if (activeEdge != null) { ! to = activeEdge.getTo(); ! Vertex from = activeEdge.getFrom(); ! if (cmp(from.getY(), to.getY()) && cmp(from.getZ(), to.getZ())) { ! gl.glColor3fv(X_AXIS_COLOR); ! } else if (cmp(from.getX(), to.getX()) && cmp(from.getZ(), to.getZ())) { ! gl.glColor3fv(Y_AXIS_COLOR); ! } else if (cmp(from.getX(), to.getX()) && cmp(from.getY(), to.getY())) { ! gl.glColor3fv(Z_AXIS_COLOR); ! } else { ! gl.glColor3fv(lineColor); ! } ! gl.glLineWidth(1.0f); ! drawEdge(activeEdge); } ! ! if (to == null) { ! to = currentVertex; } ! if (snapVertex != null && to != null) { ! boolean doDraw = true; ! if (cmp(snapVertex.getY(), to.getY()) && cmp(snapVertex.getZ(), to.getZ())) { ! gl.glColor3fv(X_AXIS_COLOR); ! } else if (cmp(snapVertex.getX(), to.getX()) && cmp(snapVertex.getZ(), to.getZ())) { ! gl.glColor3fv(Y_AXIS_COLOR); ! } else if (cmp(snapVertex.getX(), to.getX()) && cmp(snapVertex.getY(), to.getY())) { ! gl.glColor3fv(Z_AXIS_COLOR); ! } else { ! doDraw = false; ! } ! if (doDraw) { ! gl.glEnable(GL.GL_LINE_STIPPLE); ! gl.glLineWidth(1.0f); ! gl.glBegin(GL.GL_LINES); ! gl.glVertex3d(snapVertex.getX(), snapVertex.getY(), snapVertex.getZ()); ! gl.glVertex3d(to.getX(), to.getY(), to.getZ()); ! gl.glEnd(); ! gl.glDisable(GL.GL_LINE_STIPPLE); ! } } ! ! ! // draw snap point if any ! if (snapVertex != null) { ! gl.glDisable(GL.GL_DEPTH_TEST); ! gl.glColor3fv(TARGET_COLOR); ! gl.glPointSize(5.0f); ! gl.glBegin(GL.GL_POINTS); gl.glVertex3d(snapVertex.getX(), snapVertex.getY(), snapVertex.getZ()); gl.glEnd(); ! gl.glPointSize(1.0f); ! } ! } else { ! drawSelectionMode(vertices, edges, surfaces); } } /** * Draw an object --- 657,834 ---- * Draw all the existing elements * @param gld The GLDrawable + * @param hitdetection For hitdetection */ ! protected void drawAll(GLDrawable gld, boolean hitdetection) { ! if (!hitdetection) { ! drawNormalMode(gld); ! } else { ! ! drawSelectionMode(gld); ! } ! } ! ! /** ! * Draw the model normally ! * @param gld The GLDrawable ! */ ! private void drawNormalMode(GLDrawable gld) { Collection selection = glv.getTool().getSelection(); ! gl.glEnable(GL.GL_DEPTH_TEST); ! // draw selection ! gl.glColor3fv(SELECTED_COLOR); ! Iterator selit = selection.iterator(); ! while (selit.hasNext()) { ! Object o = selit.next(); ! if (o instanceof Surface) { ! drawObject(o); } ! } ! ! { ! if (DRAW_LONE_VERTICES) { ! // Draw any Vertex that are not part of an edge ! Collection vertices = Project.getInstance().getVertices(); ! gl.glColor3fv(lineColor); ! Iterator it = vertices.iterator(); ! while (it.hasNext()) { ! Vertex v = (Vertex)it.next(); ! if (v.getEdges().isEmpty()) { ! gl.glColor3fv(lineColor); ! gl.glPointSize(5.0f); ! gl.glBegin(GL.GL_POINTS); ! gl.glVertex3d(v.getX(), v.getY(), v.getZ()); ! gl.glEnd(); ! gl.glPointSize(1.0f); } ! } ! // Draw any temporary vertex not part of an edge ! gl.glColor3fv(lineColor); ! it = tempVertices.iterator(); ! while (it.hasNext()) { ! Vertex v = (Vertex)it.next(); ! if (v.getEdges().isEmpty()) { ! gl.glColor3fv(lineColor); ! gl.glPointSize(5.0f); ! gl.glBegin(GL.GL_POINTS); ! gl.glVertex3d(v.getX(), v.getY(), v.getZ()); ! gl.glEnd(); ! gl.glPointSize(1.0f); } } } ! } ! ! // Fill surfaces ! switch (drawMode) { ! case LIGHTING_MODE: { ! gl.glEnable(GL.GL_LIGHTING); ! gl.glEnable(GL.GL_POLYGON_OFFSET_FILL); ! gl.glPolygonOffset(0.5f, 0.5f); ! gl.glEnable(GL.GL_CULL_FACE); ! gl.glCullFace(GL.GL_BACK); ! gl.glColor3fv(Defaults.getFrontColor()); ! drawSurfaces(gld, FRONT); ! gl.glCullFace(GL.GL_FRONT); ! gl.glColor3fv(Defaults.getBackColor()); ! drawSurfaces(gld, BACK); ! gl.glDisable(GL.GL_CULL_FACE); ! gl.glDisable(GL.GL_POLYGON_OFFSET_FILL); ! gl.glDisable(GL.GL_LIGHTING); ! break; ! } ! case WIREFRAME_MODE: { ! // NOTHING TO DO ! break; ! } ! case SOLID_MODE: { ! gl.glEnable(GL.GL_POLYGON_OFFSET_FILL); ! gl.glPolygonOffset(1.0f, 1.0f); ! gl.glColor3fv(SURFACE_COLOR); ! drawSurfaces(gld, BOTH); ! gl.glDisable(GL.GL_POLYGON_OFFSET_FILL); ! break; ! } ! } ! //Draw edges ! if (doDrawEdges) { ! drawEdges(gld); ! } ! ! gl.glColor3fv(SELECTED_COLOR); ! selit = selection.iterator(); ! while (selit.hasNext()) { ! Object o = selit.next(); ! if (!(o instanceof Surface)) { ! drawObject(o); } ! } ! ! // draw target ! gl.glColor3fv(TARGET_COLOR); ! if (target != null) { ! drawObject(target); ! } ! ! gl.glDisable(GL.GL_DEPTH_TEST); ! Vertex to = null; ! ! if (activeEdge != null) { ! to = activeEdge.getTo(); ! Vertex from = activeEdge.getFrom(); ! if (cmp(from.getY(), to.getY()) && cmp(from.getZ(), to.getZ())) { ! gl.glColor3fv(X_AXIS_COLOR); ! } else if (cmp(from.getX(), to.getX()) && cmp(from.getZ(), to.getZ())) { ! gl.glColor3fv(Y_AXIS_COLOR); ! } else if (cmp(from.getX(), to.getX()) && cmp(from.getY(), to.getY())) { ! gl.glColor3fv(Z_AXIS_COLOR); ! } else { ! gl.glColor3fv(lineColor); } ! gl.glLineWidth(1.0f); ! drawEdge(activeEdge); ! } ! ! if (to == null) { ! to = currentVertex; ! } ! if (snapVertex != null && to != null) { ! boolean doDraw = true; ! if (cmp(snapVertex.getY(), to.getY()) && cmp(snapVertex.getZ(), to.getZ())) { ! gl.glColor3fv(X_AXIS_COLOR); ! } else if (cmp(snapVertex.getX(), to.getX()) && cmp(snapVertex.getZ(), to.getZ())) { ! gl.glColor3fv(Y_AXIS_COLOR); ! } else if (cmp(snapVertex.getX(), to.getX()) && cmp(snapVertex.getY(), to.getY())) { ! gl.glColor3fv(Z_AXIS_COLOR); ! } else { ! doDraw = false; } ! if (doDraw) { ! gl.glEnable(GL.GL_LINE_STIPPLE); ! gl.glLineWidth(1.0f); ! gl.glBegin(GL.GL_LINES); gl.glVertex3d(snapVertex.getX(), snapVertex.getY(), snapVertex.getZ()); + gl.glVertex3d(to.getX(), to.getY(), to.getZ()); gl.glEnd(); ! gl.glDisable(GL.GL_LINE_STIPPLE); ! } } + + + // draw snap point if any + if (snapVertex != null) { + gl.glDisable(GL.GL_DEPTH_TEST); + gl.glColor3fv(TARGET_COLOR); + gl.glPointSize(5.0f); + gl.glBegin(GL.GL_POINTS); + gl.glVertex3d(snapVertex.getX(), snapVertex.getY(), snapVertex.getZ()); + gl.glEnd(); + gl.glPointSize(1.0f); + } } + /** * Draw an object *************** *** 1336,1345 **** /** * Draws the objects for selection ! * @param vertices the set of vertices that should be selectable ! * @param edges the set of edges that should be selectable ! * @param surfaces the set of surfaces that should be selectable */ ! private void drawSelectionMode(Collection vertices, Collection edges, Collection surfaces) { ! // HERE STARTS SELECTION MODE DRAWING if (selectMode == VERTICES || selectMode == ALL) { Iterator it = vertices.iterator(); --- 1335,1348 ---- /** * Draws the objects for selection ! * @param gld The GLDrawable */ ! private void drawSelectionMode(GLDrawable gld) { ! Collection surfaces = Project.getInstance().getSurfaces(); ! Collection edges = Project.getInstance().getEdges(); ! Collection vertices = Project.getInstance().getVertices(); ! ! gl = gld.getGL(); ! initNames(gl); ! if (selectMode == VERTICES || selectMode == ALL) { Iterator it = vertices.iterator(); |