Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

zoom in/out

Posted on 1999-01-24
3
Medium Priority
?
1,029 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 20 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
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 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.
Suggested Courses

610 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