Results 1 to 6 of 6

Thread: moving the ball

  1. #1
    Junior Member Newbie
    Join Date
    Jan 2011
    Posts
    7

    moving the ball

    In lesson 26 (nehe) , i want to move the ball to cross 4 points in the floor, but i dont know. please help me. thank you very much!

  2. #2
    Member Contributor
    Join Date
    Sep 2010
    Posts
    74

    Re: moving the ball

    If you posted a link to the tutorial you are having trouble with, it would be easier to help you.

  3. #3
    Junior Member Newbie
    Join Date
    Jan 2011
    Posts
    7

    Re: moving the ball

    here is code :
    http://nehe.gamedev.net/data/lessons/vc/lesson26.zip
    i want to move the ball to another points ( as clip), i need sb help me.
    ex: When i press key 'z', the ball moving.
    from (1) position -> (2) ->(3) -> (4) (repeat)
    My code :


    void Drawball()
    {
    gltranslate(a,b,c);
    Drawobject();
    }
    void processkeyboard(){
    if(keys['Z'])
    {
    int k;
    for(k=0;k<3,k++)
    {
    a = a[k];
    b = b[k];
    c = c[k];
    DrawBall();
    }
    }
    But the ball only move to (2) position. and it's not like moving the ball. Please help me

  4. #4
    Senior Member Regular Contributor Rosario Leonardi's Avatar
    Join Date
    Aug 2008
    Location
    Italy
    Posts
    356

    Re: moving the ball

    If you want to create an animation you have to draw the sphere in different position in each frame.
    If you want to move an object from A to B in 10 seconds at frame 0 the object will be in the point A, in the frame 1 will be in the point A + deltaT/10 * (B-A)
    where deltaT is the time between a frame and another.
    So you will have a code like this
    Code :
    time = 0;
    init(){
      A = StartPosition
      B = EndPosition
    }
     
    draw()
    {
      time += deltaT;
      if(time < endAnimation)
         actualPosition = A + (time/endAnimation)*(B-A)
      else
        actualPosition = B;
      glTranslate(actualPosition);
      drawObject();
      glSwapBuffers()
    }
    To have a smooth animation you have to call the draw function at least 30 times for seconds.
    ~ ~ I tell you, realtime 3D is made of blood, sweat and screams! ~ ~

  5. #5
    Junior Member Newbie
    Join Date
    Jan 2011
    Posts
    7

    Re: moving the ball

    Thank you. But i understand a little your code.
    What's endAnimation ? "A = StartPosition" is : Gldouble A[3] = {a1,a2,a3 ) , isn't it?
    And I want the ball from A (start position) run to B, then run to C, then run to C..., not only from A to B.
    I'm a newbie, so i need heper of...

  6. #6
    Senior Member Regular Contributor Rosario Leonardi's Avatar
    Join Date
    Aug 2008
    Location
    Italy
    Posts
    356

    Re: moving the ball

    If you have point A, B, C, D;
    at init time set
    start = A
    end = B
    then then the animation is finished reset the timer and set
    start = B
    end = C
    and so on.

    I usually write meta code when the implementation is not important. When I write
    start = A
    is only a conceptual starting point A
    I don't care if this is a 3d point or 2d, or if it's a GLfloat or GLdouble or is you have a class representing points.
    "If you have point A, B, C, D;"
    I don't care is you have four variable or a vector, this is up to you.
    ~ ~ I tell you, realtime 3D is made of blood, sweat and screams! ~ ~

Similar Threads

  1. Replies: 6
    Last Post: 01-07-2013, 04:38 AM
  2. Need urgent help with moving ball
    By Tezelia in forum OpenGL: Basic Coding
    Replies: 10
    Last Post: 01-01-2013, 03:23 PM
  3. Moving a ball in a labyrinth
    By furetto3 in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 05-30-2011, 01:03 PM
  4. Calculating height for a ball moving down a hill
    By chronophile in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 04-26-2011, 11:02 AM
  5. Ball moving?
    By detzel in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 06-25-2001, 01:05 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean