[Super-tux-commit] supertux/src gameloop.cpp,1.198,1.199 player.cpp,1.203,1.204 sector.cpp,1.43,1.44
Brought to you by:
wkendrick
From: Matze B. <mat...@us...> - 2004-11-24 14:10:41
|
Update of /cvsroot/super-tux/supertux/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17739/src Modified Files: gameloop.cpp player.cpp sector.cpp Log Message: furhter improve collision detection by reintroducing time of collision, still more issues to solve Index: player.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/player.cpp,v retrieving revision 1.203 retrieving revision 1.204 diff -u -d -r1.203 -r1.204 --- player.cpp 24 Nov 2004 03:42:57 -0000 1.203 +++ player.cpp 24 Nov 2004 14:10:25 -0000 1.204 @@ -885,9 +885,9 @@ physic.set_velocity_y(.1); } - if(hit.normal.x != 0) { // hit on the side? - if(hit.normal.y > 0.6) // limits the slopes we can move up... - physic.set_velocity_x(0); + if(fabsf(hit.normal.x) > .5) { // hit on the side? + printf("s"); fflush(stdout); + physic.set_velocity_x(0); } return CONTINUE; Index: sector.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/sector.cpp,v retrieving revision 1.43 retrieving revision 1.44 diff -u -d -r1.43 -r1.44 --- sector.cpp 24 Nov 2004 03:42:57 -0000 1.43 +++ sector.cpp 24 Nov 2004 14:10:25 -0000 1.44 @@ -635,7 +635,7 @@ CollisionHit temphit, hit; Rectangle dest = object->get_bbox(); dest.move(object->movement); - hit.depth = -1; + hit.time = -1; // represents an invalid value for(int x = starttilex; x*32 < max_x; ++x) { for(int y = starttiley; y*32 < max_y; ++y) { const Tile* tile = solids->get_tile(x, y); @@ -670,14 +670,14 @@ if(Collision::rectangle_aatriangle(temphit, dest, object->movement, triangle)) { - if(temphit.depth > hit.depth) + if(temphit.time > hit.time) hit = temphit; } } else { // normal rectangular tile Rectangle rect(x*32, y*32, (x+1)*32, (y+1)*32); if(Collision::rectangle_rectangle(temphit, dest, object->movement, rect)) { - if(temphit.depth > hit.depth) + if(temphit.time > hit.time) hit = temphit; } } @@ -685,7 +685,7 @@ } // did we collide at all? - if(hit.depth < 0) + if(hit.time < 0) return; // call collision function @@ -698,7 +698,7 @@ return; } // move out of collision and try again - object->movement += hit.normal * (hit.depth + .001); + object->movement += hit.normal * (hit.depth + .05); collision_tilemap(object, depth+1); } @@ -714,7 +714,6 @@ Vector movement = object1->get_movement() - object2->get_movement(); if(Collision::rectangle_rectangle(hit, dest1, movement, dest2)) { HitResponse response1 = object1->collision(*object2, hit); - Vector hitnormal1 = hit.normal; hit.normal *= -1; HitResponse response2 = object2->collision(*object1, hit); @@ -722,15 +721,15 @@ if(response1 == ABORT_MOVE) object1->movement = Vector(0, 0); if(response2 == CONTINUE) - object2->movement += hit.normal * (hit.depth + .1); + object2->movement += hit.normal * (hit.depth + .05); } else if(response2 != CONTINUE) { if(response2 == ABORT_MOVE) object2->movement = Vector(0, 0); if(response1 == CONTINUE) - object1->movement += hitnormal1 * (hit.depth + .1); + object1->movement += -hit.normal * (hit.depth + .05); } else { - object1->movement += hitnormal1 * (hit.depth/2 + 1); - object2->movement += hit.normal * (hit.depth/2 + 1); + object1->movement += -hit.normal * (hit.depth/2 + .05); + object2->movement += hit.normal * (hit.depth/2 + .05); } } } Index: gameloop.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/gameloop.cpp,v retrieving revision 1.198 retrieving revision 1.199 diff -u -d -r1.198 -r1.199 --- gameloop.cpp 24 Nov 2004 03:42:57 -0000 1.198 +++ gameloop.cpp 24 Nov 2004 14:10:25 -0000 1.199 @@ -723,6 +723,7 @@ float elapsed_time = float(ticks - lastticks) / 1000.; global_time += elapsed_time; lastticks = ticks; + // 40fps is minimum if(elapsed_time > .025) elapsed_time = .025; |