#### Archived

This topic is now archived and is closed to further replies.

# IntersectRect()

This topic is 6578 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

In my code, I check if a projectile is not where the user can see it. If so, I destroy it. As with all my collision detection so far, I am trying to use IntersectRect to determine if the projectile''s bounding box is colliding with the screen (or camera, as I actually have a moving camera). As far as I know, if the two RECTs specified are colliding, the return value is non-zero. Otherwise, it is zero. Which leads me to wonder why it doesn''t work. My code looks like this: if (IntersectRect(&Dummy, &Box, Camera) == 0) Destroy(); RECT Dummy is a dummy parameter, which IntersectRect fills with the coordinates of the intersection. RECT Box is the projectile''s bounding box. RECT *Camera is the camera itself. Destroy() destroys the projectile. Projectiles are always immediatly destroyed after creation, and I''ve traced it down to this code. When commented out, the game works correctly aside from projectiles sailing up into the heavens, which will eventually cause an access violation. Any help would be greatly appreciated. Thanks. The_Minister 1C3-D3M0N Interactive

##### Share on other sites
You have it backwards. IntersectRect() returns non-zero if they do intersect, and 0 if they do not.

##### Share on other sites
Sorry my friend, YOU have it backwards . Box wasn''t initialized yet, God I''m such an idiot. Anyways, thanks.

The_Minister
1C3-D3M0N Interactive

##### Share on other sites
From VC++ 6''s documentation of IntersectRect():
Return ValuesIf the rectangles intersect, the return value is nonzero.If the rectangles do not intersect, the return value is zero.

Microsoft is not known for being the best documentation writers around, but I''m suprised to hear that it''s backwards. What does the rest of your code look like?

##### Share on other sites
Hmm sorry I have read your reply incorrectly. I simply read the part that I have it backwards, and I assumed that you mean the opposite of what I had said... you merely told me I had it backwads and then wrote the same words I did.

quote:

As far as I know, if the two RECTs specified are colliding, the return value is non-zero. Otherwise, it is zero. Which leads me to wonder why it doesn't work.

The_Minister
1C3-D3M0N Interactive

Edited by - The_Minister on July 17, 2000 3:50:25 PM

1. 1
2. 2
Rutin
24
3. 3
4. 4
JoeJ
16
5. 5

• 14
• 29
• 11
• 11
• 9
• ### Forum Statistics

• Total Topics
631773
• Total Posts
3002266
×