[Bprocessor-commit] gl/src/net/sourceforge/bprocessor/gl/tool Protractor.java, 1.18, 1.19 RotationT
Status: Pre-Alpha
Brought to you by:
henryml
From: Michael L. <he...@us...> - 2007-11-22 10:12:43
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv30174/src/net/sourceforge/bprocessor/gl/tool Modified Files: Protractor.java RotationTool.java Log Message: Refactoring of coordinate system computation in protractor Index: Protractor.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/Protractor.java,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** Protractor.java 21 Nov 2007 15:28:46 -0000 1.18 --- Protractor.java 22 Nov 2007 10:12:46 -0000 1.19 *************** *** 157,205 **** } ! /** ! * 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); --- 157,194 ---- } ! ! /** ! * CoordinateSystem for specified origin and z-axis (n), where the orientation ! * is such that x-axis points right when looking down the negative z-axis. ! * @param origin Vertex ! * @param n z-axis * @return coordinate system */ ! public CoordinateSystem systemFor(Vertex origin, Vertex n) { ! int index = n.largestCoefficient(); Vertex i = null; Vertex j = null; ! if (index == Vertex.X) { i = new Vertex(0, 1, 0); ! Vertex z = new Vertex(1, 0, 0); ! if (n.dot(z) < 0) { ! i = i.scale(-1); ! } } ! if (index == Vertex.Y) { i = new Vertex(-1, 0, 0); ! Vertex z = new Vertex(0, 1, 0); ! if (n.dot(z) < 0) { ! i = i.scale(-1); ! } } ! if (index == Vertex.Z) { i = new Vertex(1, 0, 0); } double t = n.dot(i); + i = i.minus(n.scale(t)); + i.normalize(); j = n.cross(i); *************** *** 207,210 **** --- 196,215 ---- } + /** + * 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. + * + * @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); + } + return systemFor(origin, n); + } + /** * {@inheritDoc} Index: RotationTool.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/RotationTool.java,v retrieving revision 1.32 retrieving revision 1.33 diff -C2 -d -r1.32 -r1.33 *** RotationTool.java 18 Nov 2007 21:30:17 -0000 1.32 --- RotationTool.java 22 Nov 2007 10:12:46 -0000 1.33 *************** *** 291,296 **** while (iter.hasNext()) { Vertex v = (Vertex)iter.next(); ! Geometry.rotate(angle, onto.getDoublev()[Plane.X], ! onto.getDoublev()[Plane.Y], onto.getDoublev()[Plane.Z], v, p1); } } --- 291,296 ---- while (iter.hasNext()) { Vertex v = (Vertex)iter.next(); ! Geometry.rotate(angle, onto.getDoublev()[Vertex.X], ! onto.getDoublev()[Vertex.Y], onto.getDoublev()[Vertex.Z], v, p1); } } |