Ball Angles

Hi, i need to be able to calculate the angels somehow between moving balls on a snooker table in my java 2d game, how do i do this? also how can i send the ball off in the right direction, as a ball has a x and y velocity?

Hi,

at the moment I have no idea about the first part of your question. The second part is no problem. You should have the speed of your ball and an angel. Then it is only math:

The speed is the hypotenuse of a triangle.

x-direction = Math.cos(angel) * speed;
y-direction = Math.sin(angel) * speed;

Best regards.

Ralf

just wanted to make it clear i only get the angle when the 2 balls collide, so i need a formula or do i need to use rotation using point of collision on the balls?

i am very confused!

cheers

i know i need to rotate the collided balls at 45 degrees then send them off in that direction, but i need some way of finding out if the 2 balls collided are in a straight line shot, does anyone know about this?

[quote]i know i need to rotate the collided balls at 45 degrees then send them off in that direction, but i need some way of finding out if the 2 balls collided are in a straight line shot, does anyone know about this?
[/quote]
Use Odejava for Gods sake !! Theres no way you gonna figure it out anyway, it will never work realistically unless you are some sort of math wizard. Odejava can do these things for you and a thousand times better than you and I could ever hope for even if we from now on devoted our lives to it !

maybe he wants to get the mathmatical experience. Theres nothing wrong with that…

But yes, use ODE ;D

DP

What is ODE, and how could i import and use it in my Java 2D snooker game?

http://www.ode.org Thats the C++/C library.

http://www.odejava.org And thats the java binding.

Read up on those two, they are physics libraries…

DP

I’m no ODE guru, but with the basic knowlegde I have now I bet I could make a snooker game in less than a week. At first it looks hard but it’s worth the effort, maybe it will take you 1-2 month to get a grasp on,so what, at your current path you would still be trying to figure out angles and velocities when ball A hits ball B and it would STILL not look anything near right. With ODE you would get a pro, ultra reality like snooker game.
ODE is for 3D games mostly but it can easely be used from 2D. And hey, while you at it, why don’t you go 3D ? The combination of Java3d and ODE would give you a truly pro game. I used to have the same problems as you until I found ODE. After : to hell with all that, ODE fixes it for me.
I’m not going to spent next 5 years reading up on physics and math.

Daz,

I did all the math to calculate the new directions and speeds for Balls of any radius/mass, But the other day I found a easier algorithm for it.

Look it here: http://freespace.virgin.net/hugo.elias/models/m_snokr.htm

Hope it helps you!
    
    Rafael.-