diff options
author | chai <chaifix@163.com> | 2019-08-14 22:50:43 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2019-08-14 22:50:43 +0800 |
commit | 15740faf9fe9fe4be08965098bbf2947e096aeeb (patch) | |
tree | a730ec236656cc8cab5b13f088adfaed6bb218fb /Runtime/mecanim/math/collider.h |
Diffstat (limited to 'Runtime/mecanim/math/collider.h')
-rw-r--r-- | Runtime/mecanim/math/collider.h | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/Runtime/mecanim/math/collider.h b/Runtime/mecanim/math/collider.h new file mode 100644 index 0000000..234281a --- /dev/null +++ b/Runtime/mecanim/math/collider.h @@ -0,0 +1,55 @@ +#pragma once + +#include "Runtime/mecanim/defs.h" +#include "Runtime/mecanim/types.h" +#include "Runtime/Math/Simd/xform.h" + +#include "Runtime/Serialize/TransferFunctions/SerializeTransfer.h" + +namespace math +{ + enum ColliderType { kNone = 0, kCube, kSphere, kCylinder, kCapsule }; + enum JointType { kIgnored = 0, kLocked, kLimited }; + + struct Collider + { + DEFINE_GET_TYPESTRING(Collider) + + xform m_X; + mecanim::uint32_t m_Type; // ColliderType + + inline Collider() : m_Type(kCube) {} + + // Joint information + mecanim::uint32_t m_XMotionType; + mecanim::uint32_t m_YMotionType; + mecanim::uint32_t m_ZMotionType; + float m_MinLimitX; + float m_MaxLimitX; + float m_MaxLimitY; + float m_MaxLimitZ; + + template<class TransferFunction> + inline void Transfer (TransferFunction& transfer) + { + TRANSFER(m_X); + TRANSFER(m_Type); + TRANSFER(m_XMotionType); + TRANSFER(m_YMotionType); + TRANSFER(m_ZMotionType); + TRANSFER(m_MinLimitX); + TRANSFER(m_MaxLimitX); + TRANSFER(m_MaxLimitY); + TRANSFER(m_MaxLimitZ); + } + }; + + STATIC_INLINE float4 SphereCollide(math::xform const &sphereX,math::float4 const &pos) + { + math::float4 ret = math::xformInvMulVec(sphereX,pos); + + ret *= math::rcp(math::length(ret)); + + return math::xformMulVec(sphereX,ret); + } +} |