forked from Hartmut/paradiso
stripped down all pixwerx code to a minimal istic subset
This commit is contained in:
commit
612677c52d
398 changed files with 164811 additions and 0 deletions
src/lib
62
src/lib/vector.hpp
Normal file
62
src/lib/vector.hpp
Normal file
|
@ -0,0 +1,62 @@
|
|||
#ifndef PARADISO_VECTOR_HPP
|
||||
#define PARADISO_VECTOR_HPP
|
||||
|
||||
#include "matrix.hpp"
|
||||
|
||||
namespace paradiso {
|
||||
|
||||
/**
|
||||
* Basic vector types used in pixwerx.
|
||||
*/
|
||||
|
||||
template <typename T> struct Vector2 : Matrix<2, 1, T> {
|
||||
|
||||
using base_type = Matrix<2, 1, T>;
|
||||
|
||||
constexpr const T& x() const noexcept { return (*this)[0]; }
|
||||
constexpr T& x() { return (*this)[0]; }
|
||||
|
||||
constexpr const T& y() const { return (*this)[1]; }
|
||||
constexpr T& y() { return (*this)[1]; }
|
||||
|
||||
inline auto homogenous(T w = 1) const {
|
||||
return Matrix<3, 1, T>({x(), y(), w});
|
||||
}
|
||||
|
||||
static T angle_between(const Vector2& a, const Vector2& b) {
|
||||
return std::acos(dot(a.normalized(), b.normalized()));
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T> struct Vector3 : Matrix<3, 1, T> {
|
||||
|
||||
using base_type = Matrix<3, 1, T>;
|
||||
|
||||
constexpr const T& x() const { return (*this)[0]; }
|
||||
constexpr T& x() { return (*this)[0]; }
|
||||
|
||||
constexpr const T& y() const { return (*this)[1]; }
|
||||
constexpr T& y() { return (*this)[1]; }
|
||||
|
||||
constexpr Vector2<T> xy() const noexcept { return {x(), y()}; }
|
||||
|
||||
static constexpr Vector3 cross(const Vector3& lhs, const Vector3& rhs) {
|
||||
return vector3_({lhs[1] * rhs[2] - rhs[1] * lhs[2],
|
||||
lhs[2] * rhs[0] - rhs[2] * lhs[0],
|
||||
lhs[0] * rhs[1] - rhs[0] * lhs[1]});
|
||||
}
|
||||
|
||||
static constexpr auto x_axis() noexcept {
|
||||
return Vector3::make(T{1}, T{0}, T{0});
|
||||
}
|
||||
static constexpr auto y_axis() noexcept {
|
||||
return Vector3::make(T{0}, T{1}, T{0});
|
||||
}
|
||||
static constexpr auto z_axis() noexcept {
|
||||
return Vector3<T>::make(T{0}, T{0}, T{1});
|
||||
}
|
||||
};
|
||||
|
||||
}; // namespace paradiso
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue