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?

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:
[b]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?[/b]

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