[Bprocessor-commit] gl/src/net/sourceforge/bprocessor/gl/tool Protractor.java, 1.17, 1.18
Status: Pre-Alpha
Brought to you by:
henryml
From: Michael L. <he...@us...> - 2007-11-21 15:28:44
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv655/src/net/sourceforge/bprocessor/gl/tool Modified Files: Protractor.java Log Message: plane orientation Index: Protractor.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/Protractor.java,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** Protractor.java 21 Nov 2007 13:50:53 -0000 1.17 --- Protractor.java 21 Nov 2007 15:28:46 -0000 1.18 *************** *** 102,107 **** Surface surface = View.getLastSurface(); if (surface != null) { ! system = surface.coordinateSystem(); ! system = system.plane().coordinateSystem(); } else { system = Project.getInstance().getActiveCoordinateSystem(); --- 102,106 ---- Surface surface = View.getLastSurface(); if (surface != null) { ! system = systemFor(surface); } else { system = Project.getInstance().getActiveCoordinateSystem(); *************** *** 158,161 **** --- 157,210 ---- } + /** + * Returns a coordinate system for specified surface where the Z axis + * is a normal to the surface and the x-axis points to the right. + * Does not work exactly correct yet, but works in cases where the surfaces + * are mostly vertical. + * + * @param surface Surface + * @return coordinate system + */ + public CoordinateSystem systemFor(Surface surface) { + Vertex n = surface.normal(); + Vertex origin = surface.getFirstVertex(); + if (!editor.getView().facingFront(surface)) { + n = n.scale(-1); + } + Plane plane = new Plane(n, origin); + int index = plane.largestCoefficient(); + Vertex i = null; + Vertex j = null; + Vertex z = null; + if (index == Plane.X) { + i = new Vertex(0, 1, 0); + z = new Vertex(1, 0, 0); + } + if (index == Plane.Y) { + i = new Vertex(-1, 0, 0); + z = new Vertex(0, 1, 0); + } + if (index == Plane.Z) { + i = new Vertex(1, 0, 0); + z = new Vertex(0, 0, 1); + } + + double t = n.dot(i); + double sign = 1; + + if (n.dot(z) < 0) { + sign = -1; + } + + i.setX(i.getX() - n.getX() * t); + i.setY(i.getY() - n.getY() * t); + i.setZ(i.getZ() - n.getZ() * t); + i.scaleInPlace(sign / i.length()); + + j = n.cross(i); + + return new CoordinateSystem(i, j, n, origin); + } + /** * {@inheritDoc} *************** *** 168,173 **** Surface surface = View.getLastSurface(); if (surface != null) { ! system = surface.coordinateSystem(); ! system = system.plane().coordinateSystem(); } else { system = Project.getInstance().getActiveCoordinateSystem(); --- 217,221 ---- Surface surface = View.getLastSurface(); if (surface != null) { ! system = systemFor(surface); } else { system = Project.getInstance().getActiveCoordinateSystem(); |