0

I wonder if someone could tell me how to make it possible to move a camera in a 3D space when the camera is rotated.

I am working on my own 3D engine (nothing fancy) and I can move the camera forward backward left right up down, thats all good. However when I rotate the camera, it doesnt move in the direction that the camera is directed to.

Here is a picture that should help you understand what I mean:

http://www.xaid.se/camrot.jpg

Does anybody know how to make this work?

(If you're interested in what I'm working on, visit this site)

tshepang
  • 12,111
  • 21
  • 91
  • 136
xaid
  • 740
  • 6
  • 18

1 Answers1

0

i'm not sure if i really get what you mean, but your problem looks like you want to move along the direction of the camera instead along one (main-)axis? therefore my solution would be to store a vector which keeps the direction the camera is looking, and update this vector everytime you rotate the camera. now you can use your direction vector for the forward movement. position + vector*stepsize. hope that helps a little bit.

Moe
  • 1,021
  • 1
  • 9
  • 16
  • "i'm not sure if i really get what you mean, but your problem looks like you want to move along the direction of the camera instead along one (main-)axis?" Exactly! I don't know how to do that vector-thingything. – xaid Mar 21 '11 at 23:36
  • I was wondering if there is a way to maybe tell the cam to balance the movement of the cam along the main world axes. Lets say the cam is rotated 45 degrees to the right, then it should move 50% to the left and 50% forward. I could maybe use Sinus and Cosinu to get the right results. Sounds pretty logical. I'll get back if it works. I'm trying to make it as simple as possible without all that fancy matrix stuff. – xaid Mar 21 '11 at 23:53
  • without the fancy matrix stuff i will be hard ;) i hope you know what a vector is. so imagine you have the position (x,y,z). and a vector which gives you the direction of the camera. for example at the begining the camera looking along the x-axis, then the direction vector would be(1,0,0). if we turn it it 45 degrees to the y axis it would be (1,1,0). to get the new position you only have to add the old position and the vector. – Moe Mar 22 '11 at 00:37
  • aaaaa yeah i now I understand. a vector is juat a record o variables. duuh, stupid me haha. but i dont understand how it would give me the right results just by adding the two vectors? im having a hard time visualizing it. anyways thanks. I'll try it out and see how it works. :) – xaid Mar 22 '11 at 16:30