following my another question suppose that I have two public member data in my class used as modes:
bool WantToSetRectangle;
bool WantToDrawRectangle;
and also I have two public member data which are vectors with 4 members that are used to set a rectangle and draw a rectangle.
vector<int>ViewRectangle;
vector<int>RectangleToDraw;
and this is the implementation of the class's OnDraw
function runned after each navigation task like zooming,paning and etc.
void COpenGLControl::OnDraw(CDC *pDC)
{
// TODO: Camera controls
wglMakeCurrent(hdc,hrc);
glLoadIdentity();
gluLookAt(0,0,1,0,0,0,0,1,0);
glTranslatef(m_fPosX, m_fPosY, 0.0f);
glScalef(m_fZoom,m_fZoom,1.0);
if (WantToSetRectangle)
setViewRectangle();
if (WantToDrawRectangle)
DrawRectangleOnTopOfTexture();
wglMakeCurrent(NULL, NULL);
}
Now I create two instances of the class COpenGLControl
in my CDialogEx
:
COpenGLControl m_oglWindow1;
COpenGLControl m_oglWindow2;
as you see in the first picture in my another question the m_oglWindow1
is the bigger window and m_oglWindow2
is the smaller one. I set the modes of two windows as follows:(these modes are set false
in the constructor)
m_oglWindow1.WantToSetRectangle = true;
m_oglWindow2.WantToDrawRectangle = true;
each time the onDraw
function of the m_oglWindow1
is called the ViewRectangle
is set. these data should be dynamically passed to the RectangleToDraw
of m_oglWindow2
and immediately after that the OnDraw
function of m-oglWindow2
should be called to draw the extent rectangle on the smaller window that is always in the Full Extent
mode.
Remember that for tasks like Fixed Zoom in
, I can easily write this in the button click handlers of my CDialogEx
:
void CMyOpenGLTestDlg::OnBnClickedButton4()
{
// TODO: Add your control notification handler code here
m_oglWindow1.FixedZoomOut();
m_oglWindow2.RectangleToDraw = m_oglWindow1.ViewRectangle;
m_oglWindow2.OnDraw(NULL);
}
but in other tasks like pan
,zoom in to the point
and zoom out of the point
that are implemented using mouse-event handlers
of the class COpenGLControl
, I need some kind of rea-time data exchange between two instances of the class:
void COpenGLControl::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if (WantToPan)
{
if (m_fLastX < 0.0f && m_fLastY < 0.0f)
{
m_fLastX = (float)point.x;
m_fLastY = (float)point.y;
}
int diffX = (int)(point.x - m_fLastX);
int diffY = (int)(point.y - m_fLastY);
m_fLastX = (float)point.x;
m_fLastY = (float)point.y;
if (nFlags & MK_MBUTTON)
{
m_fPosX += (float)0.2f*m_fZoomInverse*diffX;
m_fPosY -= (float)0.2f*m_fZoomInverse*diffY;
}
OnDraw(NULL);
}
CWnd::OnMouseMove(nFlags, point);
}
void COpenGLControl::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if (WantToUseZoomTool)
{
if (nFlags & MK_LBUTTON)
{
m_fZoom = 1.05f*m_fZoom;
m_fZoomInverse = 1/m_fZoom;
int diffX = (int)(point.x - oglWindowWidth/2);
int diffY = (int)(point.y - oglWindowHeight/2);
m_fPosX -= (float)diffX;
m_fPosY += (float)diffY;
}
OnDraw(NULL);
}
CWnd::OnLButtonDown(nFlags, point);
}
void COpenGLControl::OnRButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if (WantToUseZoomTool)
{
if (nFlags & MK_RBUTTON)
{
m_fZoom = 0.95f*m_fZoom;
m_fZoomInverse = 1/m_fZoom;
int diffX = (int)(point.x - oglWindowWidth/2);
int diffY = (int)(point.y - oglWindowHeight/2);
m_fPosX -= (float)diffX;
m_fPosY += (float)diffY;
}
OnDraw(NULL);
}
CWnd::OnRButtonDown(nFlags, point);
}