void CGraphicsCamera::ZoomToRectangle( CRect r )
{
	int w1 = r.Width();
	int h1 = r.Height();
	int w2 = GetViewportRect().Width();
	int h2 = GetViewportRect().Height();

	double widthZoomInc = (double)w1/(double)w2;
	double heightZoomInc = (double)h1/(double)h2;
	double zoomInc = max( widthZoomInc, heightZoomInc );
	Zoom( 1-zoomInc, r.CenterPoint() );

}
예제 #2
0
void CViewport::Render()
{
	CGraphicsContext	*graphics=mProgram->CheckGraphicsMode();

	if (graphics->GetType()==CGraphicsContext::kBlastGraphicsContext)
	{
		CCanvas				*fromCanvas=graphics->mCanvasManager.GetCanvas(mCanvas);
		
		if ((mUpdateAll) || (((CBLCanvas*)fromCanvas)->GetDrawBuffer()->GetUsedBlitRects()))
		{
			CCanvas			*toCanvas=graphics->mCanvasManager.GetCanvas(0);

			toCanvas->Copy(fromCanvas,GetViewportRect(),mBounds.left,mBounds.top);
			
			((CBLCanvas*)fromCanvas)->GetDrawBuffer()->ClearBlitList();
			mUpdateAll=false;
		}
	}
	else
	{
		CGraphicsContextGL	*glGraphics=(CGraphicsContextGL*)graphics;
		CGLCanvas			*fromCanvas=(CGLCanvas*)graphics->mCanvasManager.GetCanvas(mCanvas);
		
		float				screenWidth=glGraphics->GetWidth()/2.0f;
		float				screenHeight=glGraphics->GetHeight()/2.0f;
	
		float				across=(mBounds.left/screenWidth)-1.0f;
		float				down=-((mBounds.bottom/screenHeight)-1.0f);
		
		glPixelStorei(GL_UNPACK_ROW_LENGTH,fromCanvas->GetWidth());
		glPixelStorei(GL_UNPACK_SKIP_ROWS,fromCanvas->GetHeight()-GetHeight()-GetYOffset());
		glPixelStorei(GL_UNPACK_SKIP_PIXELS,GetXOffset());
		
		glRasterPos2f(across,down);
		glDrawPixels(GetWidth(),GetHeight(),GL_RGB,GL_UNSIGNED_BYTE,fromCanvas->GetPixels());
		glRasterPos2f(0,0);
		
		glPixelStorei(GL_UNPACK_SKIP_PIXELS,0);
		glPixelStorei(GL_UNPACK_SKIP_ROWS,0);
		glPixelStorei(GL_UNPACK_ROW_LENGTH,0);
	
		RenderSprites();
	}
}