[Bprocessor-commit] gl/src/net/sourceforge/bprocessor/gl/tool MultiExtrudeTool.java,NONE,1.1
Status: Pre-Alpha
Brought to you by:
henryml
From: rimestad <rim...@us...> - 2006-02-16 14:04:10
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12152/src/net/sourceforge/bprocessor/gl/tool Added Files: MultiExtrudeTool.java Log Message: start of new extrusion not added to the toolbar yet because of lack of functionality --- NEW FILE: MultiExtrudeTool.java --- //--------------------------------------------------------------------------------- // $Id$ // // Copyright (c) 2005 The BProcessor Team (http://bprocessor.sourceforge.net) // Released under the Lesser GNU Public License v2.1 //--------------------------------------------------------------------------------- package net.sourceforge.bprocessor.gl.tool; import java.awt.Cursor; import java.awt.event.MouseEvent; import java.util.Collection; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; import java.util.Iterator; import net.sourceforge.bprocessor.gl.GLView; import net.sourceforge.bprocessor.gl.view.Transformation; import net.sourceforge.bprocessor.gl.view.View; import net.sourceforge.bprocessor.model.Direction; import net.sourceforge.bprocessor.model.Edge; import net.sourceforge.bprocessor.model.Plane; import net.sourceforge.bprocessor.model.Selection; import net.sourceforge.bprocessor.model.Surface; import net.sourceforge.bprocessor.model.Vertex; /** * The ExtrudeTool */ public class MultiExtrudeTool extends SelectTool { /** The dragSurface and extrudesurface */ private Surface top, extrudeSurface; /** A vertex-direction map */ private Map v2dir; /** The Plane to draw in */ private Plane dragPlane; /** The vertices to extrude */ private List vertices; /** The previous coordinate */ private int prevX, prevY; /** * Constructor * @param glv THe GLCanvas * @param cursor The cursor */ public MultiExtrudeTool(GLView glv, Cursor cursor) { super(glv, cursor); } /** * Invoked when a mouse button has been pressed on a component. * @param e The MouseEvent object */ protected void pressed(MouseEvent e) { extrudeSurface = null; top = null; v2dir = new HashMap(); super.pressed(e); if (target instanceof Surface) { // lav extrudsionen af selectionen extrudeSurface = (Surface)target; View view = glv.getView(); Transformation trans = view.transformation(); double x = prevX; double y = View.getHeight() - prevY; Vertex near = new Vertex(x, y, 0.0); Vertex far = new Vertex(x, y, 1.0); Edge ray = new Edge(near, far); ray = trans.unProject(ray); dragPlane = extrudeSurface.plane().orthogonalPlane(ray); } } /** * Invoked when the mouse is held pressed and moved * @param e The MouseEvent object */ protected void dragged(MouseEvent e) { if (v2dir != null) { if (top == null) { //make the extrusion Set elements = makeExtrusion(Selection.primary()); } // Find the move direction Vertex normal; if (top == null) { normal = extrudeSurface.normal(); } else { normal = top.normal(); } View view = glv.getView(); Vertex from = view.toPlaneCoords(new double[] {prevX, prevY}, dragPlane); Vertex to = view.toPlaneCoords(new double[] {e.getX(), e.getY()}, dragPlane); Vertex delta = to.minus(from); double normDotDelta = normal.dot(delta); move(v2dir.values(), normDotDelta); } } /** * Move a collection of vertex, direction pairs * @param which The colelction of pairs * @param delta The amount of the direction each vertex should move */ private void move(Collection which, double delta) { Iterator iter = which.iterator(); while (iter.hasNext()) { Direction d = (Direction)iter.next(); Vertex movement = d.getDirection(); movement.scale(delta); d.getVertex().move(movement.getX(), movement.getY(), movement.getZ()); } } /** * Invoked when a mouse button has been released on a component. * @param e The MouseEvent */ protected void released(MouseEvent e) { super.released(e); } /** * Make the extrusion from a set of surfaces * @param c the collection of surfaces to extrude * @return the elements created for extrusion */ private Set makeExtrusion(Collection c) { Set elements = new HashSet(); Map e2e = new HashMap(); // edge to edge map Map e2s = new HashMap(); // edge to surface map Map v2v = new HashMap(); // vertex to extruded edge map v2dir = new HashMap(); // vertex to direction map Map v2e = new HashMap(); // vertex to edge map // Check for selection of only surfaces Iterator iter = c.iterator(); while (iter.hasNext()) { if (!(iter.next() instanceof Surface)) { extrudeSurface = null; return null; } } iter = c.iterator(); while (iter.hasNext()) { Surface s = ((Surface)iter.next()).extrude(1, elements, e2e, v2e, e2s, v2dir, v2v); if (extrudeSurface == null) { extrudeSurface = s; } elements.add(s); } return elements; } } |