RoboidControl-cpp/Direction.cpp
2024-08-06 10:02:01 +02:00

54 lines
1.7 KiB
C++

// 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 <math.h>
template <typename T>
Direction<T>::Direction() {
this->horizontalAngle = AngleOf<T>(0.0f);
this->verticalAngle = AngleOf<T>(0.0f);
}
template <typename T>
Direction<T>::Direction(AngleOf<T> horizontal, AngleOf<T> vertical) {
this->horizontalAngle = horizontal;
this->verticalAngle = vertical;
};
template <typename T>
Direction<T>::Direction(Vector3 v) {
this->horizontalAngle =
atan2f(v.Right(), v.Forward()) * Passer::LinearAlgebra::Rad2Deg;
this->verticalAngle = 90 - acosf(v.Up()) * Passer::LinearAlgebra::Rad2Deg;
}
template <typename T>
const Direction<T> Direction<T>::forward = Direction<T>(0.0f, 0.0f);
template <typename T>
const Direction<T> Direction<T>::back = Direction<T>(180.0f, 0.0f);
template <typename T>
const Direction<T> Direction<T>::up = Direction<T>(0.0f, 90.0f);
template <typename T>
const Direction<T> Direction<T>::down = Direction<T>(0.0f, -90.0f);
template <typename T>
const Direction<T> Direction<T>::left = Direction<T>(-90.0f, 0.0f);
template <typename T>
const Direction<T> Direction<T>::right = Direction<T>(90.0f, 0.0f);
template <typename T>
Vector3 Direction<T>::ToVector3() {
Vector3 v = Quaternion::Euler(-(this->verticalAngle.ToFloat()),
this->horizontalAngle.ToFloat(), 0) *
Vector3::forward;
return v;
}
template class Direction<float>;
template class Direction<signed short>;
template class Direction<signed char>;