AeroSujan
10-04-2011, 01:00 AM
Dear Friends
I am doing perspective projection for my 3D model. I have implemented PAN like this.
Please check this code if this is correct, when I am panning it's looking like rotating. Give me some idea how better I can do pan, zoom and rotate. Thanks a lot in advance :p
void CRevolutionProjView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
STATE = PAN;
oldP = point;
CView::OnLButtonDown(nFlags, point);
}
void CRevolutionProjView::OnMouseMove(UINT nFlags, CPoint point)
{
newP = point;
// TODO: Add your message handler code here and/or call default
int dx = oldP.x - newP.x;
int dy = newP.y - oldP.y;
switch(STATE)
{
case PAN:
{
trans[0] -= dx/10.0f;
trans[1] -= dy/10.0f;
Invalidate();
}
break;
case ZOOM:
{
trans[2] -= (dx+dy);
Invalidate();
}
break;
case ROTATE:
{
rot[0] += (dy * 180.0f) / 500.0f;
rot[1] -= (dx * 180.0f) / 500.0f;
#define clamp(x) x = x > 360.0f ? x-360.0f : x < -360.0f ? x+=360.0f : x
clamp(rot[0]);
clamp(rot[1]);
Invalidate();
}
break;
}
oldP = newP;
CView::OnMouseMove(nFlags, point);
}
I am doing perspective projection for my 3D model. I have implemented PAN like this.
Please check this code if this is correct, when I am panning it's looking like rotating. Give me some idea how better I can do pan, zoom and rotate. Thanks a lot in advance :p
void CRevolutionProjView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
STATE = PAN;
oldP = point;
CView::OnLButtonDown(nFlags, point);
}
void CRevolutionProjView::OnMouseMove(UINT nFlags, CPoint point)
{
newP = point;
// TODO: Add your message handler code here and/or call default
int dx = oldP.x - newP.x;
int dy = newP.y - oldP.y;
switch(STATE)
{
case PAN:
{
trans[0] -= dx/10.0f;
trans[1] -= dy/10.0f;
Invalidate();
}
break;
case ZOOM:
{
trans[2] -= (dx+dy);
Invalidate();
}
break;
case ROTATE:
{
rot[0] += (dy * 180.0f) / 500.0f;
rot[1] -= (dx * 180.0f) / 500.0f;
#define clamp(x) x = x > 360.0f ? x-360.0f : x < -360.0f ? x+=360.0f : x
clamp(rot[0]);
clamp(rot[1]);
Invalidate();
}
break;
}
oldP = newP;
CView::OnMouseMove(nFlags, point);
}