1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
public NetworkRenderer(){
createGLNodeList();
createGLEdgeList();
}
public void init(GLAutoDrawable arg0) { /**/ }
public void display(GLAutoDrawable arg0) {
this.gl = arg0.getGL();
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
if (this.point != null) {
pickPoint(gl);
}
drawWorld(gl, GL.GL_RENDER);
gl.glFlush();
}
private void drawNodes(GL gl, int mode){
gl.glPopName();
for (int i = 0; i < this.nodes.size(); i++) {
if (mode == gl.GL_SELECT) {
gl.glLoadName(i);
gl.glPushName(i);
}
GLNode n = this.nodes.get(i);
if (this.mouse_state == this.PICKED && this.selected == i) {
if (this.point != null) {
GLU glu = new GLU();
int viewport[] = new int[4];
double mvmatrix[] = new double[16];
double projmatrix[] = new double[16];
double wcoord[] = new double[4];// wx, wy, wz;// returned xyz coords
int realy = 0;// GL y coord pos
this.gl.glGetIntegerv(GL.GL_VIEWPORT, viewport, 0);
this.gl.glGetDoublev(GL.GL_MODELVIEW_MATRIX, mvmatrix, 0);
this.gl.glGetDoublev(GL.GL_PROJECTION_MATRIX, projmatrix, 0);
realy = viewport[3] - (int) this.point.y - 1;
glu.gluUnProject((double) this.point.x, (double) realy, 0.0, //
mvmatrix, 0,//
projmatrix, 0, //
viewport, 0, //
wcoord, 0);
n.setPosition((float) wcoord[0], (float) wcoord[1]);
n.setColor(Color.GREEN);
}
} else {
n.setPosition(n.x, n.y);
n.setColor(Color.RED);
}
n.draw(gl, new GLU());
}
gl.glPopName();
}
private void drawEdges(GL gl){
for (int i = 0; i < this.edges.size(); i++) {
GLEdge e = this.edges.get(i);
e.draw(gl, new GLU());
}
}
private void drawWorld(GL gl, int mode) {
drawNodes(gl, mode);
drawEdges(gl);
}
public void reshape(GLAutoDrawable arg0, int x, int y, int w, int h) { /**/ } |
Partager