Camera transformation enquiry

Started by
8 comments, last by haegarr 9 years ago

Hi All,

An easy one I hope.

If one wants a model to move sideways from the direction the model is facing what is the matrix transformation used to achieve this? I am storing a models position in world space as a euler angle for the orientation and a vector for the position. If I want the model to move sideways then I guess I need to calculate a vector that is perpendicular to the eular angle heading in orientation and has a magnitude of the amount I would like the model to move?

I am having trouble figuring out how to do this though...

Many thanks in advance,

Xavi

Advertisement

The first step in doing this is to stop using Euler angles. If you compute a regular world transform matrix, i.e one that relates the model to a position and orientation in the world, then one of the x, y, or z vectors of the world transform matrix denotes the "sideways" direction in world co-ordinates (which vector exactly depends on the model's initial facing direction). So fetch that vector, scale it to the movement distance, and make a translation transform matrix from it. Since it is a translation in world space, you have to apply it on the non-local side of the transform matrix so far.

Hi Haegarr,

Thanks for your reply.

I am using a world transformation row matrix (m) which I am generating using the euler angle and the location vector. m11 to m33 define the rotation to world space (which i calculate the components from the euler angle). m41 to m43 holds the location vector components. SO my matrix rotates and transformsfrom local to world space.

So my model is originally 'facing forward' toward z+ in its local space. Are you suggesting that by subtracting from x or m41 in the transformation matrix the model will move 'sideways to the left' of its forward facing direction in world space? Surely this would just rotate the model and move it in absolute terms across the x axis in world space?

I think what he is saying is to extract 3 side ways vectors from the current matrix, being
dx = { M11, M12, M13 }
dy = { M21, M22, M23 }
dz = { M31, M32, M33 }
Then you need to pick one or a combination of these. Think of it as the local coordinate space with xyz axis equals to these, represented in the global coordinate system.
When you have the translation vector, add it to your {M41, M42, M43}. In your case, if sideways can be represented by dx alone, that is simpler.

Hello Yuri,

Thanks for that.

In the end I solved it by making a translation vector in local space, rotating it into the world space then added it to the models location vector.

For example to move left when the model is facing forward (toward z+ in a left handed coordinate system) in its own space I make a vector such as v = {-5, 0, 0} then rotate the vector into the world space using a rotation matrix I generate from the models euler angles, then add v to the models location vector. Seems to work work well.

EDIT: THIS DIDN'T WORK :-)

Hi Yuri,

What do you mean by:

When you have the translation vector, add it to your {M41, M42, M43}. In your case, if sideways can be represented by dx alone, that is simpler.

Forgive me for being slow. How do I scale dx before adding it to the translation portion m41, m42, m43?

i may be wrong but world matrix should contain rotation and translation ans scale so if the scale says untouched you can just get the right up front vectors from the matrix and then just multiple it by the distance

Rotation and translation :)

This looks to be a great visual guide: http://www.codinglabs.net/article_world_view_projection_matrix.aspx

Too many projects; too much time

OK so i think I have implemented the above, as recommended:

1. Create a camera translation vector which describes the trajectory I want to the camera to move e.g. v={-5, 0, 0} to move left.

2. Multiply the vector by the inverse of the camera rotation matrix.

3. Add the vector to the translation portion of my camera translation matrix: t = {41, 42, 43}.

On first glance this appears to work well. However weirdness ensues on closer inspection. Specifically:

1. I have noticed that depending on the location the camera is in world space - the amount the camera moves varies. From moving quite slowly to moving very quickly. While the amount of 'movement' in the camera translation vector is always the same. Seems to move slower the further from the world coordinates origin the camera is.

2. In some camera orientations the input movement is reversed along the opposite direction down the axis. So left becomes right, backwards becomes forwards. This seems to occur over a small arc of the cameras full range of rotation.

Any thoughts.....


1. Create a camera translation vector which describes the trajectory I want to the camera to move e.g. v={-5, 0, 0} to move left.
2. Multiply the vector by the inverse of the camera rotation matrix.
3. Add the vector to the translation portion of my camera translation matrix: t = {41, 42, 43}.

Thing with problems like this is to make self clear in what space which transform should be done. The sideways translation that is desired is given in object local space, e.g. (-5, 0, 0). The position which should be altered by the translation is given in world space. So the object local translation is to be transformed into a world translation in order to be appended to the world position.

There are 3 Euler angles that describe the object's orientation in world space. It is hence a local-to-world transform. We assume here that this transform is applied on the unscaled and unrotated object to yield in an re-oriented object, and that the translation to the world position is applied on the re-orientated object.

Hence the way of solving the problem is this:

1.) Compute the rotation matrix R from the 3 Euler angles.

2.) Apply R to the local space translation vector t, yielding in the world space translation vector t'. (Notice that here is no inversion.)

3.) Add the resulting translation vector t' onto the world position vector p to yield in the new world position.

4.) Apply the overall transform, if needed, by 1st rotating the object by R and then translating it by p.


1. I have noticed that depending on the location the camera is in world space - the amount the camera moves varies. From moving quite slowly to moving very quickly. While the amount of 'movement' in the camera translation vector is always the same. Seems to move slower the further from the world coordinates origin the camera is.

Investigate the translation vector before (t) and after (t') the transformation by R. Both vectors must have the same length (in the limits of numerical precision). If not, then the transform does more then just rotate the space. Perhaps you already have a transform combined with non-rotational parts, or you have the conversion of the 3 Euler angles into a matrix wrong, or you accumulate rotation matrices without constraining the resulting matrix.

This topic is closed to new replies.

Advertisement