Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
OnlyRotationControl.cpp
1 #include <GLviewer/GLProjectionParametersBase.hh>
2 #include <Base/Math/Vector3.hh>
3 #include <Base/Geometry/RMatrixBase.hh>
4 #include "OnlyRotationControl.hh"
5 
6 
7 #include <Gui/biasgl.h>
8 
9 using namespace BIAS;
10 using namespace BIAS;
11 using namespace std;
12 double rememroll;
13 bool upsidedown;
14 
16 {
17  rememroll=0;
18 }
19 
21 LeftMouseMoved(int x1, int x2, int y1, int y2)
22 {
23  bool left=false;
24 
25  if (x1-x2 != 0){
26  if (x1 > x2)
27  left=true;
28  }
29 
30  Vector3<double> C, up;
31  controlledObject_->GetExtrinsics(C, up);
32 
33  RMatrix R = controlledObject_->GetMyselfAsProjectionParameterBase()->GetR();
34  double w=1.0/180.0*M_PI;
35  if (left){ w=-1.0/180.0*M_PI; }
36 
37  BIAS::Matrix3x3<double>n(cos(w),0,-sin(w), 0,1,0,sin(w),0,cos(w));
38 
39  BIAS::RMatrix m(n);
40  BIAS::RMatrix ges;
41  R.Mult(m, ges);
42 
43  double phix,phiy,phiz;
44  ges.GetRotationAnglesXYZ(phix,phiy,phiz);
45  controlledObject_->SetExtrinsics(HomgPoint3D(C), ges);
46 
47  cout<<"actual yaw (rad): "<<phiy<<" (deg): "<<phiy*180.0/M_PI <<" (!not unique)"<< endl; cout<<"and roll (rad): "<<phiz<<" (deg): "<<phiz*180.0/M_PI
48  <<" (!not unique)"<< endl; cout<<"actual pitch (rad): "<<phix<<" (deg): "<<phix*180.0/M_PI
49  <<" (!not unique)"<< endl;
50  return true;
51 }
52 
54 RightMouseMoved(int /*x1*/, int /*x2*/, int y1, int y2)
55 {
56  bool upper=false;
57 
58  if (y1-y2 != 0){
59  if (y1 > y2)
60  upper=true;
61  }
62 
63  Vector3<double> C, up;
64  controlledObject_->GetExtrinsics(C, up);
65  RMatrix R = controlledObject_->GetMyselfAsProjectionParameterBase()->GetR();
66  double w=0.1/180.0*M_PI;
67  if (upper){ w*=-1; }
68 
69  BIAS::Matrix3x3<double>n(1,0,0,0,cos(w),sin(w), 0,-sin(w),cos(w));
70 
71  BIAS::RMatrix m(n);
72  BIAS::RMatrix ges;
73  m.Mult(R, ges);
74  double phix,phiy,phiz;
75  ges.GetRotationAnglesXYZ(phix,phiy,phiz);
76  controlledObject_->SetExtrinsics(HomgPoint3D(C), ges);
77  cout<<"actual pitch (rad): "<<phix<<" (deg): "<<phix*180.0/M_PI
78  <<" (!not unique)"<< endl;
79  cout<<"and roll (rad): "<<phiz<<" (deg): "<<phiz*180.0/M_PI
80  <<" (!not unique)"<< endl;
81  cout<<"and yaw (rad): "<<phiy<<" (deg): "<<phiy*180.0/M_PI
82  <<" (!not unique)"<< endl;
83  return true;
84 }
85 
87 MiddleMouseMoved(int x1, int x2, int y1, int y2)
88 {
89  bool left=false;
90 
91  if (x1-x2 != 0) {
92  if (x1 > x2)
93  left=true;
94  }
95  Vector3<double> C, up;
96  controlledObject_->GetExtrinsics(C, up);
97  // Vector3<double> C(0.0,0.0,0.0) ;
98  RMatrix R = controlledObject_->GetMyselfAsProjectionParameterBase()->GetR();
99  double w =0.1/180.0*M_PI;
100 
101 
102  if (left){ w*=-1; }
103 
104  BIAS::Matrix3x3<double>n(cos(w),sin(w), 0,-sin(w),cos(w),0,0,0,1);
105 
106  BIAS::RMatrix m(n);
107  BIAS::RMatrix ges;
108  R.Mult(m, ges);
109  double phix,phiy,phiz;
110  ges.GetRotationAnglesXYZ(phix,phiy,phiz);
111  rememroll=phiz;
112  controlledObject_->SetExtrinsics(HomgPoint3D(C), ges);
113  cout<<"actual roll (rad): "<<phiz<<" (deg): "<<phiz*180.0/M_PI
114  <<" (!not unique)"<< endl;
115  cout<<"actual pitch (rad): "<<phix<<" (deg): "<<phix*180.0/M_PI
116  <<" (!not unique)"<< endl;
117 
118  cout<<"and yaw (rad): "<<phiy<<" (deg): "<<phiy*180.0/M_PI
119  <<" (!not unique)"<< endl;
120 
121  // RMatrix R = controlledObject_->GetR();
122  // Vector3<double> C, up, rotationAxis, A;
123 
124  // rotationAxis = Vector3<double>(R[0][2], R[1][2], R[2][2]);
125  // controlledObject_->GetExtrinsics(C, up);
126 
127  // Create quaternion and derive new up vector
128  // Quaternion<ROTATION_MATRIX_TYPE> delta;
129  // delta.SetValueAsAxisRad(rotationAxis, 1/180.0*M_PI);
130  // delta.MultVec(up, up);
131 
132  // controlledObject_->SetExtrinsics(C, C + rotationAxis, up);
133 
134  return true;
135 }
136 
139 {
140  //Vector3<double> C(0.0,0.0,0.0) ;
141  Vector3<double> C, up;
142  controlledObject_->GetExtrinsics(C, up);
143  // if ( upsidedown) {rememroll=180+(rememroll*180/M_PI);rememroll=rememroll/180*M_PI;}
144  double w=rememroll;
145 
146  RMatrix R = controlledObject_->GetMyselfAsProjectionParameterBase()->GetR();
147 
148  BIAS::Matrix3x3<double>n(cos(w),sin(w), 0,-sin(w),cos(w),0,0,0,1);
149 
150  BIAS::RMatrix m(n);
151  BIAS::RMatrix ges;
152  m.Mult(R, ges);
153  double phix,phiy,phiz;
154  ges.GetRotationAnglesXYZ(phix,phiy,phiz);
155  controlledObject_->SetExtrinsics(HomgPoint3D(C), ges);
156  rememroll=0;
157  // if (upsidedown) rememroll=180;
158 
159  cout<<"actual roll (rad): "<<phiz<<" (deg): "<<phiz*180.0/M_PI <<" (!not unique)"<< endl;
160  return true;
161 
162 }
163 
165 LeftAndRightMouseMoved(int x1, int x2, int y1, int y2)
166 {
167 
168  //bool rightMove=false;
169  bool frontMove=false;
170 
171  /*if (x1-x2 != 0)
172  {
173  if (x1 > x2)
174  {
175  rightMove=true;
176  }
177 
178  }*/
179  if (y1-y2 != 0)
180  {
181  if (y1 > y2)
182  {
183  frontMove=true;
184  }
185  }
186  Vector3<double> C, up;
187  controlledObject_->GetExtrinsics(C, up);
188  // if (rightMove)
189  // {
190  // C[0]+=0.5;
191  // }else
192  // { C[0]-=0.5;
193  // }
194  if (frontMove){
195  C[2]+=0.5;
196  }
197  else
198  C[2]-=0.5;
199 
200  cout<<"actual position: x= "<<C[0]<<" y: "<<C[1]<<"z: "<<C[2]<<endl;
201  RMatrix R = controlledObject_->GetMyselfAsProjectionParameterBase()->GetR();
202  controlledObject_->SetExtrinsics(HomgPoint3D(C), R);
203  return true;
204 }
205 
207 RightMouseDoubleClicked(int /*x*/, int /*y*/) {
208 
209 
210  Vector3<double> C, up;
211  Vector3<double> rotationAxis;
212  RMatrix R = controlledObject_->GetMyselfAsProjectionParameterBase()->GetR();
213  rotationAxis = Vector3<double>(R[0][2], R[1][2], R[2][2]);
214  controlledObject_->GetExtrinsics(C, up);
215  up[1]*=-1;
216  rememroll=180+(rememroll*180/M_PI);
217  rememroll=rememroll*180/M_PI;
218  controlledObject_->SetExtrinsics(C, C+rotationAxis,up);
219  upsidedown=!upsidedown;
220 
221  return true;
222 }
223 //TODO
224 //keylistener??? -pitch reset, center(0,0,0), print/save actual yaw/pitch/roll
bool MiddleMouseMoved(int x1, int x2, int y1, int y2)
performs a left/right (roll) rotation (mouse moving left-right) for animations without changing the v...
bool LeftMouseMoved(int x1, int x2, int y1, int y2)
performs a left/right (yaw) rotation (mouse moving left-right) for animations without changing the vi...
bool LeftMouseDoubleClicked(int x, int y)
performs a reset for (roll) rotation without changing the viewport position
3D rotation matrix
Definition: RMatrix.hh:49
bool LeftAndRightMouseMoved(int x1, int x2, int y1, int y2)
performs a minimal changing of the viewport position
bool RightMouseMoved(int x1, int x2, int y1, int y2)
performs a up/down (pitch) rotation (mouse moving up-down) for animations without changing the viewpo...
void Mult(const Vector3< T > &argvec, Vector3< T > &destvec) const
matrix - vector multiplicate this matrix with Vector3, storing the result in destvec calculates: dest...
Definition: Matrix3x3.hh:302
int GetRotationAnglesXYZ(double &PhiX, double &PhiY, double &PhiZ) const
Get Euler angles for this rotation matrix in order XYZ.
bool RightMouseDoubleClicked(int, int)
performs an invert of up vector -to correct vrml scenes
class BIASGeometryBase_EXPORT HomgPoint3D