# Arbitrary move

Hi,

i’d like to move in the direction
given by the mouse. Actually I have
my camera with is configured by its position
and angles (x,y,z). And I wanted to move in
the same direction as the camera, ie if I see
one object in front of mine I can get closer.

I tried to create a vector of the forward direction
(x=0, y=0, z=-1), then rotate according to the camera settings. But it doesnt work, the object I looked at goes away in a manner that I don’t understand.

can someone tell me how to do it correctly ?

For rotation matrices, the columns form the basis vectors for the space. So, for any rotation matrix, we can simply grab the columns, in order, for our X(right), Y(up), and Z(forward) vectors. Note that the named axis convention is the default, and an ordering of forward, left, up would do as well, depending on the orientation.

For the modelview matrix, however, things are a bit different, since the matrix is typically the inverse of that which orients the camera in the world. Given that for any rotation matrix, the inverse is equivalent to the transpose, we can extract the vectors from the rows instead (or the columns of the transpose).

If M is the current modelview matrix (with only the camera transform at the top of the stack), then we can extract the basis vectors as follows:

``````right   =  Vector(M, M, M );
up      =  Vector(M, M, M );
forward = -Vector(M, M, M);
``````

Again, the names are arbitrary, and depend entirely on your conventions to give them meaning. In my world, for instance, I have Z going up (instead of Y), and my order goes: X(forward), Y(left), Z(up).

ok, I will try it this evening.
Thanks you very much 