// Copyright (C) 2015 Jérôme Leclercq // This file is part of the "Nazara Engine - Mathematics module" // For conditions of distribution and use, see copyright notice in Config.hpp #include #include #include #include #include #include #include #define F(a) static_cast(a) namespace Nz { template EulerAngles::EulerAngles(T P, T Y, T R) { Set(P, Y, R); } template EulerAngles::EulerAngles(const T angles[3]) { Set(angles); } template EulerAngles::EulerAngles(const Quaternion& quat) { Set(quat); } template template EulerAngles::EulerAngles(const EulerAngles& angles) { Set(angles); } template void EulerAngles::MakeZero() { Set(F(0.0), F(0.0), F(0.0)); } template void EulerAngles::Normalize() { pitch = NormalizeAngle(pitch); yaw = NormalizeAngle(yaw); roll = NormalizeAngle(roll); } template void EulerAngles::Set(T P, T Y, T R) { pitch = P; yaw = Y; roll = R; } template void EulerAngles::Set(const T angles[3]) { pitch = angles[0]; yaw = angles[1]; roll = angles[2]; } template void EulerAngles::Set(const EulerAngles& angles) { std::memcpy(this, &angles, sizeof(EulerAngles)); } template void EulerAngles::Set(const Quaternion& quat) { Set(quat.ToEulerAngles()); } template template void EulerAngles::Set(const EulerAngles& angles) { pitch = F(angles.pitch); yaw = F(angles.yaw); roll = F(angles.roll); } template Quaternion EulerAngles::ToQuaternion() const { T c1 = std::cos(ToRadians(yaw) / F(2.0)); T c2 = std::cos(ToRadians(roll) / F(2.0)); T c3 = std::cos(ToRadians(pitch) / F(2.0)); T s1 = std::sin(ToRadians(yaw) / F(2.0)); T s2 = std::sin(ToRadians(roll) / F(2.0)); T s3 = std::sin(ToRadians(pitch) / F(2.0)); return Quaternion(c1 * c2 * c3 - s1 * s2 * s3, s1 * s2 * c3 + c1 * c2 * s3, s1 * c2 * c3 + c1 * s2 * s3, c1 * s2 * c3 - s1 * c2 * s3); } template String EulerAngles::ToString() const { StringStream ss; return ss << "EulerAngles(" << pitch << ", " << yaw << ", " << roll << ')'; } template EulerAngles EulerAngles::operator+(const EulerAngles& angles) const { return EulerAngles(pitch + angles.pitch, yaw + angles.yaw, roll + angles.roll); } template EulerAngles EulerAngles::operator-(const EulerAngles& angles) const { return EulerAngles(pitch - angles.pitch, yaw - angles.yaw, roll - angles.roll); } template EulerAngles& EulerAngles::operator+=(const EulerAngles& angles) { pitch += angles.pitch; yaw += angles.yaw; roll += angles.roll; return *this; } template EulerAngles& EulerAngles::operator-=(const EulerAngles& angles) { pitch -= angles.pitch; yaw -= angles.yaw; roll -= angles.roll; return *this; } template bool EulerAngles::operator==(const EulerAngles& angles) const { return NumberEquals(pitch, angles.pitch) && NumberEquals(yaw, angles.yaw) && NumberEquals(roll, angles.roll); } template bool EulerAngles::operator!=(const EulerAngles& angles) const { return !operator==(angles); } template EulerAngles EulerAngles::Zero() { EulerAngles angles; angles.MakeZero(); return angles; } } template std::ostream& operator<<(std::ostream& out, const Nz::EulerAngles& angles) { return out << angles.ToString(); } #undef F #include