From 5f118170abe44af5383e897b207e85a5870a22c4 Mon Sep 17 00:00:00 2001 From: gewlitys Date: Tue, 3 Dec 2002 20:59:35 +0000 Subject: [PATCH] Slayne's pixel-perfect collision detection patch git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@304 8092fc87-c524-0410-9efc-e669fe64eaf9 --- sc2/ChangeLog | 1 + sc2/TODO | 8 ---- sc2/src/sc2code/libs/graphics/sdl/3do_funcs.c | 41 +++++++++++++++++-- 3 files changed, 38 insertions(+), 12 deletions(-) diff --git a/sc2/ChangeLog b/sc2/ChangeLog index 7cb5ebb67..c4180d093 100644 --- a/sc2/ChangeLog +++ b/sc2/ChangeLog @@ -1,4 +1,5 @@ 0.2: +- Collision detection is now pixel-perfect (fixes Sa-Matra, BUTT missile, etc) - Fixed lander position sign bug which was introduced by previous fixes - Initial display of planet surface on landing is at correct position - Planet scan is now properly erased when cancelling/landing diff --git a/sc2/TODO b/sc2/TODO index b678ae366..b17bda9d3 100644 --- a/sc2/TODO +++ b/sc2/TODO @@ -157,13 +157,6 @@ Stuff still to do (large): Stuff still to do (medium size): - oscilloscope - loading teams in melee -- pixel-perfect collision checks - Currently bounding boxes are used for checks, causing (among others) - Spathi and Mycon to frequently hit themselves, and making the Sa-Matra - indestructable. -- remove libtool dependancy - This will probably mean the empty dummy.c files can be removed too. - (note that src/sc2code/dummy.c DOES contain data) - lines and colouring of planet surface display when scanning. Its speed isn't correct either. - get all code to compile without warnings, when the most strict @@ -192,7 +185,6 @@ Stuff still to do (small): - add some icon in the cvs tree Questions: -- remove src/sc2code/test.c? - Is there some way to automatically do CRLF translations on commits, with the -t and -f options in cvswrapper disabled by sourceforge? - What is the displist stuff for? Is it needed at all? diff --git a/sc2/src/sc2code/libs/graphics/sdl/3do_funcs.c b/sc2/src/sc2code/libs/graphics/sdl/3do_funcs.c index 2c3c9562f..3557e6f6b 100644 --- a/sc2/src/sc2code/libs/graphics/sdl/3do_funcs.c +++ b/sc2/src/sc2code/libs/graphics/sdl/3do_funcs.c @@ -21,6 +21,7 @@ #include "sdl_common.h" #include "pure.h" #include "opengl.h" +#include "primitives.h" int batch_depth = 0; static const BOOLEAN pausing_transition = TRUE; // change to FALSE for non-pausing version @@ -297,15 +298,47 @@ _init_video_file(PVOID pStr) return (ret); } -// Status: Unimplemented +// Status: Implemented BOOLEAN _image_intersect (PIMAGE_BOX box1, PIMAGE_BOX box2, PRECT rect) - // This is a biggie. { BOOLEAN ret; + SDL_Surface *img1, *img2; + int img1w, img1xpos, img1ypos, img2w, img2xpos, img2ypos; + int x,y; + Uint32 img1colourkey, img2colourkey; + GetPixelFn getpixel1, getpixel2; + + /* Image is (TFB_IMAGE*)(box1->FramePtr + box1->FramePtr->DataOffs) */ + img1 = ((TFB_Image*)((BYTE*)(box1->FramePtr) + box1->FramePtr->DataOffs))->NormalImg; + img2 = ((TFB_Image*)((BYTE*)(box2->FramePtr) + box2->FramePtr->DataOffs))->NormalImg; + + getpixel1 = getpixel_for(img1); + getpixel2 = getpixel_for(img2); + + img1w = img1->w; + img1xpos = box1->Box.corner.x; + img1ypos = box1->Box.corner.y; + img1colourkey = img1->format->colorkey; + + img2w = img2->w; + img2xpos = box2->Box.corner.x; + img2ypos = box2->Box.corner.y; + img2colourkey = img2->format->colorkey; + + for (y = rect->corner.y; y < rect->corner.y + rect->extent.height; ++y) + { + for (x = rect->corner.x; x < rect->corner.x + rect->extent.width; ++x) + { + if ((getpixel1(img1, x - img1xpos, y - img1ypos) != img1colourkey) && + (getpixel2(img2, x - img2xpos, y - img2ypos) != img2colourkey)) + { + return TRUE; + } + } + } + ret = FALSE; -// fprintf (stderr, "Unimplemented function activated: _image_intersect()\n"); - ret = TRUE; return (ret); }