PDA

View Full Version : rotate, zoom and panning in ogl steps



ahuarte
02-11-2002, 09:31 PM
I am writing a single terrain viewer. I need control rotating, zooming and panning by using 3 buttom mouse. I need that the movement of the camera must be very accurate.

To solve this, when te mouse is clicked I save the current position of the mouse in CWnd coordinates. Then, at the MouseMove event, I must move/rotate the camera position but I want do it in ogl values.

I use "gluLookAt()" for set the camera state, and I set the world state with "gluPerspective" funtion.


By Example...

class CMyWnd : public CWnd
{
...
private:
// Last position of Mouse.
CPoint m_pntPrevPos;
// Mouse Operation.
int m_shrPrevOperation;
}

void MyWnd::OnLButtonDown(UINT nFlags, CPoint point)
{
m_pntPrevPos = point;
m_shrPrevOperation = 1;
CWnd::OnLButtonDown(nFlags, point);
}
void MyWnd::OnMButtonDown(UINT nFlags, CPoint point)
{
m_pntPrevPos = point;
m_shrPrevOperation = 2;
CWnd::OnLButtonDown(nFlags, point);
}
void MyWnd::OnRButtonDown(UINT nFlags, CPoint point)
{
m_pntPrevPos = point;
m_shrPrevOperation = 3;
CWnd::OnLButtonDown(nFlags, point);
}

void MyWnd::OnMouseMove(UINT nFlags, CPoint point)
{
switch (m_shrPrevOperation)
{
case 1: // ZOOM.
// ### move camera in ogl steps -> (point - m_pntPrevPos);
break;
case 2: // PANNING.
// ### pan camera in ogl steps -> (point - m_pntPrevPos);
break;
case 3: // ROTATE.
// ### rotate camera, or world ?, in ogl steps -> (point - m_pntPrevPos);
break;
}

// Save prev position and PAINT.
if (m_shrPrevOperation)
{
m_pntPrevPos = point;
InvalidateRect(NULL, FALSE);
}

CWnd::OnMouseMove(nFlags, point);
}

void MyWnd::OnPaint()
{
/*
glClear();
glLoadIndentity();
...
gluPerspective();
...
gluLookAt();
...

Paint OGL ELEMS...
*/
}


very thanks in avance