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,068

    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
    Senior Member Regular Contributor
    Join Date
    Jul 2001
    Posts
    352

    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).]

Similar Threads

  1. changing position of an object continuously
    By david419 in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 10-21-2013, 06:53 AM
  2. A simple question on displaying an image in grey scale
    By jenny_wui in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 04-17-2013, 05:30 PM
  3. glutPassiveMotionFunc continuously fires
    By deadeye in forum OpenGL: General
    Replies: 0
    Last Post: 03-03-2011, 01:50 PM
  4. invoke key press function continuously
    By phoenix07p in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 07-01-2009, 07:36 AM
  5. And now a scale/coordinate question.
    By Spock in forum OpenGL: Basic Coding
    Replies: 11
    Last Post: 12-11-2008, 03:23 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