rotate, zoom and panning

Hi, I am new.

I am developing a CView MFC class and I need control rotating, zooming and panning by using 3 buttom mouse. I need that the movement of the camera must be very accurate.

any suggestion ??

sorry my english !
Thank you a lot

Use ether the GLUT mouse function or windows mouse function to get mouse button state.

Then used the mouse movement plus mouse button state to ether rotate, zoom or pan your scene.
The how accurate the program is depends on how you code it. Can you explain what you mean by accurate camera movement?
What type of program are you writing?

But the commands you will use are glRotate, glScale, glTranslate, or gluLookat.

Originally posted by ahuarte:
[b]Hi, I am new.

I am developing a CView MFC class and I need control rotating, zooming and panning by using 3 buttom mouse. I need that the movement of the camera must be very accurate.

any suggestion ??

sorry my english !
Thank you a lot[/b]

I am writing a single terrain viewer.

I use LookAt() for set the camera state.

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:

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();

glPerspective();
glLookAt();

Paint OGL ELEMS…
*/
}

very thanks in avance

Here is my suggestion.

You first take the button down to get the current mouse coordinate. Then use the dirrence between the current and the button down coordinates.

example:
worldview.x += right_mouse_down.x - mouse_current.x;
worldview.y += right_mouse_down.y - mouse_current.y;

worldview holds the openGL movement value, you may want to use a temp varible so the only on the mouse release does the change become permanent. Also if you need to scale the value of the movement it can be done here also.

Originally posted by ahuarte:
[b]I am writing a single terrain viewer.

I use LookAt() for set the camera state.

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:

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();

glPerspective();
glLookAt();

Paint OGL ELEMS…
*/
}

very thanks in avance[/b]

But “worldview” CPoint holds movement in CWnd values, no?

How translate this movement to ogl values for move the camera whith “glLookAt”.
I do not kwnow if I must use “glUnProject” funtion.

I am lost!!!
thanks

Originally posted by nexusone:
[b]Here is my suggestion.

You first take the button down to get the current mouse coordinate. Then use the dirrence between the current and the button down coordinates.

example:
worldview.x += right_mouse_down.x - mouse_current.x;
worldview.y += right_mouse_down.y - mouse_current.y;

worldview holds the openGL movement value, you may want to use a temp varible so the only on the mouse release does the change become permanent. Also if you need to scale the value of the movement it can be done here also.

[/b]