public abstract class Viewer implements GLEventListener, MouseListener, MouseMotionListener, KeyListener, MouseWheelListener {
Mesh.Vertex closest = null;
- Matrix projection = null;
public Mesh tile = new Mesh(false);
public Mesh goal = new Mesh(false);
+ private Matrix projection = null;
+
JFrame f;
GLCanvas glcanvas;
Point clickPoint = null;
}
public abstract void _display(GLAutoDrawable drawable, GL gl);
- public void display(GLAutoDrawable drawable) {
+ public final void display(GLAutoDrawable drawable) {
GL gl = drawable.getGL();
_display(drawable, gl);
- this.projection = Matrix.getProjectionMatrix(gl);
+ projection = Matrix.getProjectionMatrix(gl);
+ }
+
+ protected synchronized void updateVisibility(GL gl, Mesh mesh) {
+ Matrix projection = Matrix.getProjectionMatrix(gl);
+ IntBuffer buf = ByteBuffer.allocateDirect(9*4*4).order(ByteOrder.nativeOrder()).asIntBuffer();
+ gl.glFlush();
+ gl.glDrawBuffer(GL.GL_BACK);
+ gl.glReadBuffer( GL.GL_BACK );
+ gl.glPixelStorei( GL.GL_PACK_ALIGNMENT, 1);
+ gl.glFlush();
+ gl.glDisable(GL.GL_LIGHTING);
+ gl.glShadeModel(GL.GL_FLAT);
+ gl.glColor3f(0,0,0);
+ gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
+ for(Mesh.T t : mesh) t.glTriangle(gl, null);
+ for(Mesh.Vertex v : mesh.vertices()) {
+ Point p = v.getPoint();
+ gl.glColor3f(1,1,1);
+ gl.glBegin(gl.GL_POINTS);
+ p.glVertex(gl);
+ gl.glEnd();
+ gl.glFlush();
+
+ Point projected = projection.times(p);
+ gl.glReadPixels((int)projected.x-1, (int)projected.y-1, 3, 3, gl.GL_RGB, gl.GL_UNSIGNED_BYTE, buf);
+
+ boolean vis = false;
+ for(int j=0; j<9*4; j++) vis |= buf.get(j)!=0;
+ v.visible = vis;
+ if (vis) {
+ gl.glColor3f(0,0,0);
+ gl.glBegin(gl.GL_POINTS);
+ p.glVertex(gl);
+ gl.glEnd();
+ }
+ }
+ gl.glShadeModel(GL.GL_SMOOTH);
+ gl.glEnable(GL.GL_LIGHTING);
+ gl.glDrawBuffer(GL.GL_FRONT);
}
+
/** return the position of the mouse as a point in window-space */
public Point getMouse() {
return new Point(mousex, glcanvas.getHeight()-mousey, 0);
Vec delta = d1.plus(clickClosest).minus(closest.getPoint());
//System.out.println(delta + " " + closest.getPoint());
System.out.println(getMouse().minus(clickPoint));
- closest.move(Matrix.translate(delta), true);
+ closest.move(Matrix.translate(delta), false);
}
}
} else {