[Bprocessor-commit] gl/src/net/sourceforge/bprocessor/gl/view AbstractView.java,1.47,1.48 View.java,
Status: Pre-Alpha
Brought to you by:
henryml
From: Michael L. <he...@us...> - 2005-10-30 15:55:59
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/view In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19988/src/net/sourceforge/bprocessor/gl/view Modified Files: AbstractView.java View.java Log Message: Improved hit detection of vertices Uses different colors for back and front of surfaces in LIGHTING_MODE Added snap-functionality in PencilTool when drawing holes on surfaces Length is now millimeter (because the . is not accepted in length field) Index: AbstractView.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/view/AbstractView.java,v retrieving revision 1.47 retrieving revision 1.48 diff -C2 -d -r1.47 -r1.48 *** AbstractView.java 28 Oct 2005 12:18:38 -0000 1.47 --- AbstractView.java 30 Oct 2005 15:55:40 -0000 1.48 *************** *** 21,24 **** --- 21,25 ---- import java.util.ArrayList; + import java.util.HashSet; import java.util.Iterator; import java.util.List; *************** *** 149,153 **** /** The drawing mode. Either wireframe, solid og lighting */ ! protected int drawMode = View.WIREFRAME_MODE; /** The transparency of surfaces */ --- 150,158 ---- /** The drawing mode. Either wireframe, solid og lighting */ ! protected int drawMode = View.LIGHTING_MODE; ! ! /** Specify edge drawing **/ ! protected boolean doDrawEdges = true; ! /** The transparency of surfaces */ *************** *** 192,200 **** gl = gld.getGL(); glu = gld.getGLU(); ! GLUtesselator tess = glu.gluNewTess(); ! glu.gluBeginPolygon(tess); ! glu.gluEndPolygon(tess); ! glu.gluDeleteTess(tess); ! // TODO Initialize tesselation... AbstractView.width = gld.getSize().getWidth(); AbstractView.height = gld.getSize().getHeight(); --- 197,201 ---- gl = gld.getGL(); glu = gld.getGLU(); ! AbstractView.width = gld.getSize().getWidth(); AbstractView.height = gld.getSize().getHeight(); *************** *** 238,241 **** --- 239,243 ---- if (picking > 0) { //notice 512 is just some magic number for the size of the selectbuffer + // TODO Catch overflow in select buffer selectBuffer = BufferUtils.newIntBuffer(512); gl.glSelectBuffer(512, selectBuffer); *************** *** 339,345 **** int x, int y, int width, int height) { ! this.width = width; ! this.height = height; ! this.aspect = this.width / this.height; } --- 341,347 ---- int x, int y, int width, int height) { ! AbstractView.width = width; ! AbstractView.height = height; ! AbstractView.aspect = AbstractView.width / AbstractView.height; } *************** *** 612,624 **** - if (drawMode == LIGHTING_MODE) { - gl.glEnable(GL.GL_LIGHTING); - } ! gl.glLineWidth(1.0f); ! // draw all the edges in the model ! if (drawMode != LIGHTING_MODE) { ! Iterator eit = edges.iterator(); gl.glColor3fv(STD_LINE_COLOR); while (eit.hasNext()) { Edge e = (Edge)eit.next(); --- 614,624 ---- ! ! if (doDrawEdges) { ! gl.glLineWidth(1.0f); gl.glColor3fv(STD_LINE_COLOR); + // draw all the edges in the model + Iterator eit = edges.iterator(); while (eit.hasNext()) { Edge e = (Edge)eit.next(); *************** *** 626,652 **** } } ! gl.glEnable(GL.GL_POLYGON_OFFSET_FILL); ! gl.glPolygonOffset(1.0f, 1.0f); ! gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_FILL); ! // 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 (!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); ! } ! } ! } } - gl.glDisable(GL.GL_POLYGON_OFFSET_FILL); } else { --- 626,663 ---- } } ! ! switch (drawMode) { ! case LIGHTING_MODE: { ! gl.glEnable(GL.GL_LIGHTING); ! gl.glEnable(GL.GL_POLYGON_OFFSET_FILL); ! gl.glPolygonOffset(1.0f, 1.0f); ! gl.glEnable(GL.GL_CULL_FACE); ! ! 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); ! 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); ! gl.glDisable(GL.GL_POLYGON_OFFSET_FILL); ! break; ! } } } else { *************** *** 810,817 **** */ private void drawVertexHit(Vertex v) { ! gl.glPushMatrix(); ! gl.glTranslated(v.getX(), v.getY(), v.getZ()); ! glu.gluSphere(ball, 0.5, 8, 8); ! gl.glPopMatrix(); } --- 821,835 ---- */ private void drawVertexHit(Vertex v) { ! // TODO draw a point ! gl.glPointSize(7.0f); ! gl.glBegin(GL.GL_POINTS); ! gl.glVertex3d(v.getX(), v.getY(), v.getZ()); ! gl.glEnd(); ! gl.glPointSize(1.0f); ! ! //gl.glPushMatrix(); ! //gl.glTranslated(v.getX(), v.getY(), v.getZ()); ! //glu.gluSphere(ball, 0.5, 8, 8); ! //gl.glPopMatrix(); } *************** *** 839,852 **** private void drawSurfaces(GLDrawable gld) { Set surfaces = Project.getInstance().getSurfaces(); GL gl = gld.getGL(); ! GLU glu = gld.getGLU(); ! Iterator it = surfaces.iterator(); - gl.glColor3fv(STD_LINE_COLOR); while (it.hasNext()) { Surface s = (Surface)it.next(); ! gl.glPushName(s.getId().intValue()); ! drawSurface(s); ! gl.glPopName(); } } --- 857,877 ---- private void drawSurfaces(GLDrawable gld) { Set surfaces = Project.getInstance().getSurfaces(); + Collection selection = glv.getTool().getSelection(); GL gl = gld.getGL(); ! Iterator it = surfaces.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); ! } ! } } } *************** *** 1011,1019 **** objectTable = null; } /** * Processes the select buffer ! * @return the ID of the closest hit and -1 of no hit. */ ! private int processSelect() { //Processing hits int bufferOffset = 0; --- 1036,1046 ---- objectTable = null; } + + /** * Processes the select buffer ! * @return the ID of the closest hit and -1 if no hit. */ ! private int processSelectSimple() { //Processing hits int bufferOffset = 0; *************** *** 1046,1049 **** --- 1073,1150 ---- /** + * Processes the select buffer + * @return the ID of the closest hit and -1 if no hit. + */ + private Object processSelect() { + //Processing hits + // TODO Find vertices + int bufferOffset = 0; + int names = 0; + long zMax = 0xFFFFFFFFL; + double nearest = 1.0; + int id = -1; + + Object closest = null; + Object current = null; + + Set vertices = new HashSet(); + + for (int i = 0; i < hits; i++) { + names = selectBuffer.get(bufferOffset); + if (names > 0) { + bufferOffset++; + long z1 = 0xFFFFFFFFL & selectBuffer.get(bufferOffset); + long z2 = 0xFFFFFFFFL & selectBuffer.get(bufferOffset + 1); + double near = (double) z1 / (double) zMax; + double far = (double) z2 / (double) zMax; + + bufferOffset += 2; + id = selectBuffer.get(bufferOffset); + current = getName(id); + if (current instanceof Vertex) { + vertices.add(current); + } + if (near < nearest) { + nearest = near; + closest = current; + } + bufferOffset += names; + } else { + bufferOffset += 3; + } + } + if (closest instanceof Surface) { + Surface surface = (Surface) closest; + CoordinateSystem system = surface.coordinateSystem(); + Iterator iter = vertices.iterator(); + while (iter.hasNext()) { + // TODO Find the clost point measured as XY distance in + // the closest surface + Vertex v = (Vertex) iter.next(); + + // Test if v is in the same plane as the closest surface + Vertex vv = system.translate(v); + + if (Math.abs(vv.getZ()) < 0.00000000001) { + return v; + } + } + + } + if (closest instanceof Edge) { + Edge edge = (Edge) closest; + if (vertices.contains(edge.getFrom())) { + return edge.getFrom(); + } + if (vertices.contains(edge.getTo())) { + return edge.getTo(); + } + } + return closest; + } + + + + /** * Gets id of the object under a point. For use in selection. * @param x the x coordinate of the point in mouse coordinates *************** *** 1061,1073 **** //repainting to get selection buffer glv.repaint(true); ! id = processSelect(); ! if (id != -1) { ! Object o = getName(id); ! clearNames(); ! return o; ! } else { ! clearNames(); ! return null; ! } } --- 1162,1169 ---- //repainting to get selection buffer glv.repaint(true); ! ! Object o = processSelect(); ! clearNames(); ! return o; } Index: View.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/view/View.java,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** View.java 28 Oct 2005 12:18:58 -0000 1.14 --- View.java 30 Oct 2005 15:55:40 -0000 1.15 *************** *** 50,53 **** --- 50,59 ---- /** Surface color for all not selected surfaces */ public static final float[] SURFACE_COLOR = new float[] {0.93f, 0.93f, 0.93f}; + + /** 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 */ |