implementing box zoom

This is a discussion on implementing box zoom within the Game Programming forums, part of the General Programming Boards category; Hi, I am implementing the box zoom for my CFD Application.... for that i can able to capture the Rectangle ...

  1. #1
    Registered User
    Join Date
    Nov 2010
    Posts
    1

    implementing box zoom

    Hi,

    I am implementing the box zoom for my CFD Application....

    for that i can able to capture the Rectangle co-ordinates which is defining the are need to be zoom..

    but the problem is while doing the box zoom it is not exactly zoom the Rectangle,it shows nothing in the graphics screen..i.e it is not zooming the reqd area...

    here i am giving my code ...
    can anyone please correct me what i did wrong?...


    Code:
    void GraphicsViewMesh::mousePressEvent ( QMouseEvent * me )
    {
           	
            if(me->button()==Qt::LeftButton) {
          
    	onLButtonDown( ( me->buttons() | me->modifiers() ),me->pos() );
    
            }	
    
    }
    
    void GraphicsViewMesh::mouseMoveEvent ( QMouseEvent * me )
    {
    	
    	
    	
    		onMouseMove( me->buttons(), me->pos() );
    
    	
    }
    
    void GraphicsViewMesh::mouseReleaseEvent ( QMouseEvent * me )
    {
           
            if(me->button()==Qt::LeftButton) {
    
    	      onLButtonUp( me->buttons(), me->pos() );
    	}
    	
    	
    }
    
    
    void GraphicsViewMesh::onLButtonDown( const int/*Qt::MouseButtons*/ nFlags, const QPoint point )
    {
      //  save the current mouse coordinate in min
      	 myXmin = point.x();
      	myYmin = point.y();
      	myXmax = point.x();
      	myYmax = point.y();
    
    }
    
    void GraphicsViewMesh::onLButtonUp( Qt::MouseButtons nFlags, const QPoint point )
    {
       
                DrawRectangle( myXmin, myYmin, myXmax, myYmax, false );//,LongDash);
                myXmax = point.x();
                myYmax = point.y();        
    	    fitArea( myXmin, myYmin, myXmax, myYmax );
                myCurrentMode = CurAction_Nothing;    
               updateGL();        
                
    }
    
    void GraphicsViewMesh::onMouseMove( Qt::MouseButtons nFlags, const QPoint point )
    {
       
        	if ( nFlags & Qt::LeftButton )
    	{
    	        myXmax = point.x();
              	myYmax = point.y();	
    
    	        DrawRectangle( myXmin, myYmin, myXmax, myYmax, false );
    	        DrawRectangle( myXmin, myYmin, myXmax, myYmax, true );
    	}
    	     
       
    }
    
    
    void GraphicsViewMesh::DrawRectangle(const int MinX, const int MinY,
    			 const int MaxX, const int MaxY, const bool Draw)
    { 
      static double StoredMinX, StoredMaxX, StoredMinY, StoredMaxY;
      static bool m_IsVisible;
    
      StoredMinX = (MinX < MaxX) ? MinX: MaxX ;
      StoredMinY = (MinY < MaxY) ? MinY: MaxY ;
      StoredMaxX = (MinX > MaxX) ? MinX: MaxX ;
      StoredMaxY = (MinY > MaxY) ? MinY: MaxY ;
    
    
      QRect aRect;
      aRect.setRect( StoredMinX, StoredMinY, abs(StoredMaxX-StoredMinX), abs(StoredMaxY-StoredMinY));
    
      if ( !myRectBand ) 
      {
        myRectBand = new QRubberBand( QRubberBand::Rectangle, this );
        myRectBand->setStyle(new QWindowsStyle);
        myRectBand->setGeometry( aRect );
        myRectBand->show();
    
        QPalette palette;
        palette.setColor(myRectBand->foregroundRole(), Qt::white);
        myRectBand->setPalette(palette);
      }
    
      if ( m_IsVisible && !Draw ) // move or up  : erase at the old position
      {
        myRectBand->hide();
        delete myRectBand;
        myRectBand = 0;
        m_IsVisible = false;
      }
    
      if (Draw) // move : draw
      {
        //aRect.setRect( StoredMinX, StoredMinY, abs(StoredMaxX-StoredMinX), abs(StoredMaxY-StoredMinY));
        m_IsVisible = true;
        myRectBand->setGeometry( aRect );
      //  myRectBand->show();
      }
    }
    
    void GraphicsViewMesh::fitArea(double myXmin,double myXmax,double myYmin,double myYmax )
    {
    
    	double w,h;
    	w = (myXmax-myXmin);
    	h = (myYmax-myYmin);
    	glViewport(GLint(myXmin),GLint(myYmin),(GLsizei)w,(GLsizei)h);
        	glMatrixMode(GL_PROJECTION);
        	glLoadIdentity();
        	glOrtho(myXmin, myXmax, myYmax, myYmin, -1, -1);
        	glMatrixMode(GL_MODELVIEW);
        	updateGL();	    
    }
    while doing the box zoom... rubberband rectangle is visible... but the problem is ... it is not correctly zooming the captured rectangle...

    i think i had a mistake in glViewport() and glOrtho() in fitArea() function

    can anyone help me...?

    Thanks in Advance,
    Muthulingam
    Last edited by Salem; 12-01-2010 at 08:43 AM. Reason: Added [code][/code] tags - learn to use them yourself

  2. #2
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    1,623
    Do you see those smilies? That one reason why you must use code tags!

    I understand that you want to zoom in a specific area on the screen, right?
    Code:
    glViewport(0, 0, screenWidth-1, screenHeight-1);
    That's how you should use glViewport ( and code tags ).

    Edit: And change the last parameter passed to glOrtho to 1.
    Last edited by GReaper; 12-01-2010 at 08:33 AM.
    Devoted my life to programming...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Virtual Box
    By ssharish2005 in forum Tech Board
    Replies: 3
    Last Post: 02-12-2009, 04:08 AM
  2. Replies: 9
    Last Post: 02-13-2008, 01:59 PM
  3. How to program a "back" button with MFC
    By 99atlantic in forum Windows Programming
    Replies: 3
    Last Post: 04-26-2005, 08:34 PM
  4. New Theme
    By XSquared in forum A Brief History of Cprogramming.com
    Replies: 160
    Last Post: 04-01-2004, 07:00 PM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21