Solved

zoom in/out

Posted on 1999-01-24
3
1,023 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

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…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

786 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