hi all

I want to use vector in my billard game in order that i can deal with the speed and the direction of the balls so can anybody tell me about an example using vector or a website to find such a thing

thank you all for the great help you offer

plasmonster

04-13-2004, 12:45 PM

h333, there are a number of ways to do this, depending on how much control you need. But, for simplicty, lets call a pocket position P, and the ball B, and find a vector that puts the ball in the pocket. This vector, V, is V = P - B.

Then length of V is the distance to the cup. If you normalize V, that is, divide V by its length, you will have a direction vector, which is very usefull. Now, say you want to push the ball towards the cup. You could do this by scaling V by a small amount. This scale is the speed of the ball, and togehter with V, forms your velocity vector. That is, ballVelocity = ballSpeed * (V / lengthV). Now, I assume you are animating this process over several frames, so each frame add this velocity vector to your ball's position:

update( float dt ){

...

ball.position += ball.velocity * dt;

...

}

where dt is the time between consecutive frames. This scale with dt helps to smooth out animations, but can be omitted.

I hope this can get you started. If you would like the nuts and bolts on this subject, grab a physics book, and look for chapters on rigid body motion. When it comes to math and physics, nothing beats a hard copy; those magical tomes will last forever, unlike graphics documentation and technique, which changes every other tuesday.

Thank you very much RadicalHumility

all the information you offer are very useful

you helped me a lot thank you again

Powered by vBulletin® Version 4.2.3 Copyright © 2018 vBulletin Solutions, Inc. All rights reserved.