Pascal Serrarens 4385befa11 Add angle-axis
2024-04-26 12:11:48 +02:00

39 lines
999 B
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 "Axis.h"
#include "Quaternion.h"
#include "Vector3.h"
#include <math.h>
Axis::Axis() {
horizontalAngle = 0;
verticalAngle = 0;
}
Axis::Axis(Angle horizontal, Angle vertical) {
this->horizontalAngle = horizontal;
this->verticalAngle = vertical;
};
Axis::Axis(Vector3 v) {
this->horizontalAngle = atan2f(v.x, v.z) * Angle::Rad2Deg;
this->verticalAngle = 90 - acosf(v.y) * Angle::Rad2Deg;
}
const Axis Axis::forward = Axis(0, 0);
const Axis Axis::back = Axis(180, 0);
const Axis Axis::up = Axis(0, 90);
const Axis Axis::down = Axis(0, -90);
const Axis Axis::left = Axis(-90, 0);
const Axis Axis::right = Axis(90, 0);
Vector3 Axis::ToVector3() {
Vector3 v =
Quaternion::Euler(-this->verticalAngle, this->horizontalAngle, 0) *
Vector3::forward;
return v;
}