Jump to content


How to achieve smooth movement from keyboard???


3 replies to this topic

#1 koalacui

    New Member

  • Members
  • Pip
  • 2 posts

Posted 18 September 2005 - 09:58 AM

Hi, guys, i am totally newbie in OpenGL, now I am studying on movement in OpenGL, and I can control a square's movement, but it seems cannot do a smooth movement such as diagonal movement when i press UP and LEFT, it cannot keep moving towards diagonal direction, I dont know how, can anyboday explain in details to me?? thanks a lot and best regards!!!

#2 roel

    Senior Member

  • Members
  • PipPipPipPip
  • 698 posts

Posted 18 September 2005 - 10:32 AM

http://www.gamedev.n...topic_id=345960

the problem (i guess) is that you use a switch and break after your cases. in the code you posted at gamedev, you check for up, and break out of it while not checking other cases, so if you press both up and left you don't move diagonal but only in the up direction. like people said on gamedev, use ifs and check all combinations.

#3 bladder

    DevMaster Staff

  • Members
  • PipPipPipPip
  • 1057 posts

Posted 19 September 2005 - 02:47 AM

You don't have to check all combinations. You just check for the 4 basics without using any elses or a switch/case.

if( key == GLUT_KEY_UP )
    b += 5.5f;
if( key == GLUT_KEY_DOWN )
    b -= 5.5f;
if( key == GLUT_KEY_LEFT  )
    a -= 5.5f;
if( key == GLUT_KEY_RIGHT )
    a += 5.5f;


#4 roel

    Senior Member

  • Members
  • PipPipPipPip
  • 698 posts

Posted 19 September 2005 - 02:31 PM

that's what i meant with all combinations, in stead of stopping checking after the first 'hit', checking all other possibilities that are left





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users