Solved

zoom in/out

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

  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 …
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

747 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

14 Experts available now in Live!

Get 1:1 Help Now