-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCollider.h
71 lines (56 loc) · 1.46 KB
/
Collider.h
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#pragma once
#include "CommonD.h"
class Collider
{
public:
struct Frustum
{
XMFLOAT4 Planes[6];
XMFLOAT3 Corners[8];
};
struct Sphere
{
float Radius;
XMFLOAT3 Center;
Sphere()
{}
Sphere(XMVECTOR center, float rad)
{
XMStoreFloat3(&Center, center);
Radius = rad;
}
};
struct Ray
{
XMFLOAT3 Origin;
XMFLOAT3 Dir;
Ray()
{}
Ray(XMVECTOR ori, XMVECTOR dir)
{
XMStoreFloat3(&Origin, ori);
XMStoreFloat3(&Dir, dir);
}
};
struct AABB
{
XMFLOAT3 Min;
XMFLOAT3 Max;
};
public:
// return Frustum in View space
static Frustum ComputeFrustumFromViewProj(XMFLOAT4X4 matrix);
static bool IsIntersectSphereWithFrustum(Sphere sphere, Frustum frustum);
static bool IsIntersectPointWithFrustum(FXMVECTOR pos, Frustum frustm);
static Ray ComputePickRayFromScreen(int x, int y, int width, int height, XMFLOAT4X4 proj);
static bool IsIntersectSphereWithRay(Ray ray, Sphere sphere);
static bool IsIntersectTriangleWithRay(Ray ray, XMVECTOR v0, XMVECTOR v1, XMVECTOR v2, float& t);
static bool IsIntersectSphereWithSphere(Sphere s1, Sphere s2);
static bool IsIntersectSphereWithPoint(Sphere s, XMVECTOR p);
static Sphere ComputeSphere(FXMVECTOR v1, FXMVECTOR v2, FXMVECTOR v3, CXMVECTOR v4);
static bool IsIntersectAABBWithFrustum(AABB aabb, Frustum frustum);
static bool IsIntersectAABBWithRay(AABB aabb, Ray ray);
static bool IsIntersectAABBWithSphere(AABB aabb, Sphere s);
private:
static float EPSILON;
};