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 | #include <math.h>
|
---|
25 |
|
---|
26 | using std::string;
|
---|
27 | using namespace flair::core;
|
---|
28 | using namespace flair::gui;
|
---|
29 |
|
---|
30 | template void OneAxisRotation_impl::ComputeRotation(Vector3D<float>&) const;
|
---|
31 | template void OneAxisRotation_impl::ComputeRotation(Vector3D<double>&) const;
|
---|
32 |
|
---|
33 | OneAxisRotation_impl::OneAxisRotation_impl(GroupBox *box) {
|
---|
34 | rot_value =
|
---|
35 | new DoubleSpinBox(box->NewRow(), "value", " deg", -180., 180., 10., 1);
|
---|
36 | rot_axe = new ComboBox(box->LastRowLastCol(), "axis");
|
---|
37 | rot_axe->AddItem("x");
|
---|
38 | rot_axe->AddItem("y");
|
---|
39 | rot_axe->AddItem("z");
|
---|
40 | }
|
---|
41 |
|
---|
42 | OneAxisRotation_impl::~OneAxisRotation_impl() {}
|
---|
43 |
|
---|
44 | void OneAxisRotation_impl::ComputeRotation(Quaternion &quat) const {
|
---|
45 | Quaternion rot;
|
---|
46 | switch (rot_axe->CurrentIndex()) {
|
---|
47 | case 0:
|
---|
48 | rot=Quaternion(cosf(Euler::ToRadian(rot_value->Value()/2)),sinf(Euler::ToRadian(rot_value->Value()/2)), 0,0);
|
---|
49 | break;
|
---|
50 | case 1:
|
---|
51 | rot=Quaternion(cosf(Euler::ToRadian(rot_value->Value()/2)),0,sinf(Euler::ToRadian(rot_value->Value()/2)),0);
|
---|
52 | break;
|
---|
53 | case 2:
|
---|
54 | rot=Quaternion(cosf(Euler::ToRadian(rot_value->Value()/2)),0,0,sinf(Euler::ToRadian(rot_value->Value()/2)));
|
---|
55 | break;
|
---|
56 | }
|
---|
57 | quat=quat*rot;
|
---|
58 | }
|
---|
59 |
|
---|
60 | void OneAxisRotation_impl::ComputeRotation(RotationMatrix &matrix) const {
|
---|
61 | Printf("not yet implemented\n");
|
---|
62 | }
|
---|
63 |
|
---|
64 | // on utilise la rotation d'un vector pour faire une rotation de repere
|
---|
65 | // d'ou le signe negatif
|
---|
66 | template <typename T> void OneAxisRotation_impl::ComputeRotation(Vector3D<T> &vector) const {
|
---|
67 | switch (rot_axe->CurrentIndex()) {
|
---|
68 | case 0:
|
---|
69 | vector.RotateXDeg(-rot_value->Value());
|
---|
70 | break;
|
---|
71 | case 1:
|
---|
72 | vector.RotateYDeg(-rot_value->Value());
|
---|
73 | break;
|
---|
74 | case 2:
|
---|
75 | vector.RotateZDeg(-rot_value->Value());
|
---|
76 | break;
|
---|
77 | }
|
---|
78 | }
|
---|
79 |
|
---|
80 | void OneAxisRotation_impl::ComputeRotation(Euler &euler) const {
|
---|
81 | Quaternion quat;
|
---|
82 | euler.ToQuaternion(quat);
|
---|
83 | ComputeRotation(quat);
|
---|
84 | quat.ToEuler(euler);
|
---|
85 | }
|
---|
86 |
|
---|
87 | int OneAxisRotation_impl::GetAxis() const {
|
---|
88 | return rot_axe->CurrentIndex();
|
---|
89 | }
|
---|
90 |
|
---|
91 | float OneAxisRotation_impl::GetAngle() const {
|
---|
92 | return rot_value->Value();
|
---|
93 | }
|
---|
94 |
|
---|