PDA

View Full Version : Freedom of movement



Quaver
12-01-2013, 08:10 AM
I am a little stuck with making freedom of movement with the mouse, what I want is to have the controls of a 3D model making program. I am using Windows.

Here is my viewport structure, pretty standard:


struct viewport {
float x;
float y;
float z;
float angle[2];
};
struct viewport viewport;


My gluLookAt call:


glLoadIdentity();
gluLookAt(viewport.x, viewport.y, viewport.z, viewport.x + sin(viewport.angle[0] * M_PI / 180.0f), viewport.y + viewport.angle[1] * M_PI / 180.0f, viewport.z - cos(viewport.angle[0] * M_PI / 180.0f), 0.0f, 1.0f, 0.0f);

My WM_MOVE, to rotate the scene when the user holds down the right mouse button:


case WM_MOUSEMOVE:
if(GetAsyncKeyState(VK_RBUTTON)) {
viewport.angle[0] -= (GET_X_LPARAM(lParam) - lastMouseX) / 16.0f;
viewport.angle[1] += (GET_Y_LPARAM(lParam) - lastMouseY) / 16.0f;
}
lastMouseX = GET_X_LPARAM(lParam);
lastMouseY = GET_Y_LPARAM(lParam);
return 0;

My WM_MOUSEWHEEL, to zoom in and out the scene:


case WM_MOUSEWHEEL:
if(GET_WHEEL_DELTA_WPARAM(wParam) > 0) {
viewport.x += sin(GET_WHEEL_DELTA_WPARAM(wParam) / 120.0f);
viewport.y -= cos(GET_WHEEL_DELTA_WPARAM(wParam) / 120.0f);
}
else {
viewport.x += sin(GET_WHEEL_DELTA_WPARAM(wParam) / 120.0f);
viewport.y -= cos(GET_WHEEL_DELTA_WPARAM(wParam) / 120.0f);
}
return 0;

The zoom code really doesn't work, and I think my code to rotate on the Y axis is wrong, it looks weird.

Any help is appreciated, thanks!