-
Notifications
You must be signed in to change notification settings - Fork 0
/
Circle.hpp
81 lines (57 loc) · 1.54 KB
/
Circle.hpp
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 Circle_HPP
#define Circle_HPP
#include <algorithm>
#include "allegro5/allegro.h"
#include "allegro5/allegro_primitives.h"
#include "Arrow.hpp"
extern double ELASTICITY;
extern double EPSILON;
class Circle;
bool Overlaps(const Circle& c1 , const Circle& c2);
double CalculateCollision(Circle* , Circle*);
typedef bool (*CRESOLVER)(Circle* , Circle*);
extern CRESOLVER cresolver;
class Circle {
public :
double cx,cy,rad;
double vx,vy;
bool active;
bool fixed;/// Fixed, immovable, infinite mass
double density;
double mass;
Circle();
Circle(double x , double y , double r);
inline bool Overlaps(const Circle& c) {return ::Overlaps(*this , c);}
inline void Draw(ALLEGRO_COLOR col) {
al_draw_filled_circle(cx , cy , rad , al_map_rgb(0,0,0));
al_draw_circle(cx , cy , rad , col , 3.0);
Vec2 c(cx,cy);
Vec2 v(vx,vy);
DrawArrow(c , c + v , al_map_rgb(0,0,255));
}
inline void DrawHollow(ALLEGRO_COLOR col) {
/// al_draw_filled_circle(cx , cy , rad , al_map_rgb(0,0,0));
al_draw_circle(cx , cy , rad , col , 3.0);
Vec2 c(cx,cy);
Vec2 v(vx,vy);
DrawArrow(c , c + v , al_map_rgb(0,0,255));
}
/// inline void SetSpeed(double sx , double sy);
inline void SetSpeed(double sx , double sy) {
vx = sx;
vy = sy;
}
inline void Stop() {
vx = 0.0;
vy = 0.0;
}
inline void Update(double dt) {
cx += vx*dt;
cy += vy*dt;
}
inline void Reverse() {
vx = -vx;
vy = -vy;
}
};
#endif // Circle_HPP