-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPhysics.h
More file actions
46 lines (34 loc) · 2.36 KB
/
Physics.h
File metadata and controls
46 lines (34 loc) · 2.36 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
//
// Created by Parth on 12/20/2019.
//
#ifndef PHYSICS_ENGINE_PHYSICS_H
#define PHYSICS_ENGINE_PHYSICS_H
#include "TransformObject.h"
#include "polygons/Rectangle.h"
#include "polygons/Circle.h"
class Physics {
private:
static float gravity[2];
static bool rectanglerectangleCollision(Rectangle* rectangle1, Rectangle* rectangle2, float &minOverlap, std::array<float, 2> &contactPoint, std::array<float, 2> &axis);
static bool rectangleCircleCollision(Rectangle* rectangle, Circle* circle, float &maxPenetration, int &faceIndex);
static bool circleCircleCollision(Circle* circle1, Circle* circle2);
static void getMinMaxProjection(Rectangle* rectangle, float axisX, float axisY, float &minProjection, float &maxProjection, int &minIndex, int &maxIndex);
static std::array<float, 2> getSupportPoint(Rectangle* rectangle, float axisX, float axisY);
static float getPenetration(int &faceIndex, Rectangle* rectangle1, Rectangle* rectangle2);
static std::array<float, 2> calculateContactPoint(Rectangle* rectangle, int faceIndex);
static std::array<float, 2> calculateContactPoint(Rectangle* rectangle, Circle* circle, float maxPenetration, int faceIndex);
static void resolveOverlap(TransformObject &object, float maxPenetration, int faceIndex);
static void resolveOverlap(TransformObject &object, float minOverlap, std::array<float, 2> axis);
public:
constexpr static float deltaTime = 0.01f;
static void updatePosition(TransformObject &transformObject);
static void updateRotation(TransformObject &transformObject);
static void setGravity(float x, float y);
static float getGravityX();
static float getGravityY();
static bool polygonCollisionDetected(TransformObject object1, TransformObject object2, float &minOverlap, std::array<float, 2> &contactPoint, std::array<float, 2> &axis);
static bool collisionDetected(TransformObject object1, TransformObject object2, float &maxPenetration, int &faceIndex);
static void resolveCollision(TransformObject &object1, TransformObject &object2, float penetration, int faceIndex);
static void resolvePolygonCollision(TransformObject &object1, TransformObject &object2, float minOverlap, std::array<float, 2> contactPoint, std::array<float, 2> axis);
};
#endif //PHYSICS_ENGINE_PHYSICS_H