Skip to main content
gamedev.net
🔒 Locked

cam control

Started by jreh Oct 16, 2005 at 2:46 PM 0 replies 500+ views
Original Post
jreh
jreh
The problem I am having is that when the mouse is being moved up and down at close to equal distances the view quickly ends up looking down. The same thing happens with left and right but in this case the view ends up on one side. the other problemis that I would like the movement in and out of the screen to happen in the direction of the view rather than a fixed axis as is happening now. int DrawGLScene(GLvoid) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); glRotatef(camRotx, 1.0f, 0, 0); glRotatef(camRoty, 0, 1.0f, 0); glRotatef(camRotz, 0, 0, 1.0f); glTranslatef(0, 0, camSpeedz); // skybox origin should be same as camera position sky1.Render(0, 0, 0); return TRUE; } . . . . . case WM_MOUSEMOVE: float prevMouseX, prevMouseY; prevMouseX = mouseX; prevMouseY = mouseY; mouseX = LOWORD(lParam); mouseY = HIWORD(lParam); if ((mouseX - prevMouseX) < 0) camRoty += 0.8f; if ((mouseX - prevMouseX) > 0) camRoty -= 0.8f; if ((mouseY - prevMouseY) < 0) camRotx += 0.8f; if ((mouseY - prevMouseY) > 0) camRotx -= 0.8f; break;
kburkhart84
kburkhart84
Two problems. You are rotating the 0.8 amount no matter how much the mouse moved. Not good. Especially if you have a higher frame rate. Instead, multiply the amount the mouse moved by a number, than tweak that number until you get it right. Also, you need to keep the x, y, z position in a variable somewhere. Each frame, if you are moving forward, you need to use sin and cos to calulate the real x,y,z coords again. It's just a little bit of trigonometry, but you need it for this. Or, you could use vector mathematics and calculate the forward vector and add it like that. But to get the forward vector, you need either the same trigonometry or get it from the OpenGL modelview matrix, which already did the sin and cos for you.


Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.