So I tried to get this to work, but so far no luck, hope you can help. The fact is that I have a camera in my project that the user can freely move with the mouse and buttons. Currently: move = new Vector3(0, 0, -1) * moveSpeed; move = new Vector3(0, 0, 1) * moveSpeed; ... move = new Vector3(0, 0, -1) * moveSpeed; move = new Vector3(0, 0, 1) * moveSpeed; ... move = new Vector3(0, 0, -1) * moveSpeed; move = new Vector3(0, 0, 1) * moveSpeed; ... And then I just add a move vector to the camera vector: cameraPos += move
Then the problem is that if I turn the camera and then try to move, for example, down, it will not move directly down, but at a certain angle. I assume this is due to movement along the local axis. But what I want to do is move along the world axis. Is something like this possible, or do I need to somehow calculate the angle, and then move to more than one axis?
Yours faithfully!
EDIT: I rotate the camera, where cameraPos is the current camera position and rotation is the current camera rotation. And this is the code to rotate the camera:
void Update() { ... if(pressed) { int newY = currentY - oldY; pitch -= rotSpeed * newY; } Rotate(); } void Rotate() { rotation = Matrix.CreateRotationX(pitch); Vector3 transformedReference = Vector3.Transform(cameraPos, rotation); Vector3 lookAt = cameraPos + transformedReference; view = Matrix.CreateLookAt(cameraPos, lookAt, Vector3.Up); oldY = currentY; }
Ihope is more readable.
source share