Solved

zoom in/out

Posted on 1999-01-24
3
1,020 Views
Last Modified: 2012-05-04
i'm doing somehting on openGL.
i try to zoom in and out my object(let say a cube).
when i press the "+" key ,the object is suppose to scale up 0.1
then the zoom up object will be display.
when i press the "-" key ,the object is suppose to scale down by -0.1.
However, when i press the "+" key ,then the "-" key,i will need to key in "-" twice to see the scale down effect.this applies also when i key in "-" then "+".
why is it so?
my code:
void CDhView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
switch(nChar) {
      case VK_ADD:
            if (scale <= 5.0f)
             scale+=0.1f;
            cameramode = PLUS;      
            break;
       case VK_SUBTRACT:
            if (scale > 0.0f)
               scale-=0.1f;
               cameramode = SUBTRACT;
               break;
            }
void CDhView::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags)
{
switch(nChar) {
case VK_ADD :
      cameramode = STOP;                        
      break;
case VK_SUBTRACT:
      cameramode = STOP;
      break;
}
}                        
void CDhView::OnDraw(CDC* pDC)
      //Zooming
      if (cameramode == PLUS)
            glScalef(scale,scale,scale);

      if (cameramode == SUBTRACT )
            glScalef(scale,scale,scale);

thanks.      
0
Comment
Question by:at75
  • 2
3 Comments
 
LVL 4

Accepted Solution

by:
pellep earned 10 total points
ID: 1185038
try adding this to the ::OnKeyUp(...) function.


case VK_SUBRACT
if (nRepCnt!=1) //key only pressed once.
   cameramode=STOP
break


0
 

Author Comment

by:at75
ID: 1185039
pellep:thanks.i tried your method but it didn't work.same problem.any other ideas?
thanks
0
 
LVL 4

Expert Comment

by:pellep
ID: 1185040
where have you put the CDhView.Refresh() (or other grapics updating)
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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

930 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

12 Experts available now in Live!

Get 1:1 Help Now