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 3 of 3

Thread: a question about continuously scale

  1. #1
    Junior Member Newbie
    Join Date
    Jan 2003
    Posts
    11

    a question about continuously scale

    I have a problem about how to continuously scale, for example, if I press 'c', it will continuously magnify then if I release 'c', it will stop the process.

    I tried a while loop in KeyPressed function but the while loop just repeat ignoring the key release. How to do it?

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

    Re: a question about continuously scale

    What are you using to get the input from the keyboard?
    I am guessing the problem is your code, post it here and can show you the error.

    but here is some sample code, is this what you are thinking:

    float scale;

    void main_loop(void)
    {
    key = read_keyboard()

    if( key == 'c' ) scale = scale - 0.01; // Reduce scale
    if( key == 'i' ) scale = scale + 0.01; // increase scale

    update_display()
    }

    void display(void)
    {

    glScale(scale, scale, scale);

    draw_object();
    }

    Originally posted by mapds:
    I have a problem about how to continuously scale, for example, if I press 'c', it will continuously magnify then if I release 'c', it will stop the process.

    I tried a while loop in KeyPressed function but the while loop just repeat ignoring the key release. How to do it?

  3. #3
    Member Regular Contributor
    Join Date
    Jul 2001
    Posts
    409

    Re: a question about continuously scale

    the problem with that code is that it does not give a smooth result.

    to achieve a smooth result you have to compute, every frame, the amount dt of time elapsed since the last frame. Then, you check whether the 'c' key is currently pressed. For this, either you use a cross-platform library like glfw, or you maintain an array of bools representing the keyboard, or you use a system-specific func like GetAsyncKeyState. Then you code the following:

    if (c is pressed)
    { scale_factor += (SCALE_SPEED * dt);
    }

    (or maybe you'll prefer an exponential formula like scale_factor *= (1 + SCALE_SPEED * dt); )



    [This message has been edited by Morglum (edited 01-11-2003).]

Posting Permissions

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