forked from KevinHall2/CustomPhysics
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShapes.h
More file actions
69 lines (54 loc) · 2.87 KB
/
Copy pathShapes.h
File metadata and controls
69 lines (54 loc) · 2.87 KB
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
#pragma once
#include <cstdint>
#include "glm/vec2.hpp"
struct Circle
{
float Radius = 1.0f;
};
struct AABB
{
//Represents 2 floats, or 4 bytes * 2, or 8 bytes total
glm::vec2 HalfExtents;
};
enum class ShapeType : uint8_t
{
NONE = 0,
CIRCLE = 1 << 0,
AABB = 1 << 1
};
struct Shape
{
ShapeType Type;
//Anonymous union that holds the data for the shape defined by this object
//Access to its members aren't done via a name, but through directly referencing its members
union
{
Circle CircleData;
AABB AABBData;
};
};
//Tests if two circles at their given locations and shape are in collision
//Returns true if collision occurs, false otherwise
bool CheckCircleCircle(const glm::vec2& Circle1Position, const Circle& Circle1Shape, const glm::vec2& Circle2Position, const Circle& Circle2Shape);
//Tests if two AABBs at their given locations and shape are in collision
//Returns true if collision occurs, false otherwise
bool CheckAABBAABB(const glm::vec2& AABB1Position, const AABB& AABB1Shape, const glm::vec2& AABB2Position, const AABB& AABB2Shape);
//Tests if two shapes (assuming they're circles) at their given locations and shape are in collision
//Returns true if collision occurs, false otherwise
bool CheckCircleCircle(const glm::vec2& Shape1Position, const Shape& Shape1, const glm::vec2& Shape2Position, const Shape& Shape2);
//Tests if two shapes (assuming they're AABBs) at their given locations and shape are in collision
//Returns true if collision occurs, false otherwise
bool CheckAABBAABB(const glm::vec2& Shape1Position, const Shape& Shape1, const glm::vec2& Shape2Position, const Shape& Shape2);
//Tests if a circle and AABB at their given locations and shape are in collision
//Returns true if collision occurs, false otherwise
bool CheckCircleAABB(const glm::vec2& Shape1Position, const Shape& Shape1, const glm::vec2& Shape2Position, const Shape& Shape2);
//Determines the minimum translation vector (MTV) to separate two circles
glm::vec2 DepenetrateCircleCircle(const glm::vec2& PositionA, const Circle& CircleA, const glm::vec2& PositionB, const Circle& CircleB, float& Penetration);
//Determines the minimum translation vector (MTV) to separate two shapes (assuming they're circles)
glm::vec2 DepenetrateCircleCircle(const glm::vec2& PositionA, const Shape& ShapeA, const glm::vec2& PoistionB, const Shape& ShapeB, float& Penetration);
//Determines the minimum translation vector (MTV) to separate two AABBs
glm::vec2 DepenetrateAABBAABB(const glm::vec2& PositionA, const Shape& AABB1, const glm::vec2& PositionB, const Shape& AABB2, float& Penetration);
//Determines the minimum translation vector (MTV) to separate a circle and an AABB
glm::vec2 DepenetrateCircleAABB(const glm::vec2& PositionA, const Circle& CircleA, const glm::vec2& PositionB, const AABB& AABB, float& Penetration);
//Finds the center of a circle
glm::vec2 GetCenter(float x1, float x2, float y1, float y2);