Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/view
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26344/src/net/sourceforge/bprocessor/gl/view
Modified Files:
Transformation.java
Log Message:
Un-Projecting is implemented
Index: Transformation.java
===================================================================
RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/view/Transformation.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** Transformation.java 30 Aug 2005 08:22:35 -0000 1.2
--- Transformation.java 30 Aug 2005 09:37:25 -0000 1.3
***************
*** 117,120 ****
--- 117,184 ----
return projection;
}
+
+ /**
+ * Un-projects the Surface to screen coordinates
+ *
+ * @param surface The Surface to un-project
+ * @return The un-projected Surface
+ */
+ public Surface unProject(Surface surface) {
+ List edges = new ArrayList();
+ Iterator iter = surface.getEdges().iterator();
+ while (iter.hasNext()) {
+ Edge current = (Edge) iter.next();
+ edges.add(unProject(current));
+ }
+ Surface projected = new Surface("projection of " + surface.getName());
+ projected.setEdges(edges);
+ return projected;
+ }
+
+ /**
+ * Un-projects the Edge to model coordinates
+ * @param edge The edge to un-project
+ * @return The un-projected edge
+ */
+ public Edge unProject(Edge edge) {
+ Vertex from = unProject(edge.getFrom());
+ Vertex to = unProject(edge.getTo());
+ Edge projected = new Edge("projection of " + edge.getName());
+ projected.setFrom(from);
+ projected.setTo(to);
+ return projected;
+ }
+
+ /**
+ * Un-projects the Vertex to model coordinates
+ * @param vertex The Vertex to un-project
+ * @return The un-projected Vertex
+ */
+ public Vertex unProject(Vertex vertex) {
+ double x = vertex.getX();
+ double y = vertex.getY();
+ double z = vertex.getZ();
+ double[] view = new double[3];
+ boolean success = glu.gluUnProject(x, y, z, modelview, projection, viewport, view);
+ if (!success) {
+ System.out.println("error un-projecting");
+ }
+ Vertex projection = new Vertex("un-projection of " + vertex.getName());
+ System.out.println("x = " + view[0]);
+ projection.setX(round(view[0]));
+ projection.setY(round(view[1]));
+ projection.setZ(round(view[2]));
+ return projection;
+ }
+
+ /**
+ * Round to 4 decimals
+ * @param value The value to round
+ * @return The rounded value
+ */
+ private double round(double value) {
+ long i = (long) Math.round(value * 1000);
+ return ((double) i) / 1000.0;
+ }
}
|