[Bprocessor-commit] gl/src/net/sourceforge/bprocessor/gl/tool RotationToolB.java, 1.3, 1.4 Abstract
Status: Pre-Alpha
Brought to you by:
henryml
From: Michael L. <he...@us...> - 2010-02-12 11:44:34
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool In directory sfp-cvsdas-2.v30.ch3.sourceforge.com:/tmp/cvs-serv27987/src/net/sourceforge/bprocessor/gl/tool Modified Files: RotationToolB.java AbstractPencil.java Log Message: Index: RotationToolB.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/RotationToolB.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** RotationToolB.java 5 Feb 2010 15:00:31 -0000 1.3 --- RotationToolB.java 12 Feb 2010 11:44:24 -0000 1.4 *************** *** 9,13 **** --- 9,16 ---- import java.awt.Cursor; + import java.awt.Insets; + import java.awt.event.ActionEvent; import java.awt.event.MouseEvent; + import java.net.URL; import java.util.Collection; import java.util.Collections; *************** *** 16,19 **** --- 19,29 ---- import java.util.List; + import javax.swing.AbstractAction; + import javax.swing.Action; + import javax.swing.ButtonGroup; + import javax.swing.ImageIcon; + import javax.swing.JComponent; + import javax.swing.JToggleButton; + import net.sourceforge.bprocessor.gl.Editor; import net.sourceforge.bprocessor.model.CoordinateSystem; *************** *** 83,103 **** } ! private void rotate(double angle) { ! if (!Double.isNaN(angle)) { ! Vertex center = center(); ! Vertex n = normal(); ! double x = n.getX(); ! double y = n.getY(); ! double z = n.getZ(); ! reset(); ! for (Vertex current : vertices) { ! Geometry.rotate(angle, x, y, z, current, center); ! } ! for (Vertex current : vertices) { ! current.update(); ! } ! } } private void finish() { base = null; --- 93,117 ---- } ! ! private void rotateIt(Vertex center, Vertex axis, double angle, Vertex vertex) { ! Geometry.rotate(angle, axis.getX(), axis.getY(), axis.getZ(), vertex, center); ! } ! ! private Vertex rotate(Vertex axis, double angle, Vertex vector) { ! Vertex u = vector.copy(); ! Vertex zero = new Vertex(0, 0, 0); ! rotateIt(zero, axis, angle, u); ! return u; } + private void rotateIt(Vertex center, Vertex axis, double angle, Collection<Vertex> vertices) { + for (Vertex current : vertices) { + rotateIt(center, axis, angle, current); + } + for (Vertex current : vertices) { + current.update(); + } + } + private void finish() { base = null; *************** *** 107,111 **** excluded(Collections.EMPTY_LIST); } ! /** * {@inheritDoc} --- 121,125 ---- excluded(Collections.EMPTY_LIST); } ! /** * {@inheritDoc} *************** *** 122,133 **** if (system != null) { if (base != null) { ! if (mode == ONE) { ! double angle = angle(); ! if (!Double.isNaN(angle)) { ! rotate(angle); ! } ! } else { ! System.out.println("handle case two"); ! } } } --- 136,140 ---- if (system != null) { if (base != null) { ! process(); } } *************** *** 152,168 **** if (system != null) { if (base == null) { ! if (mode == ONE) { ! base = direction(); ! } else { ! System.out.println("handle case two"); ! } } else { ! if (mode == ONE) { ! double angle = angle(); ! rotate(angle); ! finish(); ! } else { ! System.out.println("handle case two"); ! } } } else { --- 159,166 ---- if (system != null) { if (base == null) { ! base = current.vertex().copy(); } else { ! process(); ! finish(); } } else { *************** *** 185,191 **** } ! private Vertex direction() { Plane plane = system.plane(); ! Vertex vertex = plane.projection(current.vertex()); Vertex u = vertex.minus(system.getOrigin()); u.normalize(); --- 183,223 ---- } ! ! ! ! private void process() { ! Vertex center = system.getOrigin(); ! Vertex up = system.getN(); ! Vertex from = base; ! Vertex to = current.vertex(); ! ! Vertex u = from.minus(center); ! u.normalize(); ! Vertex v = to.minus(center); ! v.normalize(); ! ! double alpha = angle(up, u, v); ! ! if (mode == ONE) { ! if (!Double.isNaN(alpha)) { ! reset(); ! rotateIt(center, up, alpha, vertices); ! } ! } else if (mode == TWO) { ! u = rotate(up, alpha, u); ! Vertex axis = up.cross(u); ! double beta = angle(axis, u, v); ! ! if (!Double.isNaN(alpha) && !Double.isNaN(beta)) { ! reset(); ! rotateIt(center, up, alpha, vertices); ! rotateIt(center, axis, beta, vertices); ! } ! } ! } ! ! private Vertex direction(Vertex original) { Plane plane = system.plane(); ! Vertex vertex = plane.projection(original); Vertex u = vertex.minus(system.getOrigin()); u.normalize(); *************** *** 193,207 **** } - private Vertex center() { - return system.getOrigin(); - } - - private Vertex normal() { - return system.getN(); - } - private Vertex base() { if (base != null) { ! return base; } else { return system.getI(); --- 225,232 ---- } private Vertex base() { if (base != null) { ! return direction(base); ! } else { return system.getI(); *************** *** 209,219 **** } ! private double angle() { ! Vertex i = base(); ! Vertex u = direction(); ! if (u.isZero()) { ! return Double.NaN; ! } ! if (i.cross(u).isZero()) { return 0; --- 234,249 ---- } ! ! private Vertex project(Vertex normal, Vertex vector) { ! Vertex n = normal.copy(); ! double t = vector.dot(normal); ! n.scaleIt(t / n.length()); ! vector = vector.minus(n); ! return vector; ! } ! ! private double angle(Vertex normal, Vertex v1, Vertex v2) { ! Vertex i = project(normal, v1); ! Vertex u = project(normal, v2); if (i.cross(u).isZero()) { return 0; *************** *** 222,226 **** double angle = i.angle(u); ! double box = i.cross(u).dot(system.getN()); if (box < 0) { angle = -angle; --- 252,256 ---- double angle = i.angle(u); ! double box = i.cross(u).dot(normal); if (box < 0) { angle = -angle; *************** *** 230,233 **** --- 260,294 ---- } + private Vertex vector(Vertex point) { + Vertex v = point.minus(system.getOrigin()); + if (!v.isZero()) { + v.normalize(); + } + return v; + } + + + private Vertex axis() { + Vertex up = system.getN(); + Vertex forward; + if (base == null) { + forward = system.getI(); + } else { + forward = vector(base); + } + Vertex axis = up.cross(forward); + return axis; + } + + private double angle(Vertex axis) { + Vertex v1; + if (base == null) { + v1 = system.getI(); + } else { + v1 = vector(base); + } + return angle(axis, v1, vector(current.vertex())); + } + /** * {@inheritDoc} *************** *** 235,239 **** protected void updateLength() { if (system != null) { ! double angle = angle() * 180 / Math.PI; setLength(angle / 1000); } else { --- 296,300 ---- protected void updateLength() { if (system != null) { ! double angle = angle(system.getN()) * 180 / Math.PI; setLength(angle / 1000); } else { *************** *** 259,265 **** Vertex center = system.getOrigin(); Vertex i = base(); ! Vertex j = normal().cross(i); protract = new Protract(center, i, j, true); editor.getView().addGlObjects3D(protract); } else { showConstructors = true; --- 320,336 ---- Vertex center = system.getOrigin(); Vertex i = base(); ! Vertex j = system.getN().cross(i); protract = new Protract(center, i, j, true); editor.getView().addGlObjects3D(protract); + + + if (base != null) { + Edge e1 = new Edge(center, base); + e1.setStrippled(true); + edges.add(e1); + Edge e2 = new Edge(center, current.vertex()); + e2.setStrippled(true); + edges.add(e2); + } } else { showConstructors = true; *************** *** 288,292 **** if (protract != null) { double angle = (value * 1000) * Math.PI / 180; ! rotate(angle); finish(); } --- 359,363 ---- if (protract != null) { double angle = (value * 1000) * Math.PI / 180; ! rotateIt(system.getOrigin(), system.getN(), angle, vertices); finish(); } *************** *** 349,351 **** --- 420,471 ---- affected = null; } + + class OptionAction extends AbstractAction { + private int mode; + + /** + * Constructs option action + * @param iconname String + */ + public OptionAction(String iconname, int mode) { + ClassLoader cl = Thread.currentThread().getContextClassLoader(); + URL url = cl.getResource(iconname); + ImageIcon im = new ImageIcon(url); + putValue(Action.SMALL_ICON, im); + this.mode = mode; + }; + + /** {@inheritDoc} */ + public void actionPerformed(ActionEvent event) { + RotationToolB.this.mode = mode; + System.out.println("mode is " + mode); + } + } + + + /** + * {@inheritDoc} + */ + public List<JComponent> controls() { + List<JComponent> controls = super.controls(); + ButtonGroup group = new ButtonGroup(); + + { + JToggleButton button = new JToggleButton(new OptionAction("oneicon.gif", ONE)); + button.setMargin(new Insets(1, 1, 1, 1)); + button.setMaximumSize(button.getMinimumSize()); + button.setSelected(Editor.isMulti()); + controls.add(button); + group.add(button); + } + { + JToggleButton button = new JToggleButton(new OptionAction("twoicon.gif", TWO)); + button.setMargin(new Insets(1, 1, 1, 1)); + button.setMaximumSize(button.getMinimumSize()); + button.setSelected(Editor.isMulti()); + controls.add(button); + group.add(button); + } + return controls; + } } Index: AbstractPencil.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/AbstractPencil.java,v retrieving revision 1.113 retrieving revision 1.114 diff -C2 -d -r1.113 -r1.114 *** AbstractPencil.java 5 Feb 2010 13:32:59 -0000 1.113 --- AbstractPencil.java 12 Feb 2010 11:44:24 -0000 1.114 *************** *** 271,276 **** } - // Round off - intersection.roundIt(); return intersection; } --- 271,274 ---- |