[Super-tux-commit] supertux/lib/special collision.cpp,1.2,1.3 collision_hit.h,1.1,1.2 frame_rate.cpp
Brought to you by:
wkendrick
From: Matze B. <mat...@us...> - 2004-11-24 14:11:09
|
Update of /cvsroot/super-tux/supertux/lib/special In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17739/lib/special Modified Files: collision.cpp collision_hit.h frame_rate.cpp game_object.cpp moving_object.cpp sprite.cpp sprite.h sprite_data.cpp sprite_data.h sprite_manager.h timer.cpp Log Message: furhter improve collision detection by reintroducing time of collision, still more issues to solve Index: sprite_data.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/lib/special/sprite_data.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- sprite_data.cpp 20 Nov 2004 22:18:32 -0000 1.1 +++ sprite_data.cpp 24 Nov 2004 14:10:23 -0000 1.2 @@ -23,10 +23,10 @@ #include <sstream> #include <stdexcept> -#include "../app/globals.h" -#include "../app/setup.h" -#include "../special/sprite.h" -#include "../video/drawing_context.h" +#include "sprite_data.h" +#include "app/globals.h" +#include "app/setup.h" +#include "video/drawing_context.h" namespace SuperTux { Index: moving_object.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/lib/special/moving_object.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- moving_object.cpp 20 Nov 2004 22:14:36 -0000 1.4 +++ moving_object.cpp 24 Nov 2004 14:10:23 -0000 1.5 @@ -19,7 +19,7 @@ #include <config.h> -#include "../special/moving_object.h" +#include "moving_object.h" using namespace SuperTux; Index: frame_rate.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/lib/special/frame_rate.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- frame_rate.cpp 20 Nov 2004 22:14:36 -0000 1.3 +++ frame_rate.cpp 24 Nov 2004 14:10:23 -0000 1.4 @@ -20,8 +20,8 @@ #include "SDL.h" -#include "../special/frame_rate.h" -#include "../special/timer.h" +#include "frame_rate.h" +#include "timer.h" using namespace SuperTux; Index: game_object.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/lib/special/game_object.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- game_object.cpp 20 Nov 2004 22:14:36 -0000 1.4 +++ game_object.cpp 24 Nov 2004 14:10:23 -0000 1.5 @@ -19,7 +19,7 @@ #include <config.h> -#include "../special/game_object.h" +#include "special/game_object.h" namespace SuperTux { Index: sprite.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/lib/special/sprite.cpp,v retrieving revision 1.31 retrieving revision 1.32 diff -u -d -r1.31 -r1.32 --- sprite.cpp 22 Nov 2004 23:47:49 -0000 1.31 +++ sprite.cpp 24 Nov 2004 14:10:23 -0000 1.32 @@ -23,10 +23,10 @@ #include <cassert> #include <stdexcept> -#include "../app/globals.h" -#include "../app/setup.h" -#include "../special/sprite.h" -#include "../video/drawing_context.h" +#include "app/globals.h" +#include "app/setup.h" +#include "sprite.h" +#include "video/drawing_context.h" namespace SuperTux { Index: sprite_data.h =================================================================== RCS file: /cvsroot/super-tux/supertux/lib/special/sprite_data.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- sprite_data.h 20 Nov 2004 22:14:36 -0000 1.1 +++ sprite_data.h 24 Nov 2004 14:10:23 -0000 1.2 @@ -24,8 +24,8 @@ #include <vector> #include <map> -#include "../utils/lispreader.h" -#include "../video/surface.h" +#include "utils/lispreader.h" +#include "video/surface.h" namespace SuperTux { Index: collision.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/lib/special/collision.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- collision.cpp 24 Nov 2004 03:42:57 -0000 1.2 +++ collision.cpp 24 Nov 2004 14:10:22 -0000 1.3 @@ -26,37 +26,38 @@ if(r1.p2.y < r2.p1.y || r1.p1.y > r2.p2.y) return false; - float xr; if(movement.x > DELTA) { hit.depth = r1.p2.x - r2.p1.x; + hit.time = hit.depth / movement.x; hit.normal.x = -1; hit.normal.y = 0; - xr = hit.depth / movement.x; } else if(movement.x < -DELTA) { hit.depth = r2.p2.x - r1.p1.x; + hit.time = hit.depth / -movement.x; hit.normal.x = 1; hit.normal.y = 0; - xr = hit.depth / -movement.x; } else { - xr = FLT_MAX; if(movement.y > -DELTA && movement.y < DELTA) { return false; } + hit.time = FLT_MAX; } if(movement.y > DELTA) { float ydepth = r1.p2.y - r2.p1.y; - float yr = ydepth / movement.y; - if(yr < xr) { + float yt = ydepth / movement.y; + if(yt < hit.time) { hit.depth = ydepth; + hit.time = yt; hit.normal.x = 0; hit.normal.y = -1; } } else if(movement.y < -DELTA) { float ydepth = r2.p2.y - r1.p1.y; - float yr = ydepth / -movement.y; - if(yr < xr) { + float yt = ydepth / -movement.y; + if(yt < hit.time) { hit.depth = ydepth; + hit.time = yt; hit.normal.x = 0; hit.normal.y = 1; } Index: sprite.h =================================================================== RCS file: /cvsroot/super-tux/supertux/lib/special/sprite.h,v retrieving revision 1.17 retrieving revision 1.18 diff -u -d -r1.17 -r1.18 --- sprite.h 20 Nov 2004 22:14:36 -0000 1.17 +++ sprite.h 24 Nov 2004 14:10:23 -0000 1.18 @@ -24,9 +24,9 @@ #include <vector> #include <map> -#include "../utils/lispreader.h" -#include "../video/surface.h" -#include "../math/vector.h" +#include "utils/lispreader.h" +#include "video/surface.h" +#include "math/vector.h" #include "sprite_data.h" namespace SuperTux Index: timer.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/lib/special/timer.cpp,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- timer.cpp 20 Nov 2004 22:14:36 -0000 1.5 +++ timer.cpp 24 Nov 2004 14:10:23 -0000 1.6 @@ -21,7 +21,7 @@ #include <config.h> #include "SDL.h" -#include "../special/timer.h" +#include "timer.h" using namespace SuperTux; Index: collision_hit.h =================================================================== RCS file: /cvsroot/super-tux/supertux/lib/special/collision_hit.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- collision_hit.h 20 Nov 2004 22:14:36 -0000 1.1 +++ collision_hit.h 24 Nov 2004 14:10:23 -0000 1.2 @@ -44,7 +44,9 @@ public: /// penetration depth float depth; - // The normal of the side we collided with + /// time of the collision (between 0 and 1 in relation to movement) + float time; + /// The normal of the side we collided with Vector normal; }; Index: sprite_manager.h =================================================================== RCS file: /cvsroot/super-tux/supertux/lib/special/sprite_manager.h,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- sprite_manager.h 20 Nov 2004 22:14:36 -0000 1.4 +++ sprite_manager.h 24 Nov 2004 14:10:23 -0000 1.5 @@ -22,7 +22,7 @@ #include <map> -#include "../special/sprite.h" +#include "sprite.h" namespace SuperTux { |