All Classes Files Functions Variables Typedefs Pages
Quaternion.hpp
Go to the documentation of this file.
1 #pragma once
2 
12 #include "QuaternionCore.hpp"
13 #include "RepCommon.hpp"
14 
15 #include <cmath>
16 #include <string>
17 #include <ostream>
18 
19 namespace lumina {
20 
21 template <typename T, typename S>
22 auto quaternionFromAxisAngle(Vec3<T> axis, S angle)
23  -> Quaternion<decltype(T(0) * std::sin(S(0)))> {
24  Quaternion<decltype(T(0) * std::sin(S(0)))> q;
25  S a2 = angle / 2;
26  auto sa2 = std::sin(a2);
27 
28  q.w = std::cos(a2);
29  q.x = axis.x * sa2;
30  q.y = axis.y * sa2;
31  q.z = axis.z * sa2;
32 
33  return q;
34 }
35 
36 template <typename T>
37 std::string quaternionRep(Quaternion<T> in) {
38  std::string out("Quaternion: ");
39  out += internal::numberToRep(in.w);
40  out += " + " + internal::numberToRep(in.x) + " * i";
41  out += " + " + internal::numberToRep(in.y) + " * j";
42  out += " + " + internal::numberToRep(in.z) + " * k";
43  return out;
44 }
45 
46 template <typename T>
47 std::ostream& operator<<(std::ostream& out, const Quaternion<T> q) {
48  return (out << quaternionRep(q));
49 }
50 
51 }
This file is part of the Lumina Graphics Framework.