1 | // %flair:license{
|
---|
2 | // This file is part of the Flair framework distributed under the
|
---|
3 | // CECILL-C License, Version 1.0.
|
---|
4 | // %flair:license}
|
---|
5 | // created: 2013/04/17
|
---|
6 | // filename: OneAxisRotation_impl.cpp
|
---|
7 | //
|
---|
8 | // author: Guillaume Sanahuja
|
---|
9 | // Copyright Heudiasyc UMR UTC/CNRS 7253
|
---|
10 | //
|
---|
11 | // version: $Id: $
|
---|
12 | //
|
---|
13 | // purpose: objet integrant pour une rotation sur un axe
|
---|
14 | //
|
---|
15 | //
|
---|
16 | /*********************************************************************/
|
---|
17 |
|
---|
18 | #include "OneAxisRotation_impl.h"
|
---|
19 | #include "GroupBox.h"
|
---|
20 | #include "ComboBox.h"
|
---|
21 | #include "DoubleSpinBox.h"
|
---|
22 | #include <Euler.h>
|
---|
23 | #include <Quaternion.h>
|
---|
24 |
|
---|
25 | using std::string;
|
---|
26 | using namespace flair::core;
|
---|
27 | using namespace flair::gui;
|
---|
28 |
|
---|
29 | template void OneAxisRotation_impl::ComputeRotation(Vector3D<float>&) const;
|
---|
30 | template void OneAxisRotation_impl::ComputeRotation(Vector3D<double>&) const;
|
---|
31 |
|
---|
32 | OneAxisRotation_impl::OneAxisRotation_impl(GroupBox *box) {
|
---|
33 | rot_value =
|
---|
34 | new DoubleSpinBox(box->NewRow(), "value", " deg", -180., 180., 10., 1);
|
---|
35 | rot_axe = new ComboBox(box->LastRowLastCol(), "axis");
|
---|
36 | rot_axe->AddItem("x");
|
---|
37 | rot_axe->AddItem("y");
|
---|
38 | rot_axe->AddItem("z");
|
---|
39 | }
|
---|
40 |
|
---|
41 | OneAxisRotation_impl::~OneAxisRotation_impl() {}
|
---|
42 |
|
---|
43 | // compute rotation of each axis through ComputeRotation(Vector3D& vector)
|
---|
44 | void OneAxisRotation_impl::ComputeRotation(Quaternion &quat) const {
|
---|
45 | Vector3Df rot = Vector3Df(quat.q1, quat.q2, quat.q3);
|
---|
46 | ComputeRotation(rot);
|
---|
47 | quat.q1 = rot.x;
|
---|
48 | quat.q2 = rot.y;
|
---|
49 | quat.q3 = rot.z;
|
---|
50 | }
|
---|
51 |
|
---|
52 | void OneAxisRotation_impl::ComputeRotation(RotationMatrix &matrix) const {
|
---|
53 | Printf("not yet implemented\n");
|
---|
54 | }
|
---|
55 |
|
---|
56 | // on utilise la rotation d'un vector pour faire une rotation de repere
|
---|
57 | // d'ou le signe negatif
|
---|
58 | template <typename T> void OneAxisRotation_impl::ComputeRotation(Vector3D<T> &vector) const {
|
---|
59 | switch (rot_axe->CurrentIndex()) {
|
---|
60 | case 0:
|
---|
61 | vector.RotateXDeg(-rot_value->Value());
|
---|
62 | break;
|
---|
63 | case 1:
|
---|
64 | vector.RotateYDeg(-rot_value->Value());
|
---|
65 | break;
|
---|
66 | case 2:
|
---|
67 | vector.RotateZDeg(-rot_value->Value());
|
---|
68 | break;
|
---|
69 | }
|
---|
70 | }
|
---|
71 |
|
---|
72 | void OneAxisRotation_impl::ComputeRotation(Euler &euler) const {
|
---|
73 | Quaternion quat;
|
---|
74 | euler.ToQuaternion(quat);
|
---|
75 | ComputeRotation(quat);
|
---|
76 | quat.ToEuler(euler);
|
---|
77 | }
|
---|
78 |
|
---|
79 | int OneAxisRotation_impl::GetAxis() const {
|
---|
80 | return rot_axe->CurrentIndex();
|
---|
81 | }
|
---|
82 |
|
---|
83 | float OneAxisRotation_impl::GetAngle() const {
|
---|
84 | return rot_value->Value();
|
---|
85 | }
|
---|
86 |
|
---|