PDA

View Full Version : Realtime bouncing, undepending on angles.



Dies_Irae
02-05-2002, 12:45 PM
Hi guys,

I have a small problem. But i cant figure it out.

What i want to create is a ball moving around a world, (Like just a room)

And i want it to bounce correct on all
surfaces.

I have the ball's possition and direction, and offcourse the Normal of the triangle the Ball collided with.

How can i invert/change the Ball's Direction? Is it possible to just muliply it with the plan normal?

Thanks.

Bob
02-06-2002, 12:46 AM
You have to calculate the reflection vector.



r = reflection vector
n = plane normal
v = velocity vector
* = scalar/vector multiplication
dot = dot product

r = 2 * n * (n dot v) - v

Dies_Irae
02-06-2002, 01:06 AM
Hey, thanks.

But what is Velocity?
Direction? Direction - possition?

Sorry http://www.opengl.org/discussion_boards/ubb/wink.gif

/ D

Bob
02-06-2002, 01:36 AM
The velocity vector is the direction in which the ball is moving. A more proper word could have been direction, instead of velocity vector.

Zak McKrakem
02-06-2002, 01:46 AM
_______________________________________________
GDAlgorithms-list mailing list
GDAlgorithms-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gdalgorithms-list

Dies_Irae
02-06-2002, 01:54 AM
Hi,

vNormal = [0, 1, 0] Floor
vDirection: [0, -1, -1] // Sphear is moving down/into the screen.

When hiting the floor, i use:

vReflection = vNormal * Dot(vNormal, vDirection) - vDirection;

Then the reflection should be [0, 1, -1] right?
But its [0, 0, 1] any idea why? :) What am i doing wrong?

/Thanks again.

Bob
02-06-2002, 02:00 AM
See my code again, you forgot to multiply by 2.

Also remember that I can't guarantee that formula is correct. I came up with it in a minute from a piece of paper and a pencil http://www.opengl.org/discussion_boards/ubb/biggrin.gif

Dies_Irae
02-06-2002, 02:05 AM
Hey,

Then the reflection just becomes [0, 0, 2]

Ill stop flooding you with dumb questions, and try to get my hand on some source code :)

Thanks man

Zak McKrakem
02-06-2002, 02:08 AM
Remember that this is an OpenGL advanced forum?
Yes?
Then, why are you asking non OpenGL questions?
There are many places for your questions, for example
https://lists.sourceforge.net/lists/listinfo/gdalgorithms-list

Please, don't fill this forum of offtopic noise.

Thanks.

Dies_Irae
02-06-2002, 02:32 AM
Ok, tx Ill take look,