problem with affine transformation

Started by
18 comments, last by staticVoid2 16 years, 2 months ago
I fully understand the rotational transformations, I never knew you had to use a translation matrix though.
Advertisement
It's not about understanding individual transformations, it's about the whole general concept of transformations.
Brother Bob gives you a good advice.

The order depends on the convention. DirectX works with row major matrices.

The final transformations is computed like this:
M = S0.R0.T0.S1.R1.T1. ... . Sn.Rn.Tn

So if you first rotate (and supposing an initial identity matrix) you have:
( -1 0 0 0 )
| 0 -1 0 0 |
| 0 0 1 0 |
( 0 0 0 1 )

Then applaying the translation (2, 2, 2):
( -1 0 0 0 )
| 0 -1 0 0 |
| 0 0 1 0 |
( -2 -2 2 1 )

You first turn the camera local frame 180º and then translate your camera origin (2, 2, 2) over the world frame canonical base:
e1 = (1, 0, 0)
e2 = (0, 1, 0)
e2 = (0, 0, 1)

That matrix transform from camera view space to world space.
The camera local frame basis in world space coordinates is the upper 3x3 matrix, the basis vectors are normally referred as right, up and look (note your camera frame is now facing down; second row)

If you want to move your camera 3 units in a straigh line you need to translate relative to his own look vector (in that case the same direction world z axis is pointing (0 0 1)), thats 3*(0 0 1) = (0 0 3) = Tvec so applaying that translation you get: M = M . T

( -1 0 0 0 ) ( 1 0 0 0 )
| 0 -1 0 0 | | 0 1 0 0 |
| 0 0 1 0 | | 0 0 1 0 | =
( -2 -2 2 1 ) ( 0 0 3 1 )

( -1 0 0 0 )
| 0 -1 0 0 |
| 0 0 1 0 |
( -2 -2 5 1 )

and so on...
but say i was to first apply the transition and then the rotation, why is the transition vector different when it represents the vector displacement - say, to simplify things, i never rotated at all and i applied the translation (300, 300, 300) so the matrix looked like:
[   1,   0,   0, 0 ][   0,   1,   0, 0 ][   0,   0,   1, 0 ][ 300, 300, 300, 1 ]


then I multiplied the vector (100, 100, 100, 1) by this so i get (400, 400, 400, 1) - how is that the translated vector when it should be(-200, -200, -200, 1)??? would i not just be better off storing a 3x3 matrix for rotations and the cameras location so that i can multiply the vector by the 3x3 matrix then just subtract the camera location from it??
To be honest, I have no clue what your problem is here. You have a vector, and two transformations; a translation and a rotation. You can apply the transformations in two different orders.

  • Rotation, then translation: After 180 degree rotation about the Z-axis, the point (100, 100, 100) is at (-100, -100, 100). Then you translate it by 300 along all axes, so the final point is (200, 200, 400)

  • Translation, then rotation: After translation by 300 along all axes, the point (100, 100, 100) is at (400, 400, 400). Then you rotate it by 180 degrees about the Z-axis, so the final point is (-400, -400, 400).


Those are the two cases you can get by one translation and one rotation. Which one you get depends on how you multiply your matrices. Which one you want depends on how you want to interact with your camera class.
I thought the translation vector was used to represent the camera location?
Quote:Original post by staticVoid2
I thought the translation vector was used to represent the camera location?
Let's try a slightly different approach...

I think we can agree that you want your camera to have an orientation, and you want it to have a position.

There are any number of ways you can represent this data. Examples include:

1. A 4x4 matrix
2. A 3x3 matrix and a vector
3. A quaternion and a vector
4. An Euler-angle triple and a vector
5. A spherical coordinate pair and a vector

The process of updating the orientation and position, and of combining them into a final 4x4 matrix (if necessary) will differ for each of these representations. Furthermore, which representation will work best depends on what kind of motion you want (FPS, 6DOF, 3rd-person 'chase' cam, etc.).

Can you describe what kind of camera behavior you're after?

Once you've settled on a type of motion and a representation for your camera, post back here and we can probably make some more specific suggestions about how to go about coding it.

As for the problems you've been describing, like the other posters, I'm not quite clear on where the confusion is. Just remember that when you concatenate geometrical transforms in matrix form, the transforms are applied in sequence, either from left to right or right to left, depending on convention (sounds like in your case it would be left to right). A particular set of transforms will (or at least may) have different effects depending on the order in which they're applied (as has been demonstrated already).
the camera was just to have basic functions for now.. like converting a vector into the camera's coordinate system, rotating the camera around all three axis and setting the camera's location in world space which seems to be the problem.I thought the translation vector in the 4x4 matrix represented the cameras location in world space? but I think it represents the camera's location in it's own local object space. The camera class seems to be working with the second method you stated - a 3x3 matrix and a vector representing the cameras location(world space), all I do is translate the vector by subtracting the camera location vector and then multiply this by the 3x3 matrix. I thought this is how the 4x4 matrix worked, all in one operation, but im getting different results when I use it.
No. A matrix encodes a series of transformation operations, mainly scaling, rotation, and translation - sometimes reflection, shear, and other transformations are included.

Think of it this way. You have a camera 'object'. If it isn't parented to anything, before you apply any transformations, it should be assumed that the camera origin is the same as the world system's origin (0,0,0), that lack of rotation (0d,0d,0d), say, has the lens face down the +Z axis (or whichever you decide), and that is has no scaling (1,1,1). The matrix that retains this untransformed camera is an identity matrix:

1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1

Okay. Now you want to have it moved and rotated (but not necessarily in that order). First, the basic order of a singular set of transformations (left to right) is Scales*Rotations*Translations (S*R*T). This isn't strict but is a good guide. Note that scaling and rotation occur while the camera is still at the world system's origin - where the camera origin is (0,0,0). In other words, at some point the camera must have a coordinate system and before any transformations it is usually coincident with the world system. If parented to another object, then the parent's coordinate system would be the initial one as reference. Either way, one normally wants to scale and rotate an object about its own center. This is exactly why scaling and rotation happen BEFORE translation. Translation moves the object with respect to ITS referential coordinate system. If you move the object and then rotate it, it is still being rotated from the origin - of the coordinate system, not the object's center.

As already mentioned several times, the translation vector in a matrix is not the same as its position. You really shouldn't be applying a transformation matrix as a rotation-scale matrix and a position vector. Concatenate your transform operations in order and multiply the camera object's points or vectors by the resulting matrix.
I've tried implementing this but it's giving me weird results, i'm tempted to just stick with subtracting the camera location and then rotating the vertices, but i know this way is faster, how would i move the camera in world space? I've tried just setting the components in the translation vector in the matrix to the negative of the camera location - after the points are rotated around the origin you just shift them to the cameras position, but when i rotate the camera it seems to be rotating around the world origin rather than the cameras origin.


Quote:
First, the basic order of a singular set of transformations (left to right) is Scales*Rotations*Translations (S*R*T).


I read this off an article on the internet:

Generally the order of creating a view matrix is by starting with a translation so that the camera position is moved to the origin, followed by a rotation so that the cameras view direction in the world is aligned with the z axis.

???

[Edited by - staticVoid2 on February 2, 2008 3:57:09 PM]

This topic is closed to new replies.

Advertisement