Exact Collision detection

Blitz3D Forums/Blitz3D Beginners Area/Exact Collision detection

Mental Image(Posted 2003) [#1]
Anyone know a quick way that I can determine if a rectangular area of the screen is EXACTLY the same as a test image? All of the Blitz collision detection routines check if ANY pixels collide - I want to know if all of them collide in, say a 32x32 rectangle.

As an example, in a painter-type game, I would like to determine if the outer edge of a rectangle is completely filled by comparing it against a previously filled block (maybe I just have to check the lines, somehow?)

Ta,


ford escort(Posted 2003) [#2]
depend of what you call quick.
the only method i know is to read each pixel of the two image and if a pixel is different exit the checking loop
as the fastest method is to check if a picture is different it's generaly quicker:)
Graphics 800,600,32,0
ClsColor 50,50,50
a=CreateImage(32,32)
b=CreateImage(32,32)
Cls
DrawBlock a,10,10
DrawBlock b,45,10
Text 0,40,checkmatch(a,b)
Flip 
WaitKey
SetBuffer ImageBuffer(a)
Plot 10,10
SetBuffer FrontBuffer()
Cls
DrawBlock a,10,10
DrawBlock b,45,10
Text 0,40,checkmatch(a,b)
Flip 
WaitKey



Function checkmatch(picta,pictb)
	x=-1:y=0
	Repeat
	x=x+1
	If x>31
		y=y+1
		x=0
	EndIf
	Until (ReadPixel(x,y,ImageBuffer(picta))<>ReadPixel(x,y,ImageBuffer(pictb))) Or (x=0 And y>31)
	If x=0 And y>31
		Return -1 ;match
	Else
		Return 0 ;no match
	EndIf
End Function

this method is fast if the tiles are really different but take more time on testing graphics that differs by one or two pixels if they are far from the start of the check


semar(Posted 2003) [#3]
@Mental Image,
I don't get completely your question.

What I understand is that:
- you have image_1 on the screen, at x,y
- you have image_2 that overlaps image_2; when image_2 is at the same x,y, you want to know if image_2 is the same of image_1 - right ?

If so, perhaps you can change the way to determine it.

I mean, since you draw image_1 at x,y, that means you have image_1s pointer, because you have to draw it in any case:
Drawimage image_1, x, y

That said, when image_2 is drawn at the same x,y of image_1, then you could easily check if image_2 pointer is the same pointer of image_1.

Sorry for the 'words game' here, I try to explain me better.

Suppose you load your images in an array:
arr_img(1) = loadimage("image_1.png")
arr_img(2) = loadimage("image_2.png")
and so on.

So, when you draw an image on the screen, you can use that array of image pointer:
drawimage arr_img(n),x,y ;where n is an arbitrary index.

Now, when two images are drawn at the same coordinates, and you want to check if they are the same, there's nothing easier:

S is the index of the image on the Screen
M is the index of the image you are Moving on the screen

if arr_img(S) = arr_img(M) then
;the two images are the same
endif

That's only to make you understand the concept; because you will find soon that there's an easier way to discover if the two images are the same, with this simple test:
If S = M then
;the images are the same !
endif

Of course, this method works if you use an array of images, and I assume that the array does not contain two times the same image.

If your test image is smaller than the one on the screen - ex. for puzzle games or something similar - then you could organize the big image being made with small tiles, each tile having the same size of the tile you use as test.

All the tiles should be stored in an array, and you have done.

Hope this has sense for you,
Sergio.