Solved

zoom in/out

Posted on 1999-01-24
3
1,026 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
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 be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

728 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