source: flair-src/trunk/lib/FlairCore/src/OneAxisRotation_impl.cpp @ 187

Last change on this file since 187 was 187, checked in by Sanahuja Guillaume, 3 years ago

changement post/pre rotation

File size: 2.8 KB
Line 
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 "OneAxisRotation.h"
20#include "GroupBox.h"
21#include "ComboBox.h"
22#include "DoubleSpinBox.h"
23#include <Euler.h>
24#include <Quaternion.h>
25#include <math.h>
26
27using std::string;
28using namespace flair::core;
29using namespace flair::gui;
30
31template void OneAxisRotation_impl::ComputeRotation(Vector3D<float>&) const;
32template void OneAxisRotation_impl::ComputeRotation(Vector3D<double>&) const;
33
34OneAxisRotation_impl::OneAxisRotation_impl(GroupBox *box,int rotationType) {
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");
41  this->rotationType=rotationType;
42}
43
44OneAxisRotation_impl::~OneAxisRotation_impl() {}
45
46void OneAxisRotation_impl::ComputeRotation(Quaternion &quat) const {
47  Quaternion rot;
48  switch (rot_axe->CurrentIndex()) {
49    case 0://x
50      rot=Quaternion(cosf(Euler::ToRadian(-rot_value->Value()/2)),sinf(Euler::ToRadian(-rot_value->Value()/2)),0,0);
51      break;
52    case 1://y
53      rot=Quaternion(cosf(Euler::ToRadian(-rot_value->Value()/2)),0,sinf(Euler::ToRadian(-rot_value->Value()/2)),0);
54      break;
55    case 2://z
56      rot=Quaternion(cosf(Euler::ToRadian(-rot_value->Value()/2)),0,0,sinf(Euler::ToRadian(-rot_value->Value()/2)));
57      break;
58  }
59  if(rotationType==OneAxisRotation::RotationType_t::PreRotation) {
60    quat=rot*quat;
61  } else { //post rotation
62    quat=quat*rot;
63  }
64}
65
66void OneAxisRotation_impl::ComputeRotation(RotationMatrix &matrix) const {
67  Printf("not yet implemented\n");
68}
69
70// on utilise la rotation d'un vector pour faire une rotation de repere
71// d'ou le signe negatif
72template <typename T> void OneAxisRotation_impl::ComputeRotation(Vector3D<T> &vector) const {
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  }
84}
85
86void OneAxisRotation_impl::ComputeRotation(Euler &euler) const {
87  Quaternion quat;
88  euler.ToQuaternion(quat);
89  ComputeRotation(quat);
90  quat.ToEuler(euler);
91}
92
93int OneAxisRotation_impl::GetAxis() const {
94  return rot_axe->CurrentIndex();
95}
96
97float OneAxisRotation_impl::GetAngle() const {
98  return rot_value->Value();
99}
100
Note: See TracBrowser for help on using the repository browser.