Add angle-axis

This commit is contained in:
Pascal Serrarens 2024-04-26 12:11:48 +02:00
parent 4b07328790
commit 4385befa11
4 changed files with 105 additions and 0 deletions

15
AngleAxis.cpp Normal file
View File

@ -0,0 +1,15 @@
// 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 "AngleAxis.h"
AngleAxis::AngleAxis() {
angle = Angle();
axis = Axis();
}
AngleAxis::AngleAxis(Angle angle, Axis axis) {
this->angle = angle;
this->axis = axis;
}

20
AngleAxis.h Normal file
View File

@ -0,0 +1,20 @@
// 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 ANGLEAXIS_H
#define ANGLEAXIS_H
#include "Angle.h"
#include "Axis.h"
class AngleAxis {
public:
Angle angle;
Axis axis;
AngleAxis();
AngleAxis(Angle angle, Axis axis);
};
#endif

39
Axis.cpp Normal file
View File

@ -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/.
#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;
}

31
Axis.h Normal file
View File

@ -0,0 +1,31 @@
// 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 AXIS_H
#define AXIS_H
#include "Angle.h"
class Vector3;
class Axis {
public:
Angle horizontalAngle;
Angle verticalAngle;
Axis();
Axis(Angle horizontal, Angle vertical);
Axis(Vector3 v);
const static Axis forward;
const static Axis back;
const static Axis up;
const static Axis down;
const static Axis left;
const static Axis right;
Vector3 ToVector3();
};
#endif