summaryrefslogtreecommitdiff
path: root/Runtime/mecanim/math/collider.h
blob: 234281a71a16c4555fef98f3e023cb88336d980c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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);
	}
}