-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPhysics.hpp
More file actions
81 lines (69 loc) · 1.56 KB
/
Physics.hpp
File metadata and controls
81 lines (69 loc) · 1.56 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
70
71
72
73
74
75
76
77
78
79
80
81
#ifndef PHYSICS_HPP
#define PHYSICS_HPP
#include <iostream>
#include <cmath>
struct Vec2 {
float x, y;
Vec2() : x(0), y(0) {}
Vec2(float x, float y) : x(x), y(y) {}
// Addition
Vec2 operator+(const Vec2& other) const {
return Vec2(x + other.x, y + other.y);
}
// Subtraction
Vec2 operator-(const Vec2& other) const {
return Vec2(x - other.x, y - other.y);
}
// Multiplication
Vec2 operator*(float scalar) const {
return Vec2(x * scalar, y * scalar);
}
// Division
Vec2 operator/(float scalar) const {
return Vec2(x / scalar, y / scalar);
}
// Compound addition
Vec2& operator+=(const Vec2& other) {
x += other.x;
y += other.y;
return *this;
}
// Compound subtraction
Vec2& operator-=(const Vec2& other) {
x -= other.x;
y -= other.y;
return *this;
}
// Compound multiplication
Vec2& operator*=(float scalar) {
x *= scalar;
y *= scalar;
return *this;
}
// Compound division
Vec2& operator/=(float scalar) {
x /= scalar;
y /= scalar;
return *this;
}
};
struct AABB {
Vec2 min;
Vec2 max;
};
struct Object {
Vec2 pos;
AABB aabb;
};
struct Manifold {
Object *A, *B;
Vec2 normal;
float penetration;
};
// Compare objects
bool AABBvsAABB( Manifold *m );
// Function to convert Vec2 to sf::Vector2f
sf::Vector2f toSF(const Vec2& v);
// Function to get dot product
float Dot(const Vec2& a, const Vec2& b);
#endif // PHYSICS_HPP