Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 5 of 5

Thread: Translation problem

  1. #1
    Junior Member Newbie
    Join Date
    Feb 2004
    Posts
    5

    Translation problem

    I'm in the process of developing a snooker game and I'm having trouble with the movement of the snooker balls. I've no problem tracking where there supposed to be going and when a collision occurs but I can't seem to figure out how to control the speed at which the balls move.

    For example i've got the start and finish vectors of the white ball but at the moment all that i'm doing is a simple translation from start vector to finish vector. How do I simulate a powerfull shot and a soft shot?

    Appreciate it if anyone can help me out.

  2. #2
    Senior Member OpenGL Guru Relic's Avatar
    Join Date
    Apr 2000
    Posts
    2,527

    Re: Translation problem

    Not really an advanced or OpenGL question.

    For a snooker simulation your objects need to have a velocity and a normalized direction vector, damping of the table cloth, spin, maybe torque parameters.

    The velocity and direction needs to be derived by rigid body collisions. Measure the time it takes to draw a frame and calculate the distance your ball travels in its direction in that time. Update the position for each frame. Simple as that.

    Search the internet for rigid body collision formulas.

  3. #3
    Senior Member OpenGL Pro
    Join Date
    Feb 2002
    Location
    Bonn, Germany
    Posts
    1,652

    Re: Translation problem

    Frame rate independent animation is what you're looking for.
    You need a direction vector, the current speed of the object and the time that has passed since the last frame.
    The first two can conveniently be combined into a velocity vector. The time you'll have to measure. QueryPerformanceCounter is one of the more obvious ways to measure time (on Windows systems) and is sufficiently accurate for animation purposes.

    Now, say your object has a current position P and a velocity vector V.
    Then you'd do
    Code :
    while (alive)
    {
       render();
       float dt=elapsed_time();
       P+=V*dt;
    }
    This is only basic movement. In practice, velocity should be a function of acceleration and, again, time.

  4. #4
    Advanced Member Frequent Contributor
    Join Date
    Oct 2000
    Location
    Belgium
    Posts
    857

    Re: Translation problem

    I'll transfer this to the math & algorithms forum, where this discussion is more appropriate.

    -- Tom

  5. #5
    Intern Contributor
    Join Date
    Sep 2003
    Location
    Jersey, Channel Islands
    Posts
    67

    Re: Translation problem

    How did you get your start and finish vectors, in the first place?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •