proper zero values for vectors
This commit is contained in:
parent
a5830ad9cd
commit
623f21aedd
2 changed files with 10 additions and 2 deletions
|
@ -32,7 +32,7 @@ struct point_ {
|
||||||
|
|
||||||
using value_type = T_;
|
using value_type = T_;
|
||||||
|
|
||||||
T_ x, y;
|
T_ x {0}, y {0};
|
||||||
|
|
||||||
point_() = default;
|
point_() = default;
|
||||||
point_(T_ x_,T_ y_) : x(x_), y(y_) {}
|
point_(T_ x_,T_ y_) : x(x_), y(y_) {}
|
||||||
|
|
|
@ -54,6 +54,8 @@ struct vector2_ : matrix_<2,1,T> {
|
||||||
return std::acos( dot( a.normalized(), b.normalized() ) );
|
return std::acos( dot( a.normalized(), b.normalized() ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static constexpr auto zero() { return vector2_<T>(0,0); }
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
@ -84,7 +86,9 @@ struct vector3_ : matrix_<3,1,T> {
|
||||||
inline auto xy() const { return vector2_( { x(),y() } ); }
|
inline auto xy() const { return vector2_( { x(),y() } ); }
|
||||||
inline auto homogenous(T w = 1) const { return matrix_<4,1,T>( { x(),y(),z(),w } ); }
|
inline auto homogenous(T w = 1) const { return matrix_<4,1,T>( { x(),y(),z(),w } ); }
|
||||||
|
|
||||||
inline static constexpr vector3_ cross(const vector3_& lhs,const vector3_& rhs) {
|
inline static constexpr vector3_ cross(const vector3_& lhs,
|
||||||
|
const vector3_& rhs)
|
||||||
|
{
|
||||||
return vector3_( {
|
return vector3_( {
|
||||||
lhs[1] * rhs[2] - rhs[1] * lhs[2],
|
lhs[1] * rhs[2] - rhs[1] * lhs[2],
|
||||||
lhs[2] * rhs[0] - rhs[2] * lhs[0],
|
lhs[2] * rhs[0] - rhs[2] * lhs[0],
|
||||||
|
@ -104,6 +108,8 @@ struct vector3_ : matrix_<3,1,T> {
|
||||||
inline static vector3_<T> x_axis() { return vector3_<T> ( { T(1), T(0), T(0) } ); }
|
inline static vector3_<T> x_axis() { return vector3_<T> ( { T(1), T(0), T(0) } ); }
|
||||||
inline static vector3_<T> y_axis() { return vector3_<T> ( { T(0), T(1), T(0) } ); }
|
inline static vector3_<T> y_axis() { return vector3_<T> ( { T(0), T(1), T(0) } ); }
|
||||||
inline static vector3_<T> z_axis() { return vector3_<T> ( { T(0), T(0), T(1) } ); }
|
inline static vector3_<T> z_axis() { return vector3_<T> ( { T(0), T(0), T(1) } ); }
|
||||||
|
|
||||||
|
static constexpr auto zero() { return vector3_(0,0,0); }
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
@ -134,6 +140,8 @@ struct vector4_ : matrix_<4,1,T> {
|
||||||
|
|
||||||
inline auto project() const { return vector3_<T>({ x()/w(),y()/w(),z()/w() } ); }
|
inline auto project() const { return vector3_<T>({ x()/w(),y()/w(),z()/w() } ); }
|
||||||
|
|
||||||
|
static constexpr auto zero() { return vector2_<T>(0,0,0,0); }
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue