-
Notifications
You must be signed in to change notification settings - Fork 2
/
staticEntity.cpp
42 lines (33 loc) · 911 Bytes
/
staticEntity.cpp
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
#include "staticEntity.h"
staticEntity::staticEntity(std::string s, float _x, float _y)
{
setTexture(s);//inherited drawable function
setPosition(_x, _y);
}
void staticEntity::setb2Object(b2World* world, std::vector<b2Vec2> shape, int verticecount, uint16 categoryBits, uint16 maskBits)
{
b2BodyDef bd;
bd.position.Set(x/scale, y/scale);
bd.type = b2_staticBody;
body = world->CreateBody(&bd);
b2Vec2* arr = new b2Vec2[verticecount];
auto itr = shape.begin();
int i = 0;
for(itr; itr != shape.end(); ++itr)
{
arr[i].Set((*itr).x, (*itr).y);
++i;
}
b2PolygonShape pshape;
//pshape.SetAsBox(550.f/(2*scale), 150.f/(2*scale));
pshape.Set(arr, verticecount);
b2FixtureDef fd;
fd.shape = &pshape;
fd.density = 0;
fd.friction = 1.f;
fd.filter.categoryBits = categoryBits;
fd.filter.maskBits = maskBits;
fd.userData = (void*)2;
body->CreateFixture(&fd);
body->SetUserData(this);
}