OGLplus (0.52.0) a C++ wrapper for OpenGL

slerp.hpp
Go to the documentation of this file.
1 
12 #pragma once
13 #ifndef OGLPLUS_MATH_SLERP_1310291021_HPP
14 #define OGLPLUS_MATH_SLERP_1310291021_HPP
15 
16 #include <oglplus/config/compiler.hpp>
17 #include <oglplus/math/angle.hpp>
18 
19 namespace oglplus {
20 
22 
27 template <typename Value, typename T>
28 class BaseSLERP
29 {
30 private:
31  Value _v1, _v2;
32  Angle<T> _omega;
33  T _inv_sin_omega;
34 
35  Value _first(T) const
36  {
37  return _v1;
38  }
39 
40  Value _lerp(T t) const
41  {
42  return _v1*(T(1)-t) + _v2*t;
43  }
44 
45  Value _slerp(T t) const
46  {
47  return _v1*Sin((T(1)-t)*_omega)*_inv_sin_omega+
48  _v2*Sin(t*_omega)*_inv_sin_omega;
49  }
50 
51  Value (BaseSLERP::*_func)(T) const;
52 public:
54 
58  const Value& v1,
59  const Value& v2,
60  T eps
61  ): _v1(v1)
62  , _v2(v2)
63  , _omega(Angle<T>::ArcCos(Dot(_v1, _v2)))
64  , _inv_sin_omega(Sin(_omega))
65  , _func(nullptr)
66  {
67  if(_inv_sin_omega == T(0))
68  {
69  _func = &BaseSLERP::_first;
70  }
71  else if(std::abs(_inv_sin_omega) < eps)
72  {
73  _func = &BaseSLERP::_lerp;
74  }
75  else
76  {
77  _func = &BaseSLERP::_slerp;
78  _inv_sin_omega = T(1)/_inv_sin_omega;
79  }
80  assert(_func != nullptr);
81  }
82 
84 
87  Value operator()(T param) const
88  {
89  assert(_func != nullptr);
90  return (this->*_func)(param);
91  }
92 };
93 
94 } // namespace oglplus
95 
96 #endif // include guard
Class implementing planar angle-related functionality.
Definition: fwd.hpp:24
Angle< AngleValueType > ArcCos(AngleValueType x)
Creates a new angle using the arc cosine function.
Definition: angle.hpp:558
Angle utility class.
BaseSLERP(const Value &v1, const Value &v2, T eps)
Constructs a SLERP functor from two values.
Definition: slerp.hpp:57
Base template for spherical-linear interpolation functors.
Definition: slerp.hpp:28
Value operator()(T param) const
Interpolates between the values passed to constructor.
Definition: slerp.hpp:87

Copyright © 2010-2014 Matúš Chochlík, University of Žilina, Žilina, Slovakia.
<matus.chochlik -at- fri.uniza.sk>
<chochlik -at -gmail.com>
Documentation generated on Mon Sep 22 2014 by Doxygen (version 1.8.6).