Jump to content
  • Advertisement
Sign in to follow this  

Bouncing off an angle with advanced coordinate rotation

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Let's say we have an angled line and a ball that is going to hit it from above...when hit is performed we use this matrix rotation or advanced coordinate rotation:



var x2:Number = cos * x1 - sin * y1;
var y2:Number = cos * y1 + sin * x1;


so we rotate counterclockwise the line to make it straight, lets say the line is at point (100, 100), the width of the line is also 100, and its at 45 degrees, according that the bottom are positive degrees and the top are negative, so the rotation from 45 to 0 is counterclockwise, this works if the ball hits the line from the right side, but what if the line is at 160 degrees, and the ball hits the line at the left side, in this case we can't rotate the line counterclockwise, cause the ball will be rotated too by this formula and the ball coordinates will be under the line in the cartesian plane and that is technically wrong, we have to rotate the line clockwise...


if you don't understand what I'am talking about, please see this chapter of the book..http://flylib.com/books/en/ - here it shows how the bounce if handled, but it does not explain how to do the same when the ball is at the left side from the point of where the line goes...


thanks in advance

Edited by Kjelkor

Share this post

Link to post
Share on other sites

Yeah, just use a reflected vector..


I've made a GPU particle system with a depth+normal cubemap for collision, and just used

float 3 reflvec = reflect(direction, normal);

- works really great!

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!