Thread: [Bprocessor-commit] gl/src/net/sourceforge/bprocessor/gl/view AbstractView.java,1.9,1.10
Status: Pre-Alpha
Brought to you by:
henryml
From: rimestad <rim...@us...> - 2005-08-25 09:47:12
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/view In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30393 Modified Files: AbstractView.java Log Message: Added lighting and changed when what is drawn Index: AbstractView.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/view/AbstractView.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** AbstractView.java 22 Aug 2005 14:30:57 -0000 1.9 --- AbstractView.java 25 Aug 2005 09:47:01 -0000 1.10 *************** *** 37,64 **** private static Logger log = Logger.getLogger(AbstractView.class); - /** the color of the x axis */ - public static final double[] X_AXIS_COLOR = new double[] {0.0, 1.0, 0.0}; - - /** the color of the y axis */ - public static final double[] Y_AXIS_COLOR = new double[] {1.0, 0.0, 0.0}; - - /** the color of the z axis */ - public static final double[] Z_AXIS_COLOR = new double[] {0.0, 0.0, 1.0}; - - /** the std line color*/ - public static final double[] STD_LINE_COLOR = new double[] {0.1, 0.1, 0.1}; - - /** Used for the actual drawing line */ - public static final double[] DRAW_COLOR = new double[] {1.0, 1.0, 0.0}; - - /** Used for the actual drawing line */ - public static final double[] GRID_COLOR = new double[] {0.85, 0.85, 0.85, 0.8}; - - /** Surface color for all not selected surfaces */ - public static final double[] SURFACE_COLOR = new double[] {0.93, 0.93, 0.93, 0.95}; - - /** Used for selected objects */ - public static final double[] SELECTED_COLOR = new double[] {1.0, 0.4, 1.0, 0.95}; - /** The view transformation matrix (it is shown transposed) see p. 187 [GL BIBLE]*/ protected static double[] viewTrans = new double[] {1.0, 0.0, 0.0, 0.0, --- 37,40 ---- *************** *** 139,142 **** --- 115,140 ---- private int selectMode; + /** The drawing mode. Either wireframe, solid og lighting */ + protected int drawMode = WIREFRAME_MODE; + + /** The transparency of surfaces */ + protected static byte[] transparency = new byte[128]; + + static { + setTransparency(100); + }; + + /** + * Set the transparency pattern + * @param percent the percent of visible surface; + */ + public static void setTransparency(int percent) { + byte b = (byte)0xff; //(byte)(255 * (percent / 100)); + log.info(b); + for (int i = 0; i < transparency.length; i++) { + transparency[i] = b; + } + } + /** * The constructor *************** *** 162,170 **** this.aspect = this.width / this.height; - - gl.glEnable(GL.GL_DEPTH_TEST); - gl.glEnable(GL.GL_LINE_SMOOTH); - gl.glEnable(GL.GL_POINT_SMOOTH); - gl.glEnable(GL.GL_BLEND); gl.glClearColor(0.7f, 0.7f, 0.7f, 0.0f); --- 160,163 ---- *************** *** 180,184 **** gl = gld.getGL(); gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); - gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA); glu = gld.getGLU(); --- 173,176 ---- *************** *** 191,203 **** gl.glRenderMode(GL.GL_SELECT); } ! camera(gld); picking = 0; gl.glLineWidth(1.0f); grid(); gl.glLineWidth(3.0f); coords(); ! gl.glColor3dv(STD_LINE_COLOR); gl.glLineWidth(2.0f); drawAll(gld); --- 183,224 ---- gl.glRenderMode(GL.GL_SELECT); } ! camera(gld); picking = 0; + gl.glEnable(GL.GL_LINE_SMOOTH); + gl.glEnable(GL.GL_POINT_SMOOTH); + //gl.glEnable(GL.GL_POLYGON_SMOOTH); + gl.glEnable(GL.GL_BLEND); + gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA); + gl.glDepthMask(true); + + // grid and coords are always completely lit + gl.glDisable(GL.GL_DEPTH_TEST); + gl.glDisable(GL.GL_LIGHTING); gl.glLineWidth(1.0f); grid(); gl.glLineWidth(3.0f); + gl.glEnable(GL.GL_DEPTH_TEST); coords(); ! gl.glEnable(GL.GL_LIGHTING); ! ! // set up lighting for the model ! if (drawMode == LIGHTING_MODE) { ! gl.glShadeModel(GL.GL_SMOOTH); ! gl.glEnable(GL.GL_LIGHTING); ! gl.glEnable(GL.GL_LIGHT0); ! gl.glEnable(GL.GL_COLOR_MATERIAL); ! gl.glLightModeli(GL.GL_LIGHT_MODEL_TWO_SIDE, 1); ! //gl.glLightModeli(GL.GL_LIGHT_MODEL_LOCAL_VIEWER, 1); ! gl.glColorMaterial(GL.GL_FRONT_AND_BACK, GL.GL_AMBIENT_AND_DIFFUSE); ! gl.glLightfv(GL.GL_LIGHT0, GL.GL_AMBIENT, new float[] {0.3f, 0.3f, 0.3f, 1.0f}); ! gl.glLightfv(GL.GL_LIGHT0, GL.GL_DIFFUSE, new float[] {0.7f, 0.7f, 0.7f, 1.0f}); ! } else { ! gl.glDisable(GL.GL_COLOR_MATERIAL); ! gl.glDisable(GL.GL_LIGHTING); ! } ! ! gl.glColor3fv(STD_LINE_COLOR); gl.glLineWidth(2.0f); drawAll(gld); *************** *** 268,271 **** --- 289,312 ---- gl.glInitNames(); if (mode[0] != GL.GL_SELECT) { + gl.glEnable(GL.GL_DEPTH_TEST); + // draw selected surface + if (selectedSurface != null) { + gl.glColor3fv(SELECTED_COLOR); + selectedSurface = SurfaceFacade.getInstance().findById(selectedSurface.getId()); + drawSurface(selectedSurface); + } + + // draw all the surfaces in the model + if (drawMode != WIREFRAME_MODE) { + Iterator it = surfaces.iterator(); + gl.glColor3fv(SURFACE_COLOR); + while (it.hasNext()) { + Surface s = (Surface)it.next(); + if (!s.equals(selectedSurface)) { + drawSurface(s); + } + } + } + // draw activeEdge different if it is parallel with axis if (activeEdge != null) { *************** *** 273,283 **** Vertex from = activeEdge.getFrom(); if (from.getY() == to.getY() && from.getZ() == to.getZ()) { ! gl.glColor3dv(X_AXIS_COLOR); } else if (from.getX() == to.getX() && from.getZ() == to.getZ()) { ! gl.glColor3dv(Y_AXIS_COLOR); } else if (from.getX() == to.getX() && from.getY() == to.getY()) { ! gl.glColor3dv(Z_AXIS_COLOR); } else { ! gl.glColor3dv(STD_LINE_COLOR); } gl.glBegin(GL.GL_LINES); --- 314,324 ---- Vertex from = activeEdge.getFrom(); if (from.getY() == to.getY() && from.getZ() == to.getZ()) { ! gl.glColor3fv(X_AXIS_COLOR); } else if (from.getX() == to.getX() && from.getZ() == to.getZ()) { ! gl.glColor3fv(Y_AXIS_COLOR); } else if (from.getX() == to.getX() && from.getY() == to.getY()) { ! gl.glColor3fv(Z_AXIS_COLOR); } else { ! gl.glColor3fv(STD_LINE_COLOR); } gl.glBegin(GL.GL_LINES); *************** *** 291,301 **** if (alignPoint != null && alignVertex != null) { if (alignPoint[1] == alignVertex.getY() && alignPoint[2] == alignVertex.getZ()) { ! gl.glColor3dv(X_AXIS_COLOR); } else if (alignPoint[0] == alignVertex.getX() && alignPoint[2] == alignVertex.getZ()) { ! gl.glColor3dv(Y_AXIS_COLOR); } else if (alignPoint[0] == alignVertex.getX() && alignPoint[1] == alignVertex.getY()) { ! gl.glColor3dv(Z_AXIS_COLOR); } else { ! gl.glColor3dv(DRAW_COLOR); } gl.glBegin(GL.GL_LINES); --- 332,342 ---- if (alignPoint != null && alignVertex != null) { if (alignPoint[1] == alignVertex.getY() && alignPoint[2] == alignVertex.getZ()) { ! gl.glColor3fv(X_AXIS_COLOR); } else if (alignPoint[0] == alignVertex.getX() && alignPoint[2] == alignVertex.getZ()) { ! gl.glColor3fv(Y_AXIS_COLOR); } else if (alignPoint[0] == alignVertex.getX() && alignPoint[1] == alignVertex.getY()) { ! gl.glColor3fv(Z_AXIS_COLOR); } else { ! gl.glColor3fv(DRAW_COLOR); } gl.glBegin(GL.GL_LINES); *************** *** 317,321 **** // draw selected vertex if (selectedVertex != null) { ! gl.glColor4dv(SELECTED_COLOR); gl.glPointSize(5.0f); gl.glBegin(GL.GL_POINTS); --- 358,362 ---- // draw selected vertex if (selectedVertex != null) { ! gl.glColor3fv(SELECTED_COLOR); gl.glPointSize(5.0f); gl.glBegin(GL.GL_POINTS); *************** *** 328,332 **** // draw selected edge if (selectedEdge != null) { ! gl.glColor4dv(SELECTED_COLOR); selectedEdge = EdgeFacade.getInstance().findById(selectedEdge.getId()); Vertex to = selectedEdge.getTo(); --- 369,373 ---- // draw selected edge if (selectedEdge != null) { ! gl.glColor3fv(SELECTED_COLOR); selectedEdge = EdgeFacade.getInstance().findById(selectedEdge.getId()); Vertex to = selectedEdge.getTo(); *************** *** 338,369 **** } ! // draw selected surface ! if (selectedSurface != null) { ! gl.glColor4dv(SELECTED_COLOR); ! selectedSurface = SurfaceFacade.getInstance().findById(selectedSurface.getId()); ! drawSurface(selectedSurface); ! } ! ! Iterator it = surfaces.iterator(); ! gl.glColor4dv(SURFACE_COLOR); ! while (it.hasNext()) { ! Surface s = (Surface)it.next(); ! if (!s.equals(selectedSurface)) { ! drawSurface(s); ! } ! } ! ! it = edges.iterator(); ! gl.glColor3dv(STD_LINE_COLOR); ! while (it.hasNext()) { ! Edge e = (Edge)it.next(); if (!e.equals(selectedEdge)) { drawEdge(e); } ! } } else { if (selectMode == SURFACES) { Iterator it = surfaces.iterator(); ! gl.glColor4dv(SURFACE_COLOR); while (it.hasNext()) { Surface s = (Surface)it.next(); --- 379,397 ---- } ! // draw all the edges in the model ! Iterator eit = edges.iterator(); ! gl.glColor3fv(STD_LINE_COLOR); ! while (eit.hasNext()) { ! Edge e = (Edge)eit.next(); if (!e.equals(selectedEdge)) { drawEdge(e); } ! } ! ! // HERE STARTS SELECTION MODE DRAWING } else { if (selectMode == SURFACES) { Iterator it = surfaces.iterator(); ! gl.glColor3fv(SURFACE_COLOR); while (it.hasNext()) { Surface s = (Surface)it.next(); *************** *** 377,381 **** if (selectMode == EDGES) { Iterator it = edges.iterator(); ! gl.glColor3dv(STD_LINE_COLOR); while (it.hasNext()) { Edge e = (Edge)it.next(); --- 405,409 ---- if (selectMode == EDGES) { Iterator it = edges.iterator(); ! gl.glColor3fv(STD_LINE_COLOR); while (it.hasNext()) { Edge e = (Edge)it.next(); *************** *** 389,393 **** if (selectMode == VERTICES) { Iterator it = vertices.iterator(); ! gl.glColor3dv(STD_LINE_COLOR); while (it.hasNext()) { Vertex v = (Vertex)it.next(); --- 417,421 ---- if (selectMode == VERTICES) { Iterator it = vertices.iterator(); ! gl.glColor3fv(STD_LINE_COLOR); while (it.hasNext()) { Vertex v = (Vertex)it.next(); *************** *** 406,412 **** --- 434,449 ---- */ private void drawSurface(Surface s) { + //gl.glEnable(GL.GL_POLYGON_STIPPLE); + //gl.glDisable(GL.GL_BLEND); + //glblend.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA); + //gl.glPolygonStipple(transparency); List l = s.getEdges(); if (l != null) { gl.glBegin(GL.GL_POLYGON); + if (drawMode == LIGHTING_MODE) { + Vertex norm = s.normal(); + norm.scale(1 / norm.length()); + gl.glNormal3d(norm.getX(), norm.getY(), norm.getZ()); + } Vertex previous = null; Edge previousEdge = null; *************** *** 421,433 **** gl.glVertex3d(previous.getX(), previous.getY(), previous.getZ()); previous = temp; ! 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 (previous == null) { ! log.warn("[drawSurface] could not find vertex " + temp + " on " + e); ! } else { ! gl.glVertex3d(previous.getX(), previous.getY(), previous.getZ()); } } --- 458,474 ---- 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()); ! } } } *************** *** 437,440 **** --- 478,483 ---- gl.glEnd(); } + //gl.glDisable(GL.GL_POLYGON_STIPPLE); + //gl.glEnable(GL.GL_DEPTH_TEST); } *************** *** 475,479 **** Iterator it = edges.iterator(); ! gl.glColor3dv(STD_LINE_COLOR); while (it.hasNext()) { Edge e = (Edge)it.next(); --- 518,522 ---- Iterator it = edges.iterator(); ! gl.glColor3fv(STD_LINE_COLOR); while (it.hasNext()) { Edge e = (Edge)it.next(); *************** *** 481,484 **** --- 524,528 ---- } } + /** * Draw all surfaces *************** *** 491,495 **** Iterator it = surfaces.iterator(); ! gl.glColor3dv(STD_LINE_COLOR); while (it.hasNext()) { Surface s = (Surface)it.next(); --- 535,539 ---- Iterator it = surfaces.iterator(); ! gl.glColor3fv(STD_LINE_COLOR); while (it.hasNext()) { Surface s = (Surface)it.next(); *************** *** 499,502 **** --- 543,547 ---- } } + /** * Change the rotation about the x axis. Only usable in 3D *************** *** 734,737 **** --- 779,792 ---- /** + * Change the drawing mode + * @param mode The mode one of the statics WIREFRAME_MODE, SOLID_MODE or LIGHTING_MODE + */ + public void changeDrawMode(int mode) { + if (mode <= 2 && mode >= 0) { + drawMode = mode; + } + } + + /** * The camera init function * @param gld The GLDrawable object |