#pragma once
-#include <cmath>
-#include <iostream>
-#include <sstream>
-#include <type_traits>
#include "Vector.hxx"
template <typename MT>
class Quaternion {
+ static_assert (std::is_integral<MT>::value || std::is_floating_point<MT>::value,
+ "ERROR: template parameter is not an integral or floating point type");
public:
// --- public data structurs ---
- union {
+ alignas (16) union {
struct {
MT s;
MT x;
MT z;
};
MT sxyz[4];
- } __attribute__((packed));
+ };
// --- constructors and deconstructors ---
Quaternion()
- : sxyz{1, 0, 0, 0}
+ : sxyz{1.0, 0.0, 0.0, 0.0}
{
}
bool isIdentity() const
{
- return s == 1 && x == 0 && y == 0 && z == 0;
+ return s == 1.0 && x == 0.0 && y == 0.0 && z == 0.0;
}
bool isNull() const
{
- return s == 0 && x == 0 && y == 0 && z == 0;
+ return s == 0.0 && x == 0.0 && y == 0.0 && z == 0.0;
}
MT length() const
Vector3<MT> rotatedVector3(const Vector3<MT>& vec) const
{
- return (*this * Quaternion(0, vec) * conjugated()).vector3();
+ return (*this * Quaternion(0.0, vec) * conjugated()).vector3();
}
std::string string() const