#### Archived

This topic is now archived and is closed to further replies.

# Fast angles?

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

## Recommended Posts

Got a simple problem. I am trying to do a bat''n''ball type of movement using 3d meshes - the ball bounces around and bounces off other objects. I am using simple bounding-box collision detection and then just bouncing the ball away when it hits something by reversing its movement vector. So, if it''s got a DY of -1 and it hits something, the DY becomes 1. This is great and find, but with strangely shaped meshes, the bounce is unrealistic. For example, if the ball hits a pyramid, it shouldn''t just bounce back, it should also bounce up into the air as well because of the slanted face. Is there a quick way to calculate which face and what angle the face is at? ''Doing the impossible is kind of fun'' - Walt Disney

##### Share on other sites
Since its for a ball, i wonder why dont you use bounding-sphere for its BV ?
And if turns out the bounding sphere hit another object, there''s so many way you can do collision detection, and the most expensive way is by checking face to face intersection. When you found the colliding face, then you can simply use the face normal to calculate collision response

##### Share on other sites
WOO HOO! Time to get out and dust off the ol' trig book! Seriously tho, every face has a normal. A perfectly elastic collision will come off at a vector with identical reverse incidence to that normal. Eeeerrrrr... that sounds like it is hard but imagine this:

my 2D world coords have 0deg at the +x and 270deg at the +y (draw a unit circle if ya need to )

if a ball comes in at 90deg it leaves at 270deg (your -y to +y example) if it his a square aligned to the axis.

move that square 45deg so now it's points are on the axis:
if a ball comes in at 90deg it leaves at 0deg (if it his the face on the +x axis)

the only difference in those 2 is the fact the face the ball hit has it's normal pointing 45deg to the right. you have to find the normal for each face you hit and caculate the trajectory from that

Now for the equations (in 2D)

angle of reflection = 2 * normal angle of surface - angle of the balls travel - 180 degrees

(yes i know this ain't the equation they show in physics books but i'm pretty sure it is the one i coded in .asm which means it is the fastest i found)

i.e. ball is traveing in the -y direction (90deg angle) hits the surface with a normal of 270deg (the x axis for instance)

angle of reflection = 2 * 270deg - 90deg - 180deg
angle of reflection = 2 * 270deg - 270deg
angle of reflection = 270deg (a.k.a. the y direction)

the 3D version is similar but all the vectors have 3 coords so you have to subtract the vector of incidence (the ball makes with the normal or the surface) from the normal vector to get the result vector for your ball.

I agree also that you should NOT use bounding square(cube) because you will run into problems of detecting a collision where it does not occur (imagine the edge corner of a sqare brushing by the corner of another sqare... if one of those squares was a circle there would be no collision)

Brett Lynnes
cheez_keeper@hotmail.com

Edited by - cheez_keeper on November 1, 2001 1:03:49 PM

##### Share on other sites
Thanks for the trig stuff... i think ;-)

''Doing the impossible is kind of fun'' - Walt Disney

1. 1
2. 2
3. 3
Rutin
16
4. 4
5. 5

• 10
• 14
• 30
• 13
• 11
• ### Forum Statistics

• Total Topics
631788
• Total Posts
3002356
×