[gameprogrammer] Bouncing Ball (Sleeping in math class)
- From: Scott Harper <lareon@xxxxxxxxxxx>
- To: gameprogrammer@xxxxxxxxxxxxx
- Date: Sat, 27 Nov 2004 01:14:45 -0700
Okay, I realize I should have paid better attention (or taken better
notes) in College Algebra for this, but here's my issue. I've got the
"bouncing ball"... That's easy. NOW, I want the ball to bounce
(accurately) off of some arbitrarily sized rectangle in the middle of
the window.
I've got some bounding-box collision detection going on to determine if
I need to do something more. Right about as I finished that, I realized
how much MORE I needed to do, and that simply swapping the x/y delta
value would no longer be suitable. I've looked online, but cannot find
a tutorial which discusses this.
I need two things. First, to figure out WHERE the collision hits --
which vertex or line segment I need to bounce the ball off of. Second,
I need to figure out how to get the NEW vector of the ball's movement.
I can get the plane of reflection:
if sub 'o' is the origin of the ball
and sub 'r' is the point (at radius of circle) of impact
(Yo - Yr) / (Xo - Xr) = slope from center of ball
-(Xo - Xr) / (Yo - Yr) = slope of reflection
But now my problem is this: how do you reflect a vector across a plane
that isn't (1, 0), (0, 1), or (x, y)?
Also, will there be any problems because I process the reflection the
first frame AFTER it happens (meaning that the ball has already
intersected the square)? and how do I handle that if need be?
So sorry for asking the (doubtlessly) simple math question et al...
Thanks,
--Scott
---------------------
To unsubscribe go to http://gameprogrammer.com/mailinglist.html
- Follow-Ups:
- [gameprogrammer] Re: Bouncing Ball (Sleeping in math class)
- From: Petri Latvala
- [gameprogrammer] [SDL, OpenGL and SDL_ttf] Need help
- From: Mister
Other related posts:
- » [gameprogrammer] Re: Bouncing Ball (Sleeping in math class)
- » [gameprogrammer] Bouncing Ball (Sleeping in math class)
- » [gameprogrammer] Re: Bouncing Ball (Sleeping in math class)
- [gameprogrammer] Re: Bouncing Ball (Sleeping in math class)
- From: Petri Latvala
- [gameprogrammer] [SDL, OpenGL and SDL_ttf] Need help
- From: Mister