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.manipulation;
21
22
23 import javax.vecmath.*;
24 import camera3d.TransformMode;
25 import camera3d.TransformScope;
26
27
28 /***
29 * Manipulator used to rotate objects with mouse dragging.
30 *
31 * @author Fábio Roberto de Miranda, Carlos da Silva dos Santos
32 * @version 1.0
33 */
34 public class RotationManipulator extends TransformationManipulator {
35
36
37 private double coefficient = 2.0f;
38
39 private double deltaX;
40 private double deltaY;
41
42 private double lastX;
43 private double lastY;
44
45 private double beginX;
46 private double beginY;
47
48 private RotatableObject rotatableObject;
49
50 /***
51 * Creates new manipulator.
52 */
53 public RotationManipulator(){
54 super();
55 }
56
57 /***
58 * Creates new manipulator and sets its RotatableObject.
59 */
60 public RotationManipulator(RotatableObject rotatableObject){
61 super();
62 setRotatableObject(rotatableObject);
63 }
64
65 public void setRotatableObject(RotatableObject rotatableObject){
66 this.rotatableObject = rotatableObject;
67 setTransformationMode(this.mode);
68 setTransformationScope(this.scope);
69 }
70
71 public void clearSelection(){
72 this.rotatableObject = null;
73 }
74
75 /***
76 * Sets value of the initial point (pixel) of dragging movement.
77 * @param x x coordinate of the point where dragging movement was initiated.
78 * @param y y coordinate of the point where dragging movement was initiated.
79 */
80 public void setBeginPoint(int x, int y){
81 //super.setBeginPoint(x, y);
82 //lastClickedPoint.set(clickedPoint);
83
84 lastX = x;
85 lastY = y;
86 debugln("rotation manip. begin:("+x+","+y+")");
87 /*
88 if (selectedObject!=null){
89
90 }*/
91 }
92
93 void transform(int x, int y){
94 debugln("RotationManipulator called with ("+ x +","+ y +")");
95
96 double w = canvas3d.getWidth();
97 double h = canvas3d.getHeight();;
98
99 deltaX = (x - lastX)/ w;
100 deltaY = (y - lastY)/ h;
101
102 //coefficient = 360.0;
103 coefficient = 2*Math.PI;
104
105 double totalY = coefficient*deltaY;
106
107 debugln("Delta Y: "+deltaY);
108 debugln("Total Y: "+totalY);
109
110 if(mode==TransformMode.ABSOLUTE){
111 debugln("absolute rotation");
112 //selectedObject.rotateIncremental(scope,totalY);
113 rotatableObject.rotateAbsolute(scope,totalY);
114 }
115 else if(mode==TransformMode.RELATIVE){
116 rotatableObject.rotateLocal(scope,totalY);
117 /*
118 if(scope == TransformScope.X){
119 selectedObject.rotateEulerLocalX(totalY);
120 }
121 else if(scope == TransformScope.Y){
122 selectedObject.rotateEulerLocalY(totalY);
123 }
124 else if(scope == TransformScope.Z){
125 selectedObject.rotateEulerLocalZ(totalY);
126 }
127 */
128 }
129 lastX = x;
130 lastY = y;
131 }
132
133
134 }
This page was automatically generated by Maven