3 void CollisionManager::subscribe(Thing
* thing
){
7 void CollisionManager::remove(Thing
* thing
){
11 void CollisionManager::update(){
12 std::set
<Thing
*>::iterator it1
,it2
;
13 for (it1
= things
.begin(); it1
!= things
.end(); it1
++) {
14 for (it2
= it1
; it2
!= things
.end(); it2
++) {
15 if (*it1
== *it2
) continue;
16 checkCollision(*it1
,*it2
);
21 bool pointInsidePolygon(Ponto ponto
, Polygon p
) {
22 std::vector
<Linha
>::iterator it
;
23 Ponto
infinito(0xffffff,ponto
.y
);
25 Linha
toinfinity(ponto
,infinito
);
26 for (it
= p
.linhas
.begin(); it
!= p
.linhas
.end(); it
++) {
27 if (linesIntersect(*it
,toinfinity
)) {
37 bool CollisionManager::checkCollision(Thing
* a
, Thing
* b
){
39 pa
= a
->getCollision();
40 pb
= b
->getCollision();
41 pa
.translate(a
->getPosition());
42 pb
.translate(b
->getPosition());
43 std::vector
<Linha
>::iterator ita
,itb
;
44 if (pointInsidePolygon(pb
.linhas
[0].vertices
[0],pa
)) {
49 for (ita
= pa
.linhas
.begin(); ita
!= pa
.linhas
.end(); ita
++) {
50 for (itb
= pb
.linhas
.begin(); itb
!= pb
.linhas
.end(); itb
++) {
51 /*std::cout<<"A:"<<(*ita).vertices[0].x<<" "<<(*ita).vertices[0].y<<" "
52 <<(*ita).vertices[1].x<<" "<<(*ita).vertices[1].y<<std::endl;
53 std::cout<<"B:"<<(*itb).vertices[0].x<<" "<<(*itb).vertices[0].y<<" "
54 <<(*itb).vertices[1].x<<" "<<(*itb).vertices[1].y<<std::endl;*/
55 if (linesIntersect(*ita
,*itb
)) {