[2] | 1 | // %flair:license{
|
---|
[15] | 2 | // This file is part of the Flair framework distributed under the
|
---|
| 3 | // CECILL-C License, Version 1.0.
|
---|
[2] | 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"
|
---|
[187] | 19 | #include "OneAxisRotation.h"
|
---|
[2] | 20 | #include "GroupBox.h"
|
---|
| 21 | #include "ComboBox.h"
|
---|
| 22 | #include "DoubleSpinBox.h"
|
---|
| 23 | #include <Euler.h>
|
---|
| 24 | #include <Quaternion.h>
|
---|
[186] | 25 | #include <math.h>
|
---|
[2] | 26 |
|
---|
| 27 | using std::string;
|
---|
| 28 | using namespace flair::core;
|
---|
| 29 | using namespace flair::gui;
|
---|
| 30 |
|
---|
[167] | 31 | template void OneAxisRotation_impl::ComputeRotation(Vector3D<float>&) const;
|
---|
| 32 | template void OneAxisRotation_impl::ComputeRotation(Vector3D<double>&) const;
|
---|
| 33 |
|
---|
[187] | 34 | OneAxisRotation_impl::OneAxisRotation_impl(GroupBox *box,int rotationType) {
|
---|
[15] | 35 | rot_value =
|
---|
| 36 | new DoubleSpinBox(box->NewRow(), "value", " deg", -180., 180., 10., 1);
|
---|
| 37 | rot_axe = new ComboBox(box->LastRowLastCol(), "axis");
|
---|
| 38 | rot_axe->AddItem("x");
|
---|
| 39 | rot_axe->AddItem("y");
|
---|
| 40 | rot_axe->AddItem("z");
|
---|
[187] | 41 | this->rotationType=rotationType;
|
---|
[2] | 42 | }
|
---|
| 43 |
|
---|
[15] | 44 | OneAxisRotation_impl::~OneAxisRotation_impl() {}
|
---|
[2] | 45 |
|
---|
[15] | 46 | void OneAxisRotation_impl::ComputeRotation(Quaternion &quat) const {
|
---|
[186] | 47 | Quaternion rot;
|
---|
| 48 | switch (rot_axe->CurrentIndex()) {
|
---|
[187] | 49 | case 0://x
|
---|
| 50 | rot=Quaternion(cosf(Euler::ToRadian(-rot_value->Value()/2)),sinf(Euler::ToRadian(-rot_value->Value()/2)),0,0);
|
---|
[186] | 51 | break;
|
---|
[187] | 52 | case 1://y
|
---|
| 53 | rot=Quaternion(cosf(Euler::ToRadian(-rot_value->Value()/2)),0,sinf(Euler::ToRadian(-rot_value->Value()/2)),0);
|
---|
[186] | 54 | break;
|
---|
[187] | 55 | case 2://z
|
---|
| 56 | rot=Quaternion(cosf(Euler::ToRadian(-rot_value->Value()/2)),0,0,sinf(Euler::ToRadian(-rot_value->Value()/2)));
|
---|
[186] | 57 | break;
|
---|
| 58 | }
|
---|
[187] | 59 | if(rotationType==OneAxisRotation::RotationType_t::PreRotation) {
|
---|
| 60 | quat=rot*quat;
|
---|
| 61 | } else { //post rotation
|
---|
| 62 | quat=quat*rot;
|
---|
| 63 | }
|
---|
[2] | 64 | }
|
---|
| 65 |
|
---|
[15] | 66 | void OneAxisRotation_impl::ComputeRotation(RotationMatrix &matrix) const {
|
---|
[103] | 67 | Printf("not yet implemented\n");
|
---|
[2] | 68 | }
|
---|
| 69 |
|
---|
[15] | 70 | // on utilise la rotation d'un vector pour faire une rotation de repere
|
---|
| 71 | // d'ou le signe negatif
|
---|
[167] | 72 | template <typename T> void OneAxisRotation_impl::ComputeRotation(Vector3D<T> &vector) const {
|
---|
[15] | 73 | switch (rot_axe->CurrentIndex()) {
|
---|
| 74 | case 0:
|
---|
| 75 | vector.RotateXDeg(-rot_value->Value());
|
---|
| 76 | break;
|
---|
| 77 | case 1:
|
---|
| 78 | vector.RotateYDeg(-rot_value->Value());
|
---|
| 79 | break;
|
---|
| 80 | case 2:
|
---|
| 81 | vector.RotateZDeg(-rot_value->Value());
|
---|
| 82 | break;
|
---|
| 83 | }
|
---|
[2] | 84 | }
|
---|
| 85 |
|
---|
[15] | 86 | void OneAxisRotation_impl::ComputeRotation(Euler &euler) const {
|
---|
| 87 | Quaternion quat;
|
---|
| 88 | euler.ToQuaternion(quat);
|
---|
| 89 | ComputeRotation(quat);
|
---|
| 90 | quat.ToEuler(euler);
|
---|
[2] | 91 | }
|
---|
[144] | 92 |
|
---|
| 93 | int OneAxisRotation_impl::GetAxis() const {
|
---|
| 94 | return rot_axe->CurrentIndex();
|
---|
| 95 | }
|
---|
| 96 |
|
---|
| 97 | float OneAxisRotation_impl::GetAngle() const {
|
---|
| 98 | return rot_value->Value();
|
---|
| 99 | }
|
---|
| 100 |
|
---|