[Bprocessor-commit] gl/src/net/sourceforge/bprocessor/gl/view AbstractView.java,1.66,1.67 View.java,
Status: Pre-Alpha
Brought to you by:
henryml
From: Michael L. <he...@us...> - 2005-12-03 12:27:32
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/view In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29323/src/net/sourceforge/bprocessor/gl/view Modified Files: AbstractView.java View.java Log Message: Implemented rules for colors of surfaces: When drawing one side of the surface, the color for the space on the other side is used. Default gray for none, wheat for construction and alice blue for functional. Index: AbstractView.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/view/AbstractView.java,v retrieving revision 1.66 retrieving revision 1.67 diff -C2 -d -r1.66 -r1.67 *** AbstractView.java 1 Dec 2005 10:10:02 -0000 1.66 --- AbstractView.java 3 Dec 2005 12:27:21 -0000 1.67 *************** *** 65,68 **** --- 65,79 ---- private static final int ALL = 4; + /** The NORMAL side is the side where the normal points to */ + private static final int NORMAL = 0; + + /** The front side is the functional-space side. */ + private static final int FRONT = 1; + + /** The back side the construction-space side. */ + private static final int BACK = 2; + + + /** The width of the window */ protected static double width; *************** *** 94,97 **** --- 105,117 ---- /** The current grid color */ protected static float[] gridColor; + + /** Front color for surfaces */ + protected static float[] frontCcolor = new float[] {0.96f, 0.87f, 0.70f}; + + /** NONE color for surfaces */ + protected static float[] noneColor = new float[] {0.70f, 0.70f, 0.70f}; + + /** Back color for surfaces */ + protected static float[] backColor = new float[] {0.94f, 0.97f, 1.00f}; /** The target */ *************** *** 741,750 **** gl.glCullFace(GL.GL_BACK); ! gl.glColor3fv(FRONT_COLOR); ! drawSurfaces(gld); gl.glCullFace(GL.GL_FRONT); ! gl.glColor3fv(BACK_COLOR); ! drawSurfaces(gld); gl.glDisable(GL.GL_CULL_FACE); --- 761,770 ---- gl.glCullFace(GL.GL_BACK); ! gl.glColor3fv(frontCcolor); ! drawSurfaces(gld, FRONT); gl.glCullFace(GL.GL_FRONT); ! gl.glColor3fv(backColor); ! drawSurfaces(gld, BACK); gl.glDisable(GL.GL_CULL_FACE); *************** *** 761,765 **** gl.glPolygonOffset(1.0f, 1.0f); gl.glColor3fv(SURFACE_COLOR); ! drawSurfaces(gld); gl.glDisable(GL.GL_POLYGON_OFFSET_FILL); break; --- 781,785 ---- gl.glPolygonOffset(1.0f, 1.0f); gl.glColor3fv(SURFACE_COLOR); ! drawSurfaces(gld, NORMAL); gl.glDisable(GL.GL_POLYGON_OFFSET_FILL); break; *************** *** 871,875 **** Surface s = (Surface)it.next(); pushName(gl, s); ! drawSurface(s); popName(gl); } --- 891,895 ---- Surface s = (Surface)it.next(); pushName(gl, s); ! drawSurface(s, false); popName(gl); } *************** *** 985,989 **** gl.glPolygonStipple(highlight); Surface s = (Surface) o; ! drawSurface(s); gl.glDisable(GL.GL_POLYGON_STIPPLE); } --- 1005,1009 ---- gl.glPolygonStipple(highlight); Surface s = (Surface) o; ! drawSurface(s, false); gl.glDisable(GL.GL_POLYGON_STIPPLE); } *************** *** 993,998 **** * Draw a surface * @param s The surface to draw */ ! private void drawSurface(Surface s) { GLUtesselator tess = glu.gluNewTess(); GLUtesselatorCallback cb = new Callback(); --- 1013,1019 ---- * Draw a surface * @param s The surface to draw + * @param flip Flip the surface */ ! private void drawSurface(Surface s, boolean flip) { GLUtesselator tess = glu.gluNewTess(); GLUtesselatorCallback cb = new Callback(); *************** *** 1013,1022 **** if (norm != null) { norm.scale(1 / norm.length()); ! gl.glNormal3d(norm.getX(), norm.getY(), norm.getZ()); } } //drawing the outer contour ! drawContour(s, tess); ! //drawing the inner conturs Set innerSurfaces = s.getInnerSurfaces(); --- 1034,1050 ---- if (norm != null) { norm.scale(1 / norm.length()); ! if (flip) { ! gl.glNormal3d(-norm.getX(), -norm.getY(), -norm.getZ()); ! } else { ! gl.glNormal3d(norm.getX(), norm.getY(), norm.getZ()); ! } } } //drawing the outer contour ! if (flip) { ! drawContourReverse(s, tess); ! } else { ! drawContour(s, tess); ! } //drawing the inner conturs Set innerSurfaces = s.getInnerSurfaces(); *************** *** 1056,1059 **** --- 1084,1109 ---- } + /** + * Draw contour of a Surface in reverse + * @param surface The surface + * @param tess The Tesselator + */ + private void drawContourReverse(Surface surface, GLUtesselator tess) { + List vertices = surface.getVertices(); + if (vertices.size() > 0) { + Vertex first = (Vertex) vertices.get(0); + Vertex last = (Vertex) vertices.get(vertices.size() - 1); + if (first == last) { + glu.gluTessBeginContour(tess); + for (int i = vertices.size(); i > 0; i--) { + Vertex current = (Vertex) vertices.get(i - 1); + double[] coords = new double[] {current.getX(), current.getY(), current.getZ()}; + glu.gluTessVertex(tess, coords, new Point(coords[0], coords[1], coords[2])); + } + glu.gluTessEndContour(tess); + } + } + } + /** *************** *** 1124,1134 **** } } ! /** ! * Draw all surfaces * @param gld The GLDrawable */ ! private void drawSurfaces(GLDrawable gld) { ! Set surfaces = Project.getInstance().getSurfaces(); Collection selection = glv.getTool().getSelection(); GL gl = gld.getGL(); --- 1174,1225 ---- } } ! /** ! * Is the surface visible ! * @param surface The surface to test ! * @return True if visible ! */ ! private boolean isVisible(Surface surface) { ! Domain back = surface.getBackDomain(); ! Domain front = surface.getFrontDomain(); ! if ((front instanceof FunctionalSpace) && (back instanceof FunctionalSpace)) { ! return false; ! } ! if ((front instanceof ConstructionSpace) && (back instanceof ConstructionSpace)) { ! return false; ! } ! return true; ! } ! ! /** ! * ! * Get color associated with the space ! * @param space The space ! * @return The color ! */ ! private float[] getSpaceColor(Domain space) { ! if (space == null) { ! return noneColor; ! } else { ! // TODO check if the space space has a color ! if (space instanceof ConstructionSpace) { ! // We are looking at a constructionspace ! return frontCcolor; ! } ! if (space instanceof FunctionalSpace) { ! // We are looking at a constructionspace ! return backColor; ! } ! return noneColor; ! } ! } ! ! /** ! * Draw the surfaces * @param gld The GLDrawable + * @param surfaces The surfaces to draw + * @param side The side of the Surface to draw */ ! private void drawSurfaces(GLDrawable gld, Set surfaces, int side) { Collection selection = glv.getTool().getSelection(); GL gl = gld.getGL(); *************** *** 1137,1167 **** Surface s = (Surface)it.next(); if (!selection.contains(s)) { ! if ((s.getBackDomain() instanceof FunctionalSpace) && ! (s.getFrontDomain() instanceof FunctionalSpace)) { ! //gl.glEnable(GL.GL_POLYGON_STIPPLE); ! //gl.glPolygonStipple(transparency); ! //drawSurface(s); ! //gl.glDisable(GL.GL_POLYGON_STIPPLE); ! } else { ! drawSurface(s); } } ! } ! it = tempSurfaces.iterator(); ! while (it.hasNext()) { ! Surface s = (Surface)it.next(); ! if (!selection.contains(s)) { ! if ((s.getBackDomain() instanceof FunctionalSpace) && ! (s.getFrontDomain() instanceof FunctionalSpace)) { ! //gl.glEnable(GL.GL_POLYGON_STIPPLE); ! //gl.glPolygonStipple(transparency); ! //drawSurface(s); ! //gl.glDisable(GL.GL_POLYGON_STIPPLE); ! } else { ! drawSurface(s); ! } ! } ! } } --- 1228,1269 ---- Surface s = (Surface)it.next(); if (!selection.contains(s)) { ! if (isVisible(s)) { ! if (side == FRONT) { ! // TODO check if a surface has a color assigned to ! // the front and use that. ! ! // Where are drawing the front of the surface, so ! // we should use the color of the Space associated with the ! // back. ! ! Domain back = s.getBackDomain(); ! gl.glColor3fv(getSpaceColor(back)); ! } ! if (side == BACK) { ! // TODO check if a surface has a color assigned to ! // the back and use that. ! ! // Where are drawing the back of the surface, so ! // we should use the color of the Space associated with the ! // front. ! ! Domain front = s.getFrontDomain(); ! gl.glColor3fv(getSpaceColor(front)); ! } ! drawSurface(s, false); } } ! } ! } ! /** ! * Draw all surfaces ! * @param gld The GLDrawable ! * @param side The side of surfaces to draw ! */ ! private void drawSurfaces(GLDrawable gld, int side) { ! Set surfaces = Project.getInstance().getSurfaces(); ! drawSurfaces(gld, surfaces, side); ! drawSurfaces(gld, tempSurfaces, side); } *************** *** 1772,1775 **** --- 1874,1886 ---- /** + * Set the none color + * @param color The color + */ + + public void setNoneColor(float[] color) { + noneColor = color; + } + + /** * Adds a temporary surface to be drawn. * @param s the surface Index: View.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/view/View.java,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -d -r1.25 -r1.26 *** View.java 1 Dec 2005 10:10:02 -0000 1.25 --- View.java 3 Dec 2005 12:27:21 -0000 1.26 *************** *** 58,67 **** public static final float[] SURFACE_COLOR = new float[] {1.0f, 1.0f, 1.0f}; - /** Front color for surfaces */ - public static final float[] FRONT_COLOR = new float[] {0.96f, 0.87f, 0.70f}; - - /** Back color for surfaces */ - public static final float[] BACK_COLOR = new float[] {0.94f, 0.97f, 1.00f}; - /** Used for selected objects */ public static final float[] SELECTED_COLOR = new float[] {1.0f, 0.4f, 1.0f}; --- 58,61 ---- *************** *** 298,301 **** --- 292,301 ---- /** + * Sets the default surface color + * @param color the color + */ + public void setNoneColor(float[] color); + + /** * Adds a temporary surface to be drawn. * @param s the surface |