Solved

wm_timer

Posted on 1999-01-22
6
296 Views
Last Modified: 2010-04-02
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
0
Comment
Question by:at75
  • 4
6 Comments
 
LVL 22

Accepted Solution

by:
nietod earned 30 total points
ID: 1184881
SetTimer() starts the timer and KillTimer() destroys (stops) it.  In between that you will get periodic WM_TIMER notifications messages as long as you are running a "message pump".
0
 
LVL 22

Expert Comment

by:nietod
ID: 1184882
>>.let say when i want to rotate the object by 3 degree
>>  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.

0
 
LVL 22

Expert Comment

by:nietod
ID: 1184883
>>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?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Expert Comment

by:dvest
ID: 1184884


   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
0
 

Author Comment

by:at75
ID: 1184885
dvest : thanks.i tried using your method. It continues to rotate!!
any idea how to stop it???

Thanks.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1184886
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.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Visual c++ and text files 7 60
White board coding practice 3 78
C++ mouse_event mouse look 7 69
show out valin of json for debugging in visaul c++ 1 15
When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now