Thea
CoordinateFrame3.hpp
1 //============================================================================
2 //
3 // This file is part of the Thea toolkit.
4 //
5 // This software is distributed under the BSD license, as detailed in the
6 // accompanying LICENSE.txt file. Portions are derived from other works:
7 // their respective licenses and copyright information are reproduced in
8 // LICENSE.txt and/or in the relevant source files.
9 //
10 // Author: Siddhartha Chaudhuri
11 // First version: 2009
12 //
13 //============================================================================
14 
15 #ifndef __Thea_CoordinateFrame3_hpp__
16 #define __Thea_CoordinateFrame3_hpp__
17 
18 #include "Common.hpp"
19 #include "CoordinateFrameN.hpp"
20 
21 namespace Thea {
22 
24 template <typename T>
25 class /* THEA_API */ CoordinateFrameN<3, T> : public Internal::CoordinateFrameNBase<3, T>
26 {
27  private:
29 
30  public:
31  typedef typename BaseT::RigidTransformT RigidTransformT;
32  typedef typename BaseT::VectorT VectorT;
33  typedef typename BaseT::MatrixT MatrixT;
34 
37 
39  CoordinateFrameN(RigidTransformT const & src) : BaseT(src) {}
40 
45  static CoordinateFrameN fromViewFrame(VectorT const & eye, VectorT const & look_at, VectorT const & up)
46  {
48  tr.setViewFrame(eye, look_at, up);
49  return tr;
50  }
51 
56  void setViewFrame(VectorT const & eye, VectorT const & look_at, VectorT const & up)
57  {
58  // See documentation of gluLookAt
59  VectorT f = (look_at - eye).normalized();
60  VectorT s = f.cross(up).normalized();
61  VectorT u = s.cross(f);
62 
63  this->_setRotation((MatrixT() << s[0], u[0], -f[0],
64  s[1], u[1], -f[1],
65  s[2], u[2], -f[2]).finished());
66 
67  this->setTranslation(eye);
68  }
69 
71  VectorT lookVector() const
72  {
73  return -this->getAxis(2);
74  }
75 
77  VectorT upVector() const
78  {
79  return this->getAxis(1);
80  }
81 
83  VectorT rightVector() const
84  {
85  return this->getAxis(0);
86  }
87 
88  private:
89  // Hide these functions from the default interface
90  static RigidTransformT rotationAxisAngle(VectorT const & axis, Real radians) { return RigidTransformT(); }
91  static RigidTransformT rotationEulerAnglesXYZ(Real yaw, Real pitch, Real roll) { return RigidTransformT(); }
92  static RigidTransformT rotationEulerAnglesXZY(Real yaw, Real pitch, Real roll) { return RigidTransformT(); }
93  static RigidTransformT rotationEulerAnglesYXZ(Real yaw, Real pitch, Real roll) { return RigidTransformT(); }
94  static RigidTransformT rotationEulerAnglesYZX(Real yaw, Real pitch, Real roll) { return RigidTransformT(); }
95  static RigidTransformT rotationEulerAnglesZXY(Real yaw, Real pitch, Real roll) { return RigidTransformT(); }
96  static RigidTransformT rotationEulerAnglesZYX(Real yaw, Real pitch, Real roll) { return RigidTransformT(); }
97 
98  static RigidTransformT rotationArc(VectorT const & start_dir, VectorT const & end_dir, bool normalize_dirs = true)
99  { return RigidTransformT(); }
100 
101 }; // class CoordinateFrameN<3, T>
102 
103 #ifdef THEA_EXPORT_INSTANTIATION
104  template class THEA_API CoordinateFrameN<3, Real>;
105 #endif
106 
108 typedef CoordinateFrameN<3, Real> CoordinateFrame3;
109 
110 } // namespace Thea
111 
112 #endif
[Internal] Base class for a coordinate frame in N-space, defined by N orthonormal vectors...
CoordinateFrameN()
Default constructor.
Root namespace for the Thea library.
static CoordinateFrameN fromViewFrame(VectorT const &eye, VectorT const &look_at, VectorT const &up)
Construct from a viewing position (eye), look-at position (look_at) and up direction (up)...
VectorT rightVector() const
Get the right-hand direction (the X axis of the frame).
CoordinateFrameN(RigidTransformT const &src)
Construct from a rigid transform.
A rigid transformation in N-space, consisting of a rotation followed by a translation.
VectorT lookVector() const
Get the viewing direction (the negative Z axis of the frame).
VectorT upVector() const
Get the up direction (the Y axis of the frame).
void setViewFrame(VectorT const &eye, VectorT const &look_at, VectorT const &up)
Initialize from a viewing position (eye), look-at position (look_at) and up direction (up)...
VectorT getAxis(intx i) const
Get an axis of the frame.
void _setRotation(MatrixT const &rot)
Set the rotation matrix (use with caution since it can break the rigidity guarantee).
A coordinate frame in N-space, defined by N orthonormal vectors.
void setTranslation(VectorT const &translation_)
Set translation component.
CoordinateFrameN< 3, Real > CoordinateFrame3
The default coordinate frame class in real 3-space.