relection in 2d
Ok, say I''m making a breakout style game, and I want to reflect the ball off of the wall. I know how to find the perpindicular vector, but how do I get a reflection vector based on the angle the ball hit? I had an equation in my book "computer graphics using opengl", but the page fell out and I can''t find it. Anyone know the equation?
I don''t remember the exact equation, but it seems to me in this case where everything is axis aligned, you could simply negate the component of the velocity that corresponds to the normal of the plane.
For bouncing off a verticle wall, you would just say Ball.Vel.x=-Ball.Vel.x
For a horizontal wall, it would be Ball.Vel.y=-Ball.Vel.y
For a horizontal wall, it would be Ball.Vel.y=-Ball.Vel.y
L - incident vector, pointing away from the surface
R - reflected vector, pointing away from the surface
N - surface normal vector, unit length.
R = 2*N*(N.L) - L
Negate L if you have it pointing towards the surface and want R pointing away - i.e. before/after collision velocities.
Note that this assumes a perfectly elastic collision with an immovable object.
[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]
[edited by - Fruny on January 4, 2003 11:08:51 PM]
R - reflected vector, pointing away from the surface
N - surface normal vector, unit length.
R = 2*N*(N.L) - L
Negate L if you have it pointing towards the surface and want R pointing away - i.e. before/after collision velocities.
Note that this assumes a perfectly elastic collision with an immovable object.
[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]
[edited by - Fruny on January 4, 2003 11:08:51 PM]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement