-
Notifications
You must be signed in to change notification settings - Fork 0
/
Circle.h
51 lines (48 loc) · 1.28 KB
/
Circle.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
#ifndef CIRCLE_H
#define CIRCLE_H
#include "Shape.h"
class Circle : public Shape {
friend class Physics;
public:
static const int ShapeType = 1;
private :
double radius;
public :
Circle() : Shape() {
radius = 1.;
density = 1.;
Update();
}
void Update() {
mass = density * sqr(radius) * pi;
inertia = density * sqr(sqr(radius)) * pi / 2.;
}
void GetProjection(Vector2D normal, double &minI, double &maxI) {
minI = maxI = GetCentroidPosition() * normal;
minI -= radius; maxI += radius;
}
int GetType() {
return ShapeType;
}
void Redraw() {
graphics.DrawCircle(GetTransformToWorld()(centroidPosition), radius, color);
graphics.DrawLine(GetTransformToWorld()(centroidPosition), GetTransformToWorld()(centroidPosition + Vector2D(radius, 0, 0)));
}
bool IsPointInside(Vector2D p) const {
return sgn((GetTransformToWorldInverse()(p) - centroidPosition).GetLength2() - sqr(radius)) <= 0;
}
void Move(Vector2D vec) {
centroidPosition += vec;
}
static Circle *GenerateCircle(double radius) {
Circle *cir = new Circle();
cir->radius = radius;
cir->Update();
return cir;
}
AABB GetAABB() {
Vector2D worldCentroid = GetCentroidPosition();
return AABB(worldCentroid.x - radius, worldCentroid.y - radius, worldCentroid.x + radius, worldCentroid.y + radius);
}
};
#endif