[gameprogrammer] Re: Bounding Rectangles

  • From: "Alan Wolfe" <alan.wolfe@xxxxxxxxx>
  • To: gameprogrammer@xxxxxxxxxxxxx
  • Date: Sun, 2 Sep 2007 08:57:01 -0700

of you store x1,y1,x2,y2 instead of x1,width,y2,height, AND you make
sure that your width and height of all your boxes is greater than 0,
this test would take alot less comparisons and no adds (:

I was talking about it in another thread but there is a GREAT book
called "Real time collision detection" that we keep around the office
for reference when we need detection methods.  It's really worth while
picking up a copy

http://www.amazon.com/Real-Time-Collision-Detection-Interactive-Technology/dp/1558607323

On 9/2/07, Stephen Smith <gp@xxxxxxxxxxxxxxxxxxxxxxxx> wrote:
> A bounding rectangle is just a simple way of defining the shape of a
> sprite, to avoid any complex calculations that would be involved if you
> wanted to check each individual pixel for a collision.
>
> The code to determine a collision would just be something like:-
>
> |public boolean intersects(Rectangle
> <http://kickjava.com/src/java/awt/Rectangle.java.htm> r)
> {
>   return r.width > 0 && r.height > 0 && this.width > 0 &&
> ||this.||height > 0
>     && r.x < x + ||this.||width && r.x + r.width > ||this.||x
>     && r.y < y + ||this.||height && r.y + r.height > ||this.||y;
> }|
>
> (This is from Java BTW.  I hope it makes sense out of context).  You
> just then run this function against each sprite against each other
> sprite to check for collisions.
>
> Steve
>
>
>
> Azeem Zaheer wrote:
> > Hi,I want to know how to detect collision in 2D Side-Scrolling C++
> > game like Mario?
> > without using any game engine or library?
> > Some basics about how will i know the player is hit by the enemy?
> > Whats meant by the term 'Bounding Rectangles'?
> >
> >
> > ------------------------------------------------------------------------
> > Explore the seven wonders of the world Learn more!
> > <http://search.msn.com/results.aspx?q=7+wonders+world&mkt=en-US&form=QBRE>
>
> ---------------------
> To unsubscribe go to http://gameprogrammer.com/mailinglist.html
>
>
>

---------------------
To unsubscribe go to http://gameprogrammer.com/mailinglist.html


Other related posts: