[Bprocessor-commit] gl/src/net/sourceforge/bprocessor/gl/tool OrbitStrategy.java, NONE, 1.1 Abstrac
Status: Pre-Alpha
Brought to you by:
henryml
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv18436/src/net/sourceforge/bprocessor/gl/tool Modified Files: AbstractTool.java MoveTool.java ExtrudeTool.java AbstractPencil.java CameraTool.java Added Files: OrbitStrategy.java Log Message: Refactored CameraTool into Tool + Strategy Index: ExtrudeTool.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/ExtrudeTool.java,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** ExtrudeTool.java 28 Jun 2006 13:26:02 -0000 1.20 --- ExtrudeTool.java 3 Jul 2006 14:25:02 -0000 1.21 *************** *** 518,521 **** --- 518,522 ---- */ public void keyReleased(KeyEvent e) { + super.keyReleased(e); if ((e.getModifiersEx() & KeyEvent.ALT_DOWN_MASK) == 0) { /* Alt were not pressed so we should extrude holes anyway */ Index: MoveTool.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/MoveTool.java,v retrieving revision 1.58 retrieving revision 1.59 diff -C2 -d -r1.58 -r1.59 *** MoveTool.java 6 Jun 2006 09:22:25 -0000 1.58 --- MoveTool.java 3 Jul 2006 14:25:02 -0000 1.59 *************** *** 229,232 **** --- 229,233 ---- */ public void keyReleased(KeyEvent e) { + super.keyReleased(e); if (strategy != null) { strategy.keyReleased(e); Index: CameraTool.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/CameraTool.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** CameraTool.java 16 Jun 2006 09:56:51 -0000 1.10 --- CameraTool.java 3 Jul 2006 14:25:03 -0000 1.11 *************** *** 8,18 **** import net.sourceforge.bprocessor.gl.GLView; - import net.sourceforge.bprocessor.gl.view.View; - import net.sourceforge.bprocessor.model.Camera; - import net.sourceforge.bprocessor.model.Project; //import java.awt.event.KeyEvent; import java.awt.event.MouseEvent; - import java.awt.event.InputEvent; import java.awt.Cursor; --- 8,14 ---- *************** *** 32,40 **** private static Logger log = Logger.getLogger(CameraTool.class); - /** The current rotation mode */ - protected int mode = ROTATION; - /** The cursor for rotation */ private Cursor rotationCursor; /** --- 28,36 ---- private static Logger log = Logger.getLogger(CameraTool.class); /** The cursor for rotation */ private Cursor rotationCursor; + + /** Orbit strategy */ + private Strategy orbit; /** *************** *** 45,48 **** --- 41,45 ---- public CameraTool(GLView glv, Cursor cursor1) { super(glv, cursor1); + orbit = new OrbitStrategy(glv); rotationCursor = cursor1; } *************** *** 53,61 **** */ protected void moved(MouseEvent e) { ! if ((e.getModifiersEx() & InputEvent.SHIFT_DOWN_MASK) == InputEvent.SHIFT_DOWN_MASK) { ! mode = ROLL; ! } else { ! mode = ROTATION; ! } } --- 50,54 ---- */ protected void moved(MouseEvent e) { ! orbit.moved((e)); } *************** *** 65,95 **** */ protected void dragged(MouseEvent e) { ! View view = glv.getView(); ! Camera c = Project.getInstance().getCurrentCamera(); ! double[] roll = c.getRoll(); ! if ((e.getModifiersEx() & MouseEvent.BUTTON1_DOWN_MASK) == ! MouseEvent.BUTTON1_DOWN_MASK || e.getButton() == MouseEvent.BUTTON1) { ! double angleX = ((double)(e.getX() - previousPos[0]) / 360) * Math.PI; ! double angleY = ((double)(e.getY() - previousPos[1]) / 360) * Math.PI; ! double turn = 1; ! if (roll[2] < 0) { ! turn = -1; ! } ! ! if (e.isShiftDown()) { ! // roll camera ! Camera.rollCamera(c, turn * (-angleY - angleX) / 2); ! } else if (e.isAltDown()) { ! // rotate camera about itself ! Camera.rotateHorizontallyEye(c, -angleX); ! Camera.rotateVerticallyEye(c, angleY); ! } else { ! // rotate camera about point of view (or selection if any) ! double[] pivot = super.selectionCenter(); ! Camera.rotateHorizontally(c, -angleX, pivot); ! Camera.rotateVertically(c, angleY, pivot); ! } ! Project.getInstance().changed(c); ! } } --- 58,62 ---- */ protected void dragged(MouseEvent e) { ! orbit.dragged((e)); } *************** *** 99,112 **** */ protected void pressed(MouseEvent e) { ! glv.setCursor(rotationCursor); ! if (e.getButton() == MouseEvent.BUTTON1) { ! if ((e.getModifiersEx() & InputEvent.SHIFT_DOWN_MASK) == InputEvent.SHIFT_DOWN_MASK) { ! mode = ROLL; ! } else { ! mode = ROTATION; ! } ! } else if (e.getButton() == MouseEvent.BUTTON3) { ! glv.changeTool(Tool.PREVIOUS_TOOL); ! } } /** --- 66,70 ---- */ protected void pressed(MouseEvent e) { ! orbit.pressed((e)); } /** *************** *** 115,118 **** --- 73,77 ---- */ protected void released(MouseEvent e) { + orbit.released(e); } } --- NEW FILE: OrbitStrategy.java --- //--------------------------------------------------------------------------------- // $Id: OrbitStrategy.java,v 1.1 2006/07/03 14:25:02 henryml Exp $ // // 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 net.sourceforge.bprocessor.gl.GLView; import net.sourceforge.bprocessor.gl.view.View; import net.sourceforge.bprocessor.model.Camera; import net.sourceforge.bprocessor.model.Project; //import java.awt.event.KeyEvent; import java.awt.event.MouseEvent; import java.awt.event.InputEvent; import org.apache.log4j.Logger; /** * The rotationtool */ public class OrbitStrategy implements Strategy { /** Rotation mode */ public static final int ROTATION = 0; /** Roll mode */ public static final int ROLL = 1; /** The logger */ private static Logger log = Logger.getLogger(OrbitStrategy.class); /** The current rotation mode */ protected int mode = ROTATION; /** GLView */ protected GLView glv; /** The x position */ private int x; /** The y position */ private int y; /** * KeyListener for the GL Canvas * @param glv The 3D canvas */ public OrbitStrategy(GLView glv) { this.glv = glv; } /** * Invoked when the mouse cursor has been moved * @param e The MouseEvent object */ public void moved(MouseEvent e) { if ((e.getModifiersEx() & InputEvent.SHIFT_DOWN_MASK) == InputEvent.SHIFT_DOWN_MASK) { mode = ROLL; } else { mode = ROTATION; } } /** * Invoked when the mouse is held pressed and moved * @param e The MouseEvent object */ public void dragged(MouseEvent e) { View view = glv.getView(); Camera c = Project.getInstance().getCurrentCamera(); double[] roll = c.getRoll(); if ((e.getModifiersEx() & MouseEvent.BUTTON1_DOWN_MASK) == MouseEvent.BUTTON1_DOWN_MASK || e.getButton() == MouseEvent.BUTTON1) { double angleX = ((double)(e.getX() - x) / 360) * Math.PI; double angleY = ((double)(e.getY() - y) / 360) * Math.PI; double turn = 1; if (roll[2] < 0) { turn = -1; } if (e.isShiftDown()) { // roll camera Camera.rollCamera(c, turn * (-angleY - angleX) / 2); } else if (e.isAltDown()) { // rotate camera about itself Camera.rotateHorizontallyEye(c, -angleX); Camera.rotateVerticallyEye(c, angleY); } else { // rotate camera about point of view (or selection if any) double[] pivot = AbstractTool.selectionCenter(); Camera.rotateHorizontally(c, -angleX, pivot); Camera.rotateVertically(c, angleY, pivot); } Project.getInstance().changed(c); x = e.getX(); y = e.getY(); } } /** * Invoked when a mouse button has been pressed on a component. * @param e The MouseEvent object */ public void pressed(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON1) { if ((e.getModifiersEx() & InputEvent.SHIFT_DOWN_MASK) == InputEvent.SHIFT_DOWN_MASK) { mode = ROLL; } else { mode = ROTATION; } } x = e.getX(); y = e.getY(); } /** * Invoked when a mouse button has been released on a component. * @param e The MouseEvent */ public void released(MouseEvent e) { } } Index: AbstractPencil.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/AbstractPencil.java,v retrieving revision 1.34 retrieving revision 1.35 diff -C2 -d -r1.34 -r1.35 *** AbstractPencil.java 28 Jun 2006 13:26:02 -0000 1.34 --- AbstractPencil.java 3 Jul 2006 14:25:02 -0000 1.35 *************** *** 777,780 **** --- 777,781 ---- */ public void keyReleased(KeyEvent e) { + super.keyReleased(e); if (e.getKeyCode() == KeyEvent.VK_SHIFT) { lock = false; Index: AbstractTool.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/AbstractTool.java,v retrieving revision 1.82 retrieving revision 1.83 diff -C2 -d -r1.82 -r1.83 *** AbstractTool.java 28 Jun 2006 14:19:16 -0000 1.82 --- AbstractTool.java 3 Jul 2006 14:25:02 -0000 1.83 *************** *** 48,51 **** --- 48,54 ---- protected boolean directMode = false; + /** Camera active */ + protected boolean cameraMode = false; + /** Pan strategy */ protected static Strategy pan; *************** *** 164,170 **** * @return The center of the selection */ ! public double[] selectionCenter() { double[] center = Project.getInstance().getCurrentCamera().getCenter(); ! Iterator it = selection.iterator(); if (it.hasNext()) { Object o = it.next(); --- 167,173 ---- * @return The center of the selection */ ! public static double[] selectionCenter() { double[] center = Project.getInstance().getCurrentCamera().getCenter(); ! Iterator it = Selection.primary().iterator(); if (it.hasNext()) { Object o = it.next(); *************** *** 219,222 **** --- 222,226 ---- if (e.getKeyCode() == KeyEvent.VK_SPACE) { log.info("space-pressed"); + cameraMode = true; return; } *************** *** 292,295 **** --- 296,300 ---- if (e.getKeyCode() == KeyEvent.VK_SPACE) { log.info("space-released"); + cameraMode = false; } } |