View Javadoc
1 /***************************************************************************** 2 * Virtual Mockup for Machine Vision 3 * Copyright (C) 2001-2003 Fabio R. de Miranda, João E. Kogler Jr., 4 * Carlos S. Santos. 5 * Virtual Mockup for Machine Vision Project funded by SENAC-SP 6 * 7 * Permission is granted to redistribute and/or modify this 8 * software under the terms of the GNU Lesser General Public 9 * License as published by the Free Software Foundation; either 10 * version 2.1 of the License, or (at your option) any later version. 11 * 12 * This software is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * Lesser General Public License (http://www.gnu.org/copyleft/lesser.html) 16 * for more details. 17 * 18 *****************************************************************************/ 19 20 package camera3d.action; 21 22 23 import camera3d.VcObject; 24 import camera3d.TransformMode; 25 26 /*** 27 * Action for rotating VcObjects. 28 * 29 * @author Fábio Roberto de Miranda 30 * @version 1.0 31 */ 32 public class RotationAction extends TransformAction { 33 34 public void setAngles(double x, double y, double z){ 35 this.x = x; 36 this.y = y; 37 this.z = z; 38 } 39 40 public RotationAction(VcObject v, TransformMode mode){ 41 super(v, mode); 42 //this.debugflag = true; 43 } 44 45 public void doAction(ActionExecutor executor){ 46 //debugln("Interpreting rotation action"); 47 VcObject vcObj = getVcObject(); 48 49 if(getTransformMode()==TransformMode.ABSOLUTE) { 50 vcObj.rotateEuler(this.x, this.y, this.z); 51 //debugln("__absolute rot"); 52 }else if(getTransformMode()==TransformMode.RELATIVE){ 53 vcObj.rotateEulerLocal(this.x, this.y, this.z); 54 //debugln("__relative rot"); 55 } 56 } 57 58 /*** 59 * Tries to combine the effect of this action and of inputAction into one single 60 * action. If that is possible (as signaled by the return value), only this action 61 * should be executed, and not inputAction. 62 * @return true if optimization has been performed, false otherwise 63 */ 64 public boolean optimize(VcAction inputAction){ 65 if(!canOptimize(inputAction)) return false; 66 else{ 67 TransformAction transformAction = (TransformAction) inputAction; 68 // if the rotation following this one is absolute, we only need to perform 69 // this last rotation 70 if(transformAction.getTransformMode()==TransformMode.ABSOLUTE){ 71 x = transformAction.x; 72 y = transformAction.y; 73 z = transformAction.z; 74 setTransformMode(TransformMode.ABSOLUTE); 75 return true; 76 }else{ 77 // if the two rotations are relative we can add the values 78 if(this.getTransformMode()==TransformMode.RELATIVE){ 79 x = x + transformAction.x; 80 y = y + transformAction.y; 81 z = z + transformAction.z; 82 return true; 83 } 84 } 85 // if this rotation is absolute and the next one is relative we will 86 // perform no optimization 87 return false; 88 } 89 } 90 91 92 }

This page was automatically generated by Maven