-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphys_util.cpp
More file actions
72 lines (61 loc) · 2.02 KB
/
phys_util.cpp
File metadata and controls
72 lines (61 loc) · 2.02 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
#include <cmath>
#include "phys_util.h"
using std::abs;
using std::cos;
using std::sin;
using std::acos;
void regularPolygon(Polygon& poly, int sides, int rad)
{
for(int i = 0; i < sides; ++i)
{
Vec vertex{rad * cos( 2*acos(-1) / sides * i ),
rad * sin( 2*acos(-1) / sides * i )};
poly.addVertex(vertex);
}
}
void setAABB(Rect& AABB, const Polygon& o, float margin)
{
if(o.verts() > 0)
{
float xmin = o.vertexTrans(0).x;
float xmax = xmin;
float ymin = o.vertexTrans(0).y;
float ymax = ymin;
for(uint i = 1; i < o.verts(); ++i)
{
if(o.vertexTrans(i).x < xmin)
xmin = o.vertexTrans(i).x;
else if(o.vertexTrans(i).x > xmax)
xmax = o.vertexTrans(i).x;
if(o.vertexTrans(i).y < ymin)
ymin = o.vertexTrans(i).y;
else if(o.vertexTrans(i).y > ymax)
ymax = o.vertexTrans(i).y;
}
AABB.min.set(xmin - margin, ymin - margin);
AABB.max.set(xmax + margin, ymax + margin);
}
}
void setAABB(Rect& AABB, const Cluster& o, float margin)
{
if(o.objSet().size() > 0)
{
float xmin = o.objSet()[0]->bound_box.min.x;
float xmax = xmin;
float ymin = o.objSet()[0]->bound_box.min.y;
float ymax = ymin;
for(uint i = 0; i < o.objSet().size(); ++i)
{
if(o.objSet()[i]->bound_box.min.x < xmin)
xmin = o.objSet()[i]->bound_box.min.x;
else if(o.objSet()[i]->bound_box.max.x > xmax)
xmax = o.objSet()[i]->bound_box.max.x;
if(o.objSet()[i]->bound_box.min.y < ymin)
ymin = o.objSet()[i]->bound_box.min.y;
else if(o.objSet()[i]->bound_box.max.y > ymax)
ymax = o.objSet()[i]->bound_box.max.y;
}
AABB.min.set(xmin - margin, ymin - margin);
AABB.max.set(xmax + margin, ymax + margin);
}
}