Help with collision detection 
Author Message
 Help with collision detection

I'm trying to write a simple game, and i was told that the easiest and fastest way to do collision
testing was through a api call. I got a function from a friend of mine called IntersectRect in the user.dll.
I am so close to getting this to work i just wish that i could figure it out. Can anyone help me out with
this?

It's declared like this:

Declare Function IntersectRect Lib "user" (lpDestRect As tBitMap, lpSrc1Rect As tBitMap, lpSrc2Rect As
tBitMap) As Long

and i have tBitMap as this:

Type tBitMap
    Left As Long
    Top As Long
    Right As Long
    Bottom As Long
    Width As Long
    Height As Long
End Type

What i really need to know is what does lpDestRect, lpSrc1Rect, and lpSrc2Rect stand for. when i set each of
these equal i get a collision, but i only want to check for collision in 2 things not 3????

        Alien



Wed, 06 Oct 1999 03:00:00 GMT  
 Help with collision detection

Just a guess, but DestRect ought to return any rectangle common to the other
two.

1. Put the dimensions of the bitmaps to be tested in Src1Rect and Src2Rect.
2. Dim an empty DestRect (.Width, .Height set to 0.)
3. Then call the IntersectRect API and
4. check the .Width and .Height of DestRect.
5. If they are non-zero, you have a hit.

The long return value probably is used for error detection.

If this doesn't work, look in the MSDN dir on your VB4 CD. (You have to run the
setup program in there.) There is full help for these functions, but I don't
have it here at work.



Sat, 09 Oct 1999 03:00:00 GMT  
 Help with collision detection

Quote:

>I'm trying to write a simple game, and i was told that the easiest and fastest
> way to do collision
>testing was through a api call. I got a function from a friend of mine called
> IntersectRect in the user.dll.
>I am so close to getting this to work i just wish that i could figure it out.
> Can anyone help me out with
>this?

>It's declared like this:

>Declare Function IntersectRect Lib "user" (lpDestRect As tBitMap, lpSrc1Rect As
> tBitMap, lpSrc2Rect As
>tBitMap) As Long

>and i have tBitMap as this:

>Type tBitMap
>    Left As Long
>    Top As Long
>    Right As Long
>    Bottom As Long
>    Width As Long
>    Height As Long
>End Type

>What i really need to know is what does lpDestRect, lpSrc1Rect, and lpSrc2Rect
> stand for. when i set each of
>these equal i get a collision, but i only want to check for collision in 2
> things not 3????

>        Alien

First, if you haven't already bought it I would recommend that you run out and
get Daniel Appleman's book "Visual Basic Programmer's Guide to the Windows
API". It comes in many flavors based on 16- and 32-bit Windows and VB3, 4 and
5. It is the best reference for this type of programming.

As for IntersectRect...

What this function does is load into lpDestRec the values describing a
rectangle that includes all the common points of the two source rectangles. It
is used to find the intersecting rectangle not detect it. Fortunately, if
there are no points in common the destination rectangle will be set to an
empty rectangle and the return value will be zero.

So, just use a dummy RECT type variable for the lpDestRect and the result of
calling the function will be nonzero if a collision is detected or zero if no
collision is detected.

Hope this helps.

-Stu



Fri, 22 Oct 1999 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Help with collision detection (rectangular)

2. Bad collision detection..Help??

3. Collision detection routines between images

4. Sprites and collision detection

5. Collision detection problems w/ scrolling?

6. Collision detection

7. Collision detection

8. VB InterSectRect Collision detection...

9. Collision Detection

10. collision detection

11. Collision Detection Problems

12. Collision Detection in VB5

 

 
Powered by phpBB® Forum Software