Thread: [Bprocessor-commit] gl/src/net/sourceforge/bprocessor/gl/tool Protractor.java, 1.8, 1.9
Status: Pre-Alpha
Brought to you by:
henryml
From: Michael L. <he...@us...> - 2007-11-15 07:17:29
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv22874/src/net/sourceforge/bprocessor/gl/tool Modified Files: Protractor.java Log Message: Protractor work Index: Protractor.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/Protractor.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** Protractor.java 14 Nov 2007 10:34:29 -0000 1.8 --- Protractor.java 15 Nov 2007 07:17:32 -0000 1.9 *************** *** 18,21 **** --- 18,22 ---- import net.sourceforge.bprocessor.gl.model.GlObject; import net.sourceforge.bprocessor.gl.view.View; + import net.sourceforge.bprocessor.model.Camera; import net.sourceforge.bprocessor.model.CoordinateSystem; import net.sourceforge.bprocessor.model.Edge; *************** *** 34,37 **** --- 35,40 ---- private Protract protract; + private Vertex normal; + private Vertex base; /** *************** *** 70,76 **** edges.add(line); feedback(edges); } else { feedback(new LinkedList()); ! protract = new Protract(current.vertex()); glv.getView().addGlObjects3D(protract); } --- 73,94 ---- edges.add(line); feedback(edges); + Vertex i = current.vertex().minus(start.vertex()); + i.normalize(); + Vertex j = normal.cross(i); + protract = new Protract(start.vertex(), i, j); + glv.getView().addGlObjects3D(protract); } else { feedback(new LinkedList()); ! CoordinateSystem system; ! Surface surface = View.getLastSurface(); ! if (surface != null) { ! system = surface.coordinateSystem(); ! system = system.plane().coordinateSystem(); ! } else { ! system = Project.getInstance().getActiveCoordinateSystem(); ! } ! Vertex i = system.getI(); ! Vertex j = system.getJ(); ! protract = new Protract(current.vertex(), i, j); glv.getView().addGlObjects3D(protract); } *************** *** 107,117 **** if (start == null) { start = current; ! CoordinateSystem system = Project.getInstance().getActiveCoordinateSystem(); ! system = system.copy(start.vertex()); ! Plane plane = system.plane(); Surface surface = View.getLastSurface(); if (surface != null) { ! plane = surface.plane(); } lockingPlane = plane; lock = true; --- 125,138 ---- if (start == null) { start = current; ! CoordinateSystem system; Surface surface = View.getLastSurface(); if (surface != null) { ! system = surface.coordinateSystem(); ! system = system.plane().coordinateSystem(); ! } else { ! system = Project.getInstance().getActiveCoordinateSystem(); } + Plane plane = system.plane(); + normal = system.getN(); lockingPlane = plane; lock = true; *************** *** 149,152 **** --- 170,174 ---- glv.getView().removeGlObjects3D(protract); protract = null; + base = null; } } *************** *** 157,186 **** public static class Protract implements GlObject { private Vertex origin; /** * Constructs a Protract * @param origin Vertex */ ! public Protract(Vertex origin) { this.origin = origin; } /** {@inheritDoc} */ public void draw(GL gl) { ! gl.glPushMatrix(); ! gl.glTranslated(origin.getX(), origin.getY(), origin.getZ()); ! double radius = 1; ! double n = 24; gl.glLineWidth(1.5f); gl.glColor3fv(View.CONSTRUCTOR_COLOR, 0); ! gl.glBegin(GL.GL_LINE_LOOP); ! for (int i = 0; i < n; i++) { ! double angle = 2 * Math.PI * i / n; ! double x = Math.cos(angle) * radius; ! double y = Math.sin(angle) * radius; ! gl.glVertex3d(x, y, 0); } - gl.glEnd(); - gl.glPopMatrix(); } --- 179,249 ---- public static class Protract implements GlObject { private Vertex origin; + private Vertex u; + private Vertex v; /** * Constructs a Protract * @param origin Vertex + * @param i Vertex + * @param j Vertex */ ! public Protract(Vertex origin, Vertex i, Vertex j) { this.origin = origin; + this.u = i; + this.v = j; + } + + private Vertex radian(double radius, double angle) { + double x = Math.cos(angle) * radius; + double y = Math.sin(angle) * radius; + Vertex p = origin.add(u.scale(x).add(v.scale(y))); + return p; } /** {@inheritDoc} */ public void draw(GL gl) { ! Camera camera = Project.getInstance().getCurrentCamera(); ! double distance = camera.distance(origin); ! double radius = 3 * distance; ! double n = 36; gl.glLineWidth(1.5f); gl.glColor3fv(View.CONSTRUCTOR_COLOR, 0); ! { ! gl.glBegin(GL.GL_LINE_LOOP); ! for (int i = 0; i < n; i++) { ! double angle = 2 * Math.PI * i / n; ! Vertex p = radian(radius, angle); ! gl.glVertex3d(p.getX(), p.getY(), p.getZ()); ! } ! gl.glEnd(); ! gl.glBegin(GL.GL_LINE_LOOP); ! for (int i = 0; i < n; i++) { ! double angle = 2 * Math.PI * i / n; ! Vertex p = radian(radius * 0.6, angle); ! gl.glVertex3d(p.getX(), p.getY(), p.getZ()); ! } ! gl.glEnd(); ! } ! { ! Vertex a = radian(radius, 0.1); ! Vertex b = radian(radius * 0.85, 0); ! Vertex c = radian(radius, -0.1); ! gl.glBegin(GL.GL_TRIANGLES); ! gl.glVertex3d(a.getX(), a.getY(), a.getZ()); ! gl.glVertex3d(b.getX(), b.getY(), b.getZ()); ! gl.glVertex3d(c.getX(), c.getY(), c.getZ()); ! gl.glEnd(); ! } ! { ! gl.glBegin(GL.GL_LINES); ! for (int i = 0; i < 36; i++) { ! double angle = 2 * Math.PI * i / 36; ! Vertex p = radian(radius, angle); ! Vertex q = radian(radius * 0.95, angle); ! gl.glVertex3d(p.getX(), p.getY(), p.getZ()); ! gl.glVertex3d(q.getX(), q.getY(), q.getZ()); ! } ! gl.glEnd(); } } |