Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6706
Modified Files:
SelectTool.java
Log Message:
Added edge selecting
Index: SelectTool.java
===================================================================
RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/SelectTool.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** SelectTool.java 26 Jul 2005 12:34:09 -0000 1.1
--- SelectTool.java 27 Jul 2005 11:01:54 -0000 1.2
***************
*** 13,16 ****
--- 13,18 ----
import net.sourceforge.bprocessor.kernel.notification.Notifier;
+ import net.sourceforge.bprocessor.model.Edge;
+ import net.sourceforge.bprocessor.model.EdgeFacade;
import net.sourceforge.bprocessor.model.Vertex;
import net.sourceforge.bprocessor.model.VertexFacade;
***************
*** 22,27 ****
import org.apache.log4j.Logger;
/**
! * The abstracttool
*/
public class SelectTool extends AbstractTool {
--- 24,30 ----
import org.apache.log4j.Logger;
+
/**
! * The selecttool
*/
public class SelectTool extends AbstractTool {
***************
*** 30,34 ****
/**
! * KeyListener for the GL Canvas
* @param glv The 3D canvas
*/
--- 33,37 ----
/**
! * The constructor
* @param glv The 3D canvas
*/
***************
*** 73,78 ****
--- 76,120 ----
Notification n = new Notification(Notification.VERTEX_SELECTED, v.getId());
Notifier.getInstance().sendNotification(n);
+ } else {
+ Edge edge = edgeCollide(coords);
+ if (edge != null) {
+ Notification n = new Notification(Notification.EDGE_SELECTED, edge.getId());
+ Notifier.getInstance().sendNotification(n);
+ }
+ }
+ }
+ }
+
+ /**
+ * Check if this cordinate collide with an edge
+ * @param coord The cordinate to check for collision at
+ * @return The excisting edge on that coord, null if there ain't any
+ */
+ protected Edge edgeCollide(double[] coord) {
+ Set edges = EdgeFacade.getInstance().findAll();
+ Iterator it = edges.iterator();
+ while (it.hasNext()) {
+ Edge e = (Edge)it.next();
+ double[] r = new double[] {e.getTo().getX() - e.getFrom().getX(),
+ e.getTo().getY() - e.getFrom().getY(),
+ e.getTo().getZ() - e.getFrom().getZ()};
+ double[] ppo = new double[] {coord[0] - e.getFrom().getX(),
+ coord[1] - e.getFrom().getY(),
+ coord[2] - e.getFrom().getZ()};
+ double normr = Math.abs(Math.sqrt(r[0] * r[0] + r[1] * r[1] + r[2] * r[2]));
+ double[] temp = new double[] {r[1] * ppo[2] - ppo[1] * r[2],
+ r[2] * ppo[0] - ppo[2] * r[0],
+ r[0] * ppo[1] - ppo[0] * r[1]};
+ double t = Math.abs(Math.sqrt(temp[0] * temp[0] +
+ temp[1] * temp[1] +
+ temp[2] * temp[2]));
+ double normppo = Math.abs(Math.sqrt(ppo[0] * ppo[0] + ppo[1] * ppo[1] + ppo[2] * ppo[2]));
+ double rppo = r[0] * ppo[0] + r[1] * ppo[1] + r[2] * ppo[2];
+
+ if (t / normr < EPSILON && normppo <= normr && rppo > 0) {
+ return e;
}
}
+ return null;
}
|