diff --git a/AngleAxis.cpp b/AngleAxis.cpp index 9cc1f1e..8dad1b1 100644 --- a/AngleAxis.cpp +++ b/AngleAxis.cpp @@ -4,12 +4,14 @@ #include "AngleAxis.h" -AngleAxis::AngleAxis() { +template +AngleAxis::AngleAxis() { angle = Angle(); axis = Axis(); } -AngleAxis::AngleAxis(Angle angle, Axis axis) { +template +AngleAxis::AngleAxis(AngleOf angle, Direction axis) { this->angle = angle; this->axis = axis; } \ No newline at end of file diff --git a/AngleAxis.h b/AngleAxis.h index 7dd47ab..c9e1fd5 100644 --- a/AngleAxis.h +++ b/AngleAxis.h @@ -6,22 +6,24 @@ #define ANGLEAXIS_H #include "Angle.h" -#include "Axis.h" +// #include "Axis.h" +#include "Direction.h" namespace Passer { namespace LinearAlgebra { +template class AngleAxis { -public: - Angle angle; - Axis axis; + public: + AngleOf angle; + Direction axis; AngleAxis(); - AngleAxis(Angle angle, Axis axis); + AngleAxis(AngleOf angle, Direction axis); }; -} // namespace LinearAlgebra -} // namespace Passer +} // namespace LinearAlgebra +} // namespace Passer using namespace Passer::LinearAlgebra; #endif \ No newline at end of file diff --git a/Direction.cpp b/Direction.cpp new file mode 100644 index 0000000..925bee3 --- /dev/null +++ b/Direction.cpp @@ -0,0 +1,50 @@ +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0.If a copy of the MPL was not distributed with this +// file, You can obtain one at https ://mozilla.org/MPL/2.0/. + +#include "Direction.h" + +#include "Quaternion.h" +#include "Vector3.h" + +#include + +template +Direction::Direction() { + this->horizontalAngle = AngleOf(0.0f); + this->verticalAngle = AngleOf(0.0f); +} + +template +Direction::Direction(AngleOf horizontal, AngleOf vertical) { + this->horizontalAngle = horizontal; + this->verticalAngle = vertical; +}; + +template +Direction::Direction(Vector3 v) { + this->horizontalAngle = + atan2f(v.Right(), v.Forward()) * Passer::LinearAlgebra::Rad2Deg; + this->verticalAngle = 90 - acosf(v.Up()) * Passer::LinearAlgebra::Rad2Deg; +} + +template +const Direction Direction::forward = Direction(0.0f, 0.0f); +template +const Direction Direction::back = Direction(180.0f, 0.0f); +template +const Direction Direction::up = Direction(0.0f, 90.0f); +template +const Direction Direction::down = Direction(0.0f, -90.0f); +template +const Direction Direction::left = Direction(-90.0f, 0.0f); +template +const Direction Direction::right = Direction(90.0f, 0.0f); + +template +Vector3 Direction::ToVector3() { + Vector3 v = Quaternion::Euler(-(this->verticalAngle.ToFloat()), + this->horizontalAngle.ToFloat(), 0) * + Vector3::forward; + return v; +} \ No newline at end of file diff --git a/Direction.h b/Direction.h new file mode 100644 index 0000000..6978b0a --- /dev/null +++ b/Direction.h @@ -0,0 +1,39 @@ +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0.If a copy of the MPL was not distributed with this +// file, You can obtain one at https ://mozilla.org/MPL/2.0/. + +#ifndef DIRECTION_H +#define DIRECTION_H + +#include "Angle.h" + +namespace Passer { +namespace LinearAlgebra { + +struct Vector3; + +template +class Direction { + public: + AngleOf horizontalAngle; + AngleOf verticalAngle; + + Direction(); + Direction(AngleOf horizontal, AngleOf vertical); + Direction(Vector3 v); + + const static Direction forward; + const static Direction back; + const static Direction up; + const static Direction down; + const static Direction left; + const static Direction right; + + Vector3 ToVector3(); +}; + +} // namespace LinearAlgebra +} // namespace Passer +using namespace Passer::LinearAlgebra; + +#endif \ No newline at end of file