[2]  1  // %flair:license{


[15]  2  // This file is part of the Flair framework distributed under the


 3  // CECILLC 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"


 19  #include "GroupBox.h"


 20  #include "ComboBox.h"


 21  #include "DoubleSpinBox.h"


 22  #include <Euler.h>


 23  #include <Quaternion.h>


[186]  24  #include <math.h>


[2]  25 


 26  using std::string;


 27  using namespace flair::core;


 28  using namespace flair::gui;


 29 


[167]  30  template void OneAxisRotation_impl::ComputeRotation(Vector3D<float>&) const;


 31  template void OneAxisRotation_impl::ComputeRotation(Vector3D<double>&) const;


 32 


[15]  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");


[2]  40  }


 41 


[15]  42  OneAxisRotation_impl::~OneAxisRotation_impl() {}


[2]  43 


[15]  44  void OneAxisRotation_impl::ComputeRotation(Quaternion &quat) const {


[186]  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;


[2]  58  }


 59 


[15]  60  void OneAxisRotation_impl::ComputeRotation(RotationMatrix &matrix) const {


[103]  61  Printf("not yet implemented\n");


[2]  62  }


 63 


[15]  64  // on utilise la rotation d'un vector pour faire une rotation de repere


 65  // d'ou le signe negatif


[167]  66  template <typename T> void OneAxisRotation_impl::ComputeRotation(Vector3D<T> &vector) const {


[15]  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  }


[2]  78  }


 79 


[15]  80  void OneAxisRotation_impl::ComputeRotation(Euler &euler) const {


 81  Quaternion quat;


 82  euler.ToQuaternion(quat);


 83  ComputeRotation(quat);


 84  quat.ToEuler(euler);


[2]  85  }


[144]  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 

