Results 1 to 6 of 6

Thread: Keyboard Interaction

  1. #1

    Keyboard Interaction

    I have a set of flippers ( like in a pinball game ) im rotating them about the origin etc, i would like to have it so as long as i hold down a key for example the 'z' key the flipper will rotate up, and when i release it, it will rotate back down to where it originally was. But as far as i see you cant do this with the switch statement the is ussually used. Thank for your help!
    -=( DragonXTC )=-

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Jun 2000
    Location
    Gastonia, NC, USA
    Posts
    2,068

    Re: Keyboard Interaction

    Did you check out my other post to you?
    If you take a look at how I handle objects in that code, it would be easy to add the flipper function you asked about.

    Use the switch statment to set what is called a state varible.
    example:
    int flipper_state; state = 0 flipper down; state = 1 flipper up;
    int flipper_position; 0 = flipper at rest; 10 = flipper at full up position.
    int key_state; key not pressed = 0; key pressed = 1;

    1. When a flipper key is pressed the flipper position starts to move from 0 to 10.
    2. When the flipper position reach's ten, we set the flipper state to one.
    1. As long as a key is pressed the flipper stay's in state = 1
    2. After key is released, we start changing flipper_position from 10 to 0.
    3. When flipper position has reached zero, then we change flipper state to zero.

    Let me know if you understand it?

    Originally posted by DragonXTC:
    I have a set of flippers ( like in a pinball game ) im rotating them about the origin etc, i would like to have it so as long as i hold down a key for example the 'z' key the flipper will rotate up, and when i release it, it will rotate back down to where it originally was. But as far as i see you cant do this with the switch statement the is ussually used. Thank for your help!

  3. #3

    Re: Keyboard Interaction

    To nexsome:

    I understand most of what you say, but my question is, how do i tell what the key_state is ? a switch statement will take it one time correct? meaning it will rise up, set flipper_state to 1, then descend and set flipper_state to 0? do you have a while of some sorts checking the key_state? Thanx for your help
    -=( DragonXTC )=-

  4. #4
    Senior Member OpenGL Guru
    Join Date
    Jun 2000
    Location
    Gastonia, NC, USA
    Posts
    2,068

    Re: Keyboard Interaction

    That is a problem with GLUT is does not give you the keyboard state, other then a key was pressed. Getting the keyboard state has been asked on this forum before, I do not have the answer myself, but will check on getting the key press state up/down.

    The other option would be to use the mouse button's for your flippers, glut will get the state of button up/down.


    Originally posted by DragonXTC:
    To nexsome:

    I understand most of what you say, but my question is, how do i tell what the key_state is ? a switch statement will take it one time correct? meaning it will rise up, set flipper_state to 1, then descend and set flipper_state to 0? do you have a while of some sorts checking the key_state? Thanx for your help

  5. #5
    Senior Member OpenGL Pro
    Join Date
    Oct 2000
    Location
    Fargo, ND
    Posts
    1,753

    Re: Keyboard Interaction

    You could always store the states yourself...

    When the key is pressed...

    bKeyDown = true;

    When the key is released...

    bKeyDown = false;

    Your update method, or your rendering method, or wherever you need to see what the state of the key is, you just check that variable. Nice and simple. You'd have to have a separate variable for each key you need to track, though.
    Deiussum
    Software Engineer and OpenGL enthusiast

  6. #6
    Senior Member Regular Contributor
    Join Date
    Jul 2001
    Posts
    442

    Re: Keyboard Interaction

    If you are using windows, you can get the key-state with the win32 function, GetAsyncKeyState ( VK_UP ) <-- for example.

    Not sure about glut however or whether this function will be available with a console app (should be!). Be aware that the Async nature of this call will mean your application (if running in the background) will still detect and respond to keyboard messages. You can stop this by checking the current window HWND is = your window HWND (not sure even if you can get the hWnd from glut).

    Anyway, hope this helps.

Similar Threads

  1. Keyboard interaction opengl problems
    By moody in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 12-05-2011, 02:59 PM
  2. Interaction of 2 Shapes
    By Arunes in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 06-16-2009, 04:38 AM
  3. Mouse Interaction
    By melmiligui in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 11-28-2002, 02:28 AM
  4. scene interaction
    By in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 08-06-2002, 07:34 PM
  5. Keyboard: how can i read the buffer of the keyboard ?
    By Bahamut_france in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 03-02-2001, 08:13 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