error += olderror;
}
+ /*
public Vertex hack(GL gl, Point mouse) {
double dist = Double.MAX_VALUE;
Vertex cur = null;
}
return cur;
}
+ */
public float averageTriangleArea() {
int count = 0;
public void mouseClicked(MouseEvent e) { }
public void mouseEntered(MouseEvent e) { }
public void mouseExited(MouseEvent e) { }
- public void mousePressed(MouseEvent e) { }
- public void mouseReleased(MouseEvent e) { }
+ public void mousePressed(MouseEvent e) {
+ clickPoint = getMouse();
+ clickClosest = closest == null ? null : closest.getPoint();
+ }
+ public void mouseReleased(MouseEvent e) {
+ clickPoint = null;
+ clickClosest = null;
+ }
+
+ Point clickPoint = null;
+ Point clickClosest = null;
int mousex;
int mousey;
float angley = 0;
public void mouseDragged(MouseEvent e) {
if (shift) {
+ /*
tx += (mousex - e.getX())/(float)20;
ty += (mousey - e.getY())/(float)20;
+ */
+ if (closest != null && lastGL != null && projection != null && clickClosest != null) {
+ synchronized(safeTriangles) {
+ Vec d1 = projection.inverse().times(getMouse()).minus(projection.inverse().times(clickPoint));
+ 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);
+ }
+ }
} else {
anglex -= mousex - e.getX();
angley += mousey - e.getY();
display(gld);
}
+ private GL lastGL = null;
+
public int temps;
public int accepts;
public int vertss;
g.fillRect(140, 65+top, vertss, 10);
GL gl = drawable.getGL();
+ lastGL = gl;
GLU glu = new GLU();
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
gl.glPointSize(5.0f);
gl.glBegin(gl.GL_POINTS);
closest.getPoint().glVertex(gl);
gl.glEnd();
+ /*
Mesh.Vertex v2 = closest.hack(gl, getMouse());
gl.glBegin(GL.GL_LINES);
closest.getPoint().glVertex(gl);
if (v2 != null) v2.getPoint().glVertex(gl);
gl.glEnd();
+ */
}
gl.glFlush();
gl.glColor3f(0,0,0);
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
double dist = Double.MAX_VALUE;
- closest = null;
+ if (clickPoint==null) closest = null;
+ projection = Matrix.getProjectionMatrix(gl);
synchronized(safeTriangles) {
for(Mesh.T t : safeTriangles)
t.glTriangle(gl, null);
gl.glEnd();
gl.glFlush();
- Point projected = p.glProject(gl);
+ Point projected = projection.times(p);
int x = (int)projected.x;
int y = (int)projected.y;
gl.glReadPixels(x-1, y-1, 3, 3, gl.GL_RGB, gl.GL_UNSIGNED_BYTE, buf);
p.glVertex(gl);
gl.glEnd();
y = glcanvas.getHeight()-y;
- if (closest==null || (x-mousex)*(x-mousex)+(y-mousey)*(y-mousey) < dist) {
- dist = (x-mousex)*(x-mousex)+(y-mousey)*(y-mousey);
- closest = v;
+ if (clickPoint==null) {
+ if (closest==null || (x-mousex)*(x-mousex)+(y-mousey)*(y-mousey) < dist) {
+ dist = (x-mousex)*(x-mousex)+(y-mousey)*(y-mousey);
+ closest = v;
+ }
}
}
}
*/
}
Mesh.Vertex closest = null;
+ Matrix projection = null;
// I copied this method without changes from the mentioned base class.
// It extracts the data in the selection buffer and writes it on the console.
green -= .12f;
blue -= .15f;
- if (triangles) switch(t.color/*class*/) {
+ /*
+ if (triangles) switch(t.color) {
case 0: gl.glColor4f((float)0.25, (float)0.25, (float)0.75, (float)0.3); break;
case 1: gl.glColor4f((float)0.25, (float)0.75, (float)0.25, (float)0.3); break;
case 2: gl.glColor4f((float)0.75, (float)0.25, (float)0.25, (float)0.3); break;
case 5: gl.glColor4f((float)0.25, (float)0.75, (float)0.75, (float)0.3); break;
case 6: gl.glColor4f((float)0.75, (float)0.25, (float)0.75, (float)0.3); break;
}
+ */
- gl.glColor4f((float)0.25, (float)0.25, (float)0.75, (float)0.3);
+ gl.glColor4f((float)(0.25+(0.05*t.color)),
+ (float)(0.25+(0.05*t.color)),
+ (float)(0.75+(0.05*t.color)),
+ (float)0.3);
//if (t.v1().visible && t.v2().visible && t.v3().visible) continue;
/*
package edu.berkeley.qfat.geom;
+import javax.media.opengl.*;
// FEATURE: precompute/cache determinant?
/** the identity matrix */
public static final Matrix NEGATIVE_ONE = new Matrix(-1,0,0,0,0,-1,0,0,0,0,-1,0,0,0,0,1);
+ public Matrix(double a, double b, double c, double d, double e, double f, double g,
+ double h, double i, double j, double k, double l, double m, double n, double o, double p) {
+ this((float)a, (float)b, (float)c, (float)d,
+ (float)e, (float)f, (float)g, (float)h,
+ (float)i, (float)j, (float)k, (float)l,
+ (float)m, (float)n, (float)o, (float)p);
+ }
+
public Matrix(float a, float b, float c, float d, float e, float f, float g,
float h, float i, float j, float k, float l, float m, float n, float o, float p) {
this.a = a; this.b = b; this.c = c; this.d = d; this.e = e; this.f = f; this.g = g; this.h = h; this.i = i;
/** discards bottom row */
public Point times(Point p) {
// discards bottom row
- return new Point(a*p.x + b*p.y + c*p.z + d,
- e*p.x + f*p.y + g*p.z + h,
- i*p.x + j*p.y + k*p.z + l);
+ double x = a*p.x + b*p.y + c*p.z + d;
+ double y = e*p.x + f*p.y + g*p.z + h;
+ double z = i*p.x + j*p.y + k*p.z + l;
+ double q = m*p.x + n*p.y + o*p.z + this.p;
+ return new Point(x/q, y/q, z/q);
}
/** discards bottom row */
Float.floatToIntBits(o) ^
Float.floatToIntBits(p);
}
+
+ public static Matrix getProjectionMatrix(GL gl) {
+ int view[] = new int[4];
+ double mvmatrix[] = new double[16];
+ double projmatrix[] = new double[16];
+ gl.glGetIntegerv(GL.GL_VIEWPORT, view, 0);
+ gl.glGetDoublev(GL.GL_MODELVIEW_MATRIX, mvmatrix, 0);
+ gl.glGetDoublev(GL.GL_PROJECTION_MATRIX, projmatrix, 0);
+ Matrix m = new Matrix(mvmatrix[0],
+ mvmatrix[4],
+ mvmatrix[8],
+ mvmatrix[12],
+ mvmatrix[1],
+ mvmatrix[5],
+ mvmatrix[9],
+ mvmatrix[13],
+ mvmatrix[2],
+ mvmatrix[6],
+ mvmatrix[10],
+ mvmatrix[14],
+ mvmatrix[3],
+ mvmatrix[7],
+ mvmatrix[11],
+ mvmatrix[15]);
+ Matrix p = new Matrix(projmatrix[0],
+ projmatrix[4],
+ projmatrix[8],
+ projmatrix[12],
+ projmatrix[1],
+ projmatrix[5],
+ projmatrix[9],
+ projmatrix[13],
+ projmatrix[2],
+ projmatrix[6],
+ projmatrix[10],
+ projmatrix[14],
+ projmatrix[3],
+ projmatrix[7],
+ projmatrix[11],
+ projmatrix[15]);
+ Matrix z =
+ new Matrix(0.5*view[2], 0, 0, view[0]+view[2]*0.5,
+ 0, 0.5*view[3], 0, view[1]+view[3]*0.5,
+ 0, 0, 0.5, 0.5,
+ 0, 0, 0, 1);
+ return z.times(p).times(m);
+ }
+
}
public float getMinY() { return y; }
public float getMaxZ() { return z; }
public float getMinZ() { return z; }
-
- public Point glProject(GL gl) {
- Point p = this;
- int viewport[] = new int[4];
- double mvmatrix[] = new double[16];
- double projmatrix[] = new double[16];
- double wcoord[] = new double[4];
- gl.glGetIntegerv(GL.GL_VIEWPORT, viewport, 0);
- gl.glGetDoublev(GL.GL_MODELVIEW_MATRIX, mvmatrix, 0);
- gl.glGetDoublev(GL.GL_PROJECTION_MATRIX, projmatrix, 0);
- GLU glu = new GLU();
- glu.gluProject(p.x, p.y, p.z, mvmatrix, 0, projmatrix, 0, viewport, 0, wcoord, 0);
- return new Point(wcoord[0], wcoord[1], 0);
- }
}
public float getMaxZ() { return Math.max(p1.z, p2.z); }
public float getMinZ() { return Math.min(p1.z, p2.z); }
- public Segment glProject(GL gl) { return new Segment(p1.glProject(gl), p2.glProject(gl)); }
+ public double distance(Point p) {
+ throw new RuntimeException("not yet implemented");
+ }
}
package edu.berkeley.qfat.geom;
import javax.media.opengl.*;
+import javax.media.opengl.glu.*;
/** vector in 3-space; immutable */
public final class Vec {
public Vec(Point p1, Point p2) { this(p2.x-p1.x, p2.y-p1.y, p2.z-p1.z); }
public Vec cross(Vec v) { return new Vec(y*v.z-z*v.y, z*v.x-x*v.z, x*v.y-y*v.x); }
public Vec plus(Vec v) { return new Vec(x+v.x, y+v.y, z+v.z); }
+ public Point plus(Point p) { return p.plus(this); }
public Vec minus(Vec v) { return new Vec(x-v.x, y-v.y, z-v.z); }
public Vec norm() { return mag()==0 ? this : div(mag()); }
public float mag() { return (float)Math.sqrt(x*x+y*y+z*z); }