Bouncing off an angle with advanced coordinate rotation

Started by
1 comment, last by vinterberg 8 years, 8 months ago

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/4.261.1.71/1/ - 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

Advertisement

Why aren’t you using vectors to perform this operation? It’s literally a single line of code and is stable.

http://math.stackexchange.com/questions/13261/how-to-get-a-reflection-vector

L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

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!

.:vinterberg:.

This topic is closed to new replies.

Advertisement