Added Direction to replace Axis
This commit is contained in:
parent
c72bba4f7a
commit
38ebb34491
@ -4,12 +4,14 @@
|
|||||||
|
|
||||||
#include "AngleAxis.h"
|
#include "AngleAxis.h"
|
||||||
|
|
||||||
AngleAxis::AngleAxis() {
|
template <typename T>
|
||||||
|
AngleAxis<T>::AngleAxis() {
|
||||||
angle = Angle();
|
angle = Angle();
|
||||||
axis = Axis();
|
axis = Axis();
|
||||||
}
|
}
|
||||||
|
|
||||||
AngleAxis::AngleAxis(Angle angle, Axis axis) {
|
template <typename T>
|
||||||
|
AngleAxis<T>::AngleAxis(AngleOf<T> angle, Direction<T> axis) {
|
||||||
this->angle = angle;
|
this->angle = angle;
|
||||||
this->axis = axis;
|
this->axis = axis;
|
||||||
}
|
}
|
16
AngleAxis.h
16
AngleAxis.h
@ -6,22 +6,24 @@
|
|||||||
#define ANGLEAXIS_H
|
#define ANGLEAXIS_H
|
||||||
|
|
||||||
#include "Angle.h"
|
#include "Angle.h"
|
||||||
#include "Axis.h"
|
// #include "Axis.h"
|
||||||
|
#include "Direction.h"
|
||||||
|
|
||||||
namespace Passer {
|
namespace Passer {
|
||||||
namespace LinearAlgebra {
|
namespace LinearAlgebra {
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
class AngleAxis {
|
class AngleAxis {
|
||||||
public:
|
public:
|
||||||
Angle angle;
|
AngleOf<T> angle;
|
||||||
Axis axis;
|
Direction<T> axis;
|
||||||
|
|
||||||
AngleAxis();
|
AngleAxis();
|
||||||
AngleAxis(Angle angle, Axis axis);
|
AngleAxis(AngleOf<T> angle, Direction<T> axis);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace LinearAlgebra
|
} // namespace LinearAlgebra
|
||||||
} // namespace Passer
|
} // namespace Passer
|
||||||
using namespace Passer::LinearAlgebra;
|
using namespace Passer::LinearAlgebra;
|
||||||
|
|
||||||
#endif
|
#endif
|
50
Direction.cpp
Normal file
50
Direction.cpp
Normal file
@ -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 <math.h>
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
Direction<T>::Direction() {
|
||||||
|
this->horizontalAngle = AngleOf(0.0f);
|
||||||
|
this->verticalAngle = AngleOf(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;
|
||||||
|
}
|
39
Direction.h
Normal file
39
Direction.h
Normal 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/.
|
||||||
|
|
||||||
|
#ifndef DIRECTION_H
|
||||||
|
#define DIRECTION_H
|
||||||
|
|
||||||
|
#include "Angle.h"
|
||||||
|
|
||||||
|
namespace Passer {
|
||||||
|
namespace LinearAlgebra {
|
||||||
|
|
||||||
|
struct Vector3;
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
class Direction {
|
||||||
|
public:
|
||||||
|
AngleOf<T> horizontalAngle;
|
||||||
|
AngleOf<T> verticalAngle;
|
||||||
|
|
||||||
|
Direction();
|
||||||
|
Direction(AngleOf<T> horizontal, AngleOf<T> 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
|
Loading…
x
Reference in New Issue
Block a user