vector: make cross function constexpr
This commit is contained in:
parent
c4bb04dee7
commit
b927c8b8e7
17
vector.cpp
17
vector.cpp
@ -85,23 +85,6 @@ template util::vector2f util::to_euler (util::vector3f);
|
|||||||
template util::vector2d util::to_euler (util::vector3d);
|
template util::vector2d util::to_euler (util::vector3d);
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
|
||||||
template <typename T>
|
|
||||||
vector<3,T>
|
|
||||||
util::cross (vector<3,T> a,
|
|
||||||
vector<3,T> b)
|
|
||||||
{
|
|
||||||
return util::vector<3,T> {
|
|
||||||
a.y * b.z - a.z * b.y,
|
|
||||||
a.z * b.x - a.x * b.z,
|
|
||||||
a.x * b.y - a.y * b.x
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
template vector3f util::cross(vector3f, vector3f);
|
|
||||||
template vector3d util::cross(vector3d, vector3d);
|
|
||||||
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
template <typename T>
|
template <typename T>
|
||||||
vector<3,T>
|
vector<3,T>
|
||||||
|
@ -36,11 +36,15 @@ namespace util {
|
|||||||
void sanity (void) const;
|
void sanity (void) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
constexpr
|
||||||
|
vector<3,T>
|
||||||
|
cross (vector<3,T>, vector<3,T>);
|
||||||
|
|
||||||
// polar/cartesian conversions; assumes (mag, angle) form.
|
// polar/cartesian conversions; assumes (mag, angle) form.
|
||||||
template <typename T> vector<2,T> polar_to_cartesian (vector<2,T>);
|
template <typename T> vector<2,T> polar_to_cartesian (vector<2,T>);
|
||||||
template <typename T> vector<2,T> cartesian_to_polar (vector<2,T>);
|
template <typename T> vector<2,T> cartesian_to_polar (vector<2,T>);
|
||||||
|
|
||||||
template <typename T> vector<3,T> cross (vector<3,T>, vector<3,T>);
|
|
||||||
template <typename T> vector<3,T> spherical_to_cartesian (vector<3,T>);
|
template <typename T> vector<3,T> spherical_to_cartesian (vector<3,T>);
|
||||||
template <typename T> vector<3,T> cartesian_to_spherical (vector<3,T>);
|
template <typename T> vector<3,T> cartesian_to_spherical (vector<3,T>);
|
||||||
|
|
||||||
|
14
vector.ipp
14
vector.ipp
@ -32,3 +32,17 @@ util::vector<S,T>::homog (void) const
|
|||||||
static_assert (D > S, "reducing size loses data");
|
static_assert (D > S, "reducing size loses data");
|
||||||
return (*this).template redim<D> (0.f);
|
return (*this).template redim<D> (0.f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
template <typename T>
|
||||||
|
constexpr
|
||||||
|
util::vector<3,T>
|
||||||
|
util::cross (util::vector<3,T> a, util::vector<3,T> b)
|
||||||
|
{
|
||||||
|
return {
|
||||||
|
a.y * b.z - a.z * b.y,
|
||||||
|
a.z * b.x - a.x * b.z,
|
||||||
|
a.x * b.y - a.y * b.x
|
||||||
|
};
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user