[Bprocessor-commit] gl/src/net/sourceforge/bprocessor/gl/view AbstractView.java,1.6,1.7
Status: Pre-Alpha
Brought to you by:
henryml
From: Nordholt <nor...@us...> - 2005-08-17 10:58:20
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/view In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16706 Modified Files: AbstractView.java Log Message: getObjectAtPoint now supports selection Index: AbstractView.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/view/AbstractView.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** AbstractView.java 17 Aug 2005 08:56:08 -0000 1.6 --- AbstractView.java 17 Aug 2005 10:58:11 -0000 1.7 *************** *** 22,28 **** --- 22,31 ---- import java.util.Set; + import java.nio.IntBuffer; + import net.java.games.jogl.GL; import net.java.games.jogl.GLDrawable; import net.java.games.jogl.GLU; + import net.java.games.jogl.util.BufferUtils; import org.apache.log4j.Logger; *************** *** 63,66 **** --- 66,74 ---- 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0}; + /** Select mode for selecting edges */ + private static final int EDGES = 0; + + /** Select mode for selecting surfaces */ + private static final int SURFACES = 1; /** The width of the window */ *************** *** 103,109 **** protected GLU glu = null; - /** The GLDrawable */ - protected GLDrawable drawable = null; - /** The zoomFactor in the parent view */ protected double zoomFactor = 1.0; --- 111,114 ---- *************** *** 112,117 **** protected GLView glv = null; ! /** The frames per second counter */ ! protected int fps = 0; /** --- 117,137 ---- protected GLView glv = null; ! /** Flag for when to use SELECT render mode */ ! protected int picking = 0; ! ! /** The last amount of hits from SELECT render mode */ ! protected int hits = 0; ! ! /** The selection buffer */ ! protected IntBuffer selectBuffer; ! ! /** The x-coordinate of last selection */ ! protected double x; ! ! /** The y-coordinate of last selection */ ! protected double y; ! ! /** The mode of selecting. Either edges or surfaces */ ! private int selectMode; /** *************** *** 133,136 **** --- 153,157 ---- gl = gld.getGL(); glu = gld.getGLU(); + this.width = gld.getSize().getWidth(); this.height = gld.getSize().getHeight(); *************** *** 138,145 **** this.aspect = this.width / this.height; - drawable = gld; - gl.glEnable(GL.GL_DEPTH_TEST); gl.glEnable(GL.GL_BLEND); gl.glClearColor(0.7f, 0.7f, 0.7f, 0.0f); gl.glViewport(0, 0, (int)width, (int)height); --- 159,165 ---- this.aspect = this.width / this.height; gl.glEnable(GL.GL_DEPTH_TEST); gl.glEnable(GL.GL_BLEND); + gl.glClearColor(0.7f, 0.7f, 0.7f, 0.0f); gl.glViewport(0, 0, (int)width, (int)height); *************** *** 157,165 **** glu = gld.getGLU(); ! drawable = gld; ! gl.glViewport(0, 0, (int)width, (int)height); ! camera(gld); gl.glLineWidth(1.0f); --- 177,191 ---- glu = gld.getGLU(); ! int[] mode = new int[1]; gl.glViewport(0, 0, (int)width, (int)height); ! ! if (picking > 0) { ! selectBuffer = BufferUtils.newIntBuffer(512); ! gl.glSelectBuffer(512, selectBuffer); ! gl.glRenderMode(GL.GL_SELECT); ! } ! camera(gld); + picking = 0; gl.glLineWidth(1.0f); *************** *** 170,179 **** gl.glLineWidth(2.0f); drawAll(gld); long after = System.currentTimeMillis(); long ellapsed = after - before; - //StringBuffer buffer = new StringBuffer(); - //buffer.append("ellapsed: "); - //buffer.append(ellapsed); - //log.info(buffer); } --- 196,208 ---- gl.glLineWidth(2.0f); drawAll(gld); + gl.glGetIntegerv(GL.GL_RENDER_MODE, mode); + if (mode[0] == GL.GL_SELECT) { + gl.glFlush(); + hits = gl.glRenderMode(GL.GL_RENDER); + glv.repaint(); + } + long after = System.currentTimeMillis(); long ellapsed = after - before; } *************** *** 222,322 **** Set surfaces = SurfaceFacade.getInstance().findAll(); Set edges = EdgeFacade.getInstance().findAll(); gl = gld.getGL(); glu = gld.getGLU(); ! gl.glInitNames(); ! 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); } ! } ! ! // draw activeEdge different if it is parallel with axis ! if (activeEdge != null) { ! Vertex to = activeEdge.getTo(); ! 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); ! gl.glLineWidth(1.0f); ! gl.glVertex3d(from.getX(), from.getY(), from.getZ()); ! gl.glVertex3d(to.getX(), to.getY(), to.getZ()); ! gl.glEnd(); ! } ! ! // draw alignment line ! 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); - gl.glVertex3d(alignPoint[0], alignPoint[1], alignPoint[2]); - gl.glVertex3d(alignVertex.getX(), alignVertex.getY(), alignVertex.getZ()); - gl.glEnd(); - } - - // draw snap point if any - if (snapVertex != null) { - gl.glColor3d(0.0, 1.0, 0.0); - gl.glPointSize(5.0f); - gl.glBegin(GL.GL_POINTS); - gl.glVertex3d(snapVertex.getX(), snapVertex.getY(), snapVertex.getZ()); - gl.glEnd(); - gl.glPointSize(1.0f); - } ! // draw selected vertex ! if (selectedVertex != null) { ! gl.glColor4dv(SELECTED_COLOR); ! gl.glPointSize(5.0f); ! gl.glBegin(GL.GL_POINTS); ! selectedVertex = VertexFacade.getInstance().findById(selectedVertex.getId()); ! gl.glVertex3d(selectedVertex.getX(), selectedVertex.getY(), selectedVertex.getZ()); ! gl.glEnd(); ! gl.glPointSize(1.0f); ! } ! ! // draw selected edge ! if (selectedEdge != null) { ! gl.glColor4dv(SELECTED_COLOR); ! selectedEdge = EdgeFacade.getInstance().findById(selectedEdge.getId()); ! Vertex to = selectedEdge.getTo(); ! Vertex from = selectedEdge.getFrom(); ! gl.glBegin(GL.GL_LINES); ! gl.glVertex3d(to.getX(), to.getY(), to.getZ()); ! gl.glVertex3d(from.getX(), from.getY(), from.getZ()); ! gl.glEnd(); ! } ! // draw selected surface ! if (selectedSurface != null) { ! gl.glColor4dv(SELECTED_COLOR); ! selectedSurface = SurfaceFacade.getInstance().findById(selectedSurface.getId()); ! drawSurface(selectedSurface); } } --- 251,380 ---- Set surfaces = SurfaceFacade.getInstance().findAll(); Set edges = EdgeFacade.getInstance().findAll(); + int[] mode = new int[1]; + gl.glGetIntegerv(GL.GL_RENDER_MODE, mode); + gl = gld.getGL(); glu = gld.getGLU(); ! gl.glInitNames(); ! if (mode[0] != GL.GL_SELECT) { ! 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); ! } } ! ! // draw activeEdge different if it is parallel with axis ! if (activeEdge != null) { ! Vertex to = activeEdge.getTo(); ! 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); ! gl.glLineWidth(1.0f); ! gl.glVertex3d(from.getX(), from.getY(), from.getZ()); ! gl.glVertex3d(to.getX(), to.getY(), to.getZ()); ! gl.glEnd(); } ! ! // draw alignment line ! 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); ! gl.glVertex3d(alignPoint[0], alignPoint[1], alignPoint[2]); ! gl.glVertex3d(alignVertex.getX(), alignVertex.getY(), alignVertex.getZ()); ! gl.glEnd(); } ! // draw snap point if any ! if (snapVertex != null) { ! gl.glColor3d(0.0, 1.0, 0.0); ! gl.glPointSize(5.0f); ! gl.glBegin(GL.GL_POINTS); ! gl.glVertex3d(snapVertex.getX(), snapVertex.getY(), snapVertex.getZ()); ! gl.glEnd(); ! gl.glPointSize(1.0f); ! } ! ! // draw selected vertex ! if (selectedVertex != null) { ! gl.glColor4dv(SELECTED_COLOR); ! gl.glPointSize(5.0f); ! gl.glBegin(GL.GL_POINTS); ! selectedVertex = VertexFacade.getInstance().findById(selectedVertex.getId()); ! gl.glVertex3d(selectedVertex.getX(), selectedVertex.getY(), selectedVertex.getZ()); ! gl.glEnd(); ! gl.glPointSize(1.0f); ! } ! ! // draw selected edge ! if (selectedEdge != null) { ! gl.glColor4dv(SELECTED_COLOR); ! selectedEdge = EdgeFacade.getInstance().findById(selectedEdge.getId()); ! Vertex to = selectedEdge.getTo(); ! Vertex from = selectedEdge.getFrom(); ! gl.glBegin(GL.GL_LINES); ! gl.glVertex3d(to.getX(), to.getY(), to.getZ()); ! gl.glVertex3d(from.getX(), from.getY(), from.getZ()); ! gl.glEnd(); ! } ! // draw selected surface ! if (selectedSurface != null) { ! gl.glColor4dv(SELECTED_COLOR); ! selectedSurface = SurfaceFacade.getInstance().findById(selectedSurface.getId()); ! drawSurface(selectedSurface); ! } ! } else { ! if (selectMode == SURFACES) { ! Iterator it = surfaces.iterator(); ! gl.glColor4dv(SURFACE_COLOR); ! while (it.hasNext()) { ! Surface s = (Surface)it.next(); ! int name = s.getId().intValue(); ! gl.glPushName(name); ! drawSurface(s); ! gl.glPopName(); ! } ! } ! ! if (selectMode == EDGES) { ! Iterator it = edges.iterator(); ! gl.glColor3dv(STD_LINE_COLOR); ! while (it.hasNext()) { ! Edge e = (Edge)it.next(); ! int name = e.getId().intValue(); ! gl.glPushName(name); ! drawEdge(e); ! gl.glPopName(); ! } ! } } } *************** *** 368,372 **** Vertex from = e.getFrom(); int name = e.getId().intValue(); - gl.glPushName(name); if (to != null && from != null) { gl.glBegin(GL.GL_LINE_STRIP); --- 426,429 ---- *************** *** 375,379 **** gl.glEnd(); } - gl.glPopName(); } --- 432,435 ---- *************** *** 566,576 **** /** ! * Gets id of the object under a point. For use in 3D selection. ! * @param x the x coordinate of the point ! * @param y the y coordinate of the point * @return a Long id of the object under the point, null if no object is there */ ! public Long getObjectAtPoint(double x, double y) { ! return null; } --- 622,692 ---- /** ! * Processes the select buffer ! * @return the ID of the closest hit ! */ ! private Long processSelect() { ! //Processing hits ! int bufferOffset = 0; ! int names = 0; ! int minZ = Integer.MAX_VALUE; ! int z1; ! int z2; ! Long id = null; ! Integer intId; ! for (int i = 0; i < hits; i++) { ! names = selectBuffer.get(bufferOffset); ! if (names > 0) { ! bufferOffset++; ! z1 = selectBuffer.get(bufferOffset); ! z2 = selectBuffer.get(bufferOffset + 1); ! bufferOffset += 2; ! if (z1 < minZ) { ! minZ = z1; ! id = new Long((new Integer(selectBuffer.get(bufferOffset))).longValue()); ! } ! bufferOffset += names; ! } else { ! bufferOffset += 3; ! } ! } ! ! if (id != null) { ! return id; ! } else { ! return null; ! } ! } ! ! /** ! * Gets id of the object under a point. For use in selection. ! * @param x the x coordinate of the point in mouse coordinates ! * @param y the y coordinate of the point in mouse coordinates * @return a Long id of the object under the point, null if no object is there */ ! public Object getObjectAtPoint(double x, double y) { ! Long id = null; ! this.x = x; ! this.y = y; ! //indicating that I am trying to pick(used in camera) ! picking = 10; ! selectMode = EDGES; ! //repainting to get selection buffer ! glv.repaint(true); ! id = processSelect(); ! if (id != null) { ! Edge e = EdgeFacade.getInstance().findById(id); ! return e; ! } ! //indicating that I am trying to pick(used in camera) ! picking = 10; ! selectMode = SURFACES; ! //repainting to get selection buffer ! glv.repaint(true); ! id = processSelect(); ! if (id != null) { ! Surface s = SurfaceFacade.getInstance().findById(id); ! return s; ! } ! return null; } |