at75
asked on
wm_timer
i have some problem with the timer.
dun quite understand how it works???
when did i start the timer?how do i stop? quite confused!
let say when i want to rotate the object by 3 degree
everytime i pressed the arrow key...
how do i do it?
or is there other ways to do it?
like using a flag to indicate as shown in the code below:
void CDhView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
switch(nChar) {
case VK_LEFT:
z_angle -= 3.0f;
if (z_angle <=0.0f);
z_angle = 359.0f;
cameramode = ROTATE;
Invalidate();
break;
On_Draw()
if (cameramode == ROTATE)
{
glRotatef(z_angle, 0.0f, 1.0f, 0.0f);
cameramode == STOP;
}
so once i rotate the z_angle by 3 degree, then the object
should stop rotating until i press arrow key again.
but it keep on rotating...why??
thanks
dun quite understand how it works???
when did i start the timer?how do i stop? quite confused!
let say when i want to rotate the object by 3 degree
everytime i pressed the arrow key...
how do i do it?
or is there other ways to do it?
like using a flag to indicate as shown in the code below:
void CDhView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
switch(nChar) {
case VK_LEFT:
z_angle -= 3.0f;
if (z_angle <=0.0f);
z_angle = 359.0f;
cameramode = ROTATE;
Invalidate();
break;
On_Draw()
if (cameramode == ROTATE)
{
glRotatef(z_angle, 0.0f, 1.0f, 0.0f);
cameramode == STOP;
}
so once i rotate the z_angle by 3 degree, then the object
should stop rotating until i press arrow key again.
but it keep on rotating...why??
thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
>>so once i rotate the z_angle by 3 degree, then the object
>> should stop rotating until i press arrow key again.
>> but it keep on rotating...why??
Do you mean it continues to rotate more and more? it doesn't look like it should from the code. Do you mean it stays rotated? Like do you want it to appear unrotated again?
what does glRotatef() do?
>> should stop rotating until i press arrow key again.
>> but it keep on rotating...why??
Do you mean it continues to rotate more and more? it doesn't look like it should from the code. Do you mean it stays rotated? Like do you want it to appear unrotated again?
what does glRotatef() do?
void CDhView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
switch(nChar) {
case VK_LEFT:
if(nRepCnt != 0) // if this isn't the initial keypress
{return;}
z_angle -= 3.0f;
if (z_angle <=0.0f);
z_angle = 359.0f;
cameramode = ROTATE;
Invalidate();
break;
I didn't get to test this, but by the name of the variable I'd think it would start off at zero. If this
doesn't work, try using one.
David
ASKER
dvest : thanks.i tried using your method. It continues to rotate!!
any idea how to stop it???
Thanks.
any idea how to stop it???
Thanks.
That code is fine (as is what I suggested). It cannot make it continue to rotate. I think you must have other code somewhere that is the culprit. Look for other occurances of code that alters z_angle.
I still don't see where WM_TIMER comes into this. That sounds suspicious.
I still don't see where WM_TIMER comes into this. That sounds suspicious.
>> everytime i pressed the arrow key...
>> how do i do it?
That doesn't have anything to do with a timer. Handle the WM_KEYDOWN message to determine when the arrow key is pressed. Then adjust whatver variables you are using that records the current camera angle and then invalidate the window. Then return when the window is redrawn (shortly) it will be redrawn at the new angle.