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
24 import camera3d.VcObject;
25 import camera3d.TransformMode;
26 import javax.vecmath.*;
27
28 /***
29 * Action for translating a VcObject.
30 *
31 * @author Fábio Roberto de Miranda
32 * @version 1.0
33 */
34 public class TranslationAction extends TransformAction {
35
36 public TranslationAction(VcObject v, TransformMode mode){
37 super(v, mode);
38 }
39
40 public TranslationAction(VcObject v, TransformMode mode, Point3d trans){
41 super(v, mode);
42 this.x = trans.x;
43 this.y = trans.y;
44 this.z = trans.z;
45 }
46
47 /***
48 * Sets the values by which the VcObject will be translated.
49 */
50 public void setTranslationValues(double x, double y, double z){
51 this.x = x;
52 this.y = y;
53 this.z = z;
54 }
55
56 /***
57 * Performs the translation.
58 */
59 public void doAction(ActionExecutor executor){
60 VcObject vcObj = getVcObject();
61 if(getTransformMode()== TransformMode.ABSOLUTE) {
62 vcObj.translate(this.x, this.y, this.z);
63 }
64 else if(getTransformMode()== TransformMode.RELATIVE) {
65 vcObj.translateLocal(this.x, this.y, this.z);
66 }
67
68 }
69
70
71 /***
72 * Tries to eliminate the Action given as input, when possible. In case inputAction is not a
73 * TranslationAction, then no optimization can be performed and the method returns false. If
74 * inputAction is a set to an absolute translation its parameters are simply copied into this
75 * object, so inputAction no longer need to be performed. Finally, if inputAction is set to a
76 * relative translation, this object's parameters are set to reflect the combined effects of
77 * this object and inputAction, which is no longer necessary. In both former cases the method
78 * returns true.
79 */
80 public boolean optimize(VcAction inputAction){
81 if(!canOptimize(inputAction)) return false;
82 else{
83 TransformAction transformAction = (TransformAction) inputAction;
84 if(transformAction.getTransformMode()==TransformMode.ABSOLUTE){
85 x = transformAction.x;
86 y = transformAction.y;
87 z = transformAction.z;
88 setTransformMode(TransformMode.ABSOLUTE);
89 }else{
90 x = x + transformAction.x;
91 y = y + transformAction.y;
92 z = z + transformAction.z;
93 }
94 return true;
95 }
96 }
97
98 }
This page was automatically generated by Maven