Hi Kevin,
I hope I am not too late to help you with your problem/question. You did right to watch on scratchapixel but you should look at this page in particular:
http://www.scratchapixel.com/lessons/3dbasiclessons/lesson4geometry/conventionsagainrowmajorvscolumnmajorvector/
Basically knowing whether you use a right or left hand coordinate system is indeed important but in fact, in that particular case, it has little to do with whether you matrix is correct or not. What is important for constructing your matrix from the 3 vectors (up, right, forward) is whether you renderer uses row or columnmajor notation for matrices. As mentioned in the page above if you use the rowmajor notation, your 3 vectors should be written vertically in the matrix and if you use columnmajor they should be written horizontally. In other words, assuming you have the vectors A B C (representing the right, top and forward vector from your camera coordinate system) you should write:
Ax Bx Cx
Ay By Cy
Az Bz Cz
If you use rowmajor notation. Now I will explain you why (there's a way an easy of checking how you should write the matrix if you can't remember it by heart). Remember that if you use rowmajor vector then the vectormatrix multiplication needs to be written as:
Ax Ay Az
V[x y z] M Bx By Bz [EDITED: changed from original post]
Cx Cy Cz
Where A is Right Vector, B is Up Vector and C is Forward Vector
Computing the multiplication can be done like that:
V'x = Vx * Ax + Vy * Bx + Vz * Cx
V'y = Vx * Ay + Vy * By + Vz * Cy [EDITED: changed from original post]
V'z = Vx * Az + Vy * Bz + Vz * Cz
EDITED FROM HERE:
I guess I was a bit too quick yesterday when I replied and my demonstration was actually wrong. Talking to the guys from work, they showed me a better way of checking that this is the right way of writing the matrix if you use a rowmajor notation for matrices. The default cartesian coordinate system should be like that:
Y (up 0, 1, 0)
^

> X (right 1, 0, 0)
/
/
Z (forward 1, 0, 0)
If you have a camera you would be looking down the zaxis. Now you can imagine that your camera is looking down the xaxis. Therefore the right vector for this camera becomes (0, 0, 1), the Up vector is still (0, 1, 0) and the Forward vector becomes the xaxis (1, 0, 0):
Up Right
^ / \
 / \
/> Fwd > camera
/
/
Now if you right these vectors as a matrix you get:
Rx Ry Rz 0 0 1
M = Ux Uy Yz = 0 1 0
Fx Fy Fz 1 0 0
This matrix is called the cameratoworld matrix.
The demonstration to check that this is correct is a bit complicated so I thought I would first quickly correct my original post to avoid leading you and other people on the wrong track. I will post the demonstration later today.
Sorry for having (probably) confused you (even more). Anyway, bottom line is that if you use rowmajor notation for your vectors and matrices (and assuming a righthand coordinate system) as you mentioned, then this is the "proper" way of writing the cameratoworld matrix from the right, up and fwd vector.
One tip though. I am always (and I proved it) myself very confused about these things. I found scratchapixel very useful but I am also often using Maya to check the accuracy of my code. For instance in that case, you can create a default camera, rotate it around the yaxis by 90 degrees CCW, and check the resulting world matrix with the following mel code: getAttr camera.worldMatrix;
Because Maya uses rowmajor and uses the right hand coordinate system, if you use the same standard, then the result you get should mach your code and what you use.
Show differencesHistory of post edits
#Actualmast4as
Posted 08 January 2013  03:06 PM
#4mast4as
Posted 08 January 2013  02:50 PM
Hi Kevin,
I hope I am not too late to help you with your problem/question. You did right to watch on scratchapixel but you should look at this page in particular:
http://www.scratchapixel.com/lessons/3dbasiclessons/lesson4geometry/conventionsagainrowmajorvscolumnmajorvector/
Basically knowing whether you use a right or left hand coordinate system is indeed important but in fact, in that particular case, it has little to do with whether you matrix is correct or not. What is important for constructing your matrix from the 3 vectors (up, right, forward) is whether you renderer uses row or columnmajor notation for matrices. As mentioned in the page above if you use the rowmajor notation, your 3 vectors should be written vertically in the matrix and if you use columnmajor they should be written horizontally. In other words, assuming you have the vectors A B C (representing the right, top and forward vector from your camera coordinate system) you should write:
Ax Bx Cx
Ay By Cy
Az Bz Cz
If you use rowmajor notation. Now I will explain you why (there's a way an easy of checking how you should write the matrix if you can't remember it by heart). Remember that if you use rowmajor vector then the vectormatrix multiplication needs to be written as:
Ax Ay Az
V[x y z] M Bx By Bz [EDITED: changed from original post]
Cx Cy Cz
Where A is Right Vector, B is Up Vector and C is Forward Vector
Computing the multiplication can be done like that:
V'x = Vx * Ax + Vy * Bx + Vz * Cx
V'y = Vx * Ay + Vy * By + Vz * Cy [EDITED: changed from original post]
V'z = Vx * Az + Vy * Bz + Vz * Cz
EDITED FROM HERE:
I guess I was a bit too quick yesterday when I replied and my demonstration was actually wrong. Talking to the guys from work, they showed me a better way of checking that this is the right way of writing the matrix if you use a rowmajor notation for matrices. The default cartesian coordinate system should be like that:
Y (up 0, 1, 0)
^

> X (right 1, 0, 0)
/
/
Z (forward 1, 0, 0)
If you have a camera you would be looking down the zaxis. Now you can imagine that your camera is looking down the xaxis. Therefore the right vector for this camera becomes (0, 0, 1), the Up vector is still (0, 1, 0) and the Forward vector becomes the xaxis (1, 0, 0):
Up Right
^ / \
 / \
/> Fwd > camera
/
/
Now if you right these vectors as a matrix you get:
Rx Ry Rz 0 0 1
M = Ux Uy Yz = 0 1 0
Fx Fy Fz 1 0 0
This matrix is called the cameratoworld matrix.
The demonstration to check that this is correct is a bit complicated so I thought I would first quickly correct my original post to avoid leading you and other people on the wrong track. I will post the demonstration later today.
Sorry for having (probably) confused you (even more). Anyway, bottom line is that if you use column major notation for your vectors and matrices (and assuming a righthand coordinate system) as you mentioned, then this is the "right" way of writing the cameratoworld matrix from the right, up and fwd vector.
One tip though. I am always (and I proved it) myself very confused about these things. I found scratchapixel very useful but I am also often using Maya to check the accuracy of my code. For instance in that case, you can create a default camera, rotate it around the yaxis by 90 degrees CCW, and check the resulting world matrix with the following mel code: getAttr camera.worldMatrix;
Because Maya uses rowmajor and uses the right hand coordinate system, if you use the same standard, then the result you get should mach your code and what you use.
#3mast4as
Posted 07 January 2013  02:18 PM
Hi Kevin,
I hope I am not too late to help you with your problem/question. You did right to watch on scratchapixel but you should look at this page in particular:
http://www.scratchapixel.com/lessons/3dbasiclessons/lesson4geometry/conventionsagainrowmajorvscolumnmajorvector/
Basically knowing whether you use a right or left hand coordinate system is indeed important but in fact, in that particular case, it has little to do with whether you matrix is correct or not. What is important for constructing your matrix from the 3 vectors (up, right, forward) is whether you renderer uses row or columnmajor notation for matrices. As mentioned in the page above if you use the rowmajor notation, your 3 vectors should be written vertically in the matrix and if you use columnmajor they should be written horizontally. In other words, assuming you have the vectors A B C (representing the right, top and forward vector from your camera coordinate system) you should write:
Ax Bx Cx
Ay By Cy
Az Bz Cz
If you use rowmajor notation. Now I will explain you why (there's a way an easy of checking how you should write the matrix if you can't remember it by heart). Remember that if you use rowmajor vector then the vectormatrix multiplication needs to be written as:
Ax Bx Cx
V[x y z] M Ay By Cy
Az Bz Cz
Computing the multiplication can be done like that:
V'x = Vx * Ax + Vy * Ay + Vz * Az
V'y = Vx * Bx + Vy * By + Vz * Bz
V'z = Vx * Cx + Vy * Cy + Vz * Cz
Okay so that doesn't help you much maybe. But imagine now that you actually want to transform a point using this technique. And to make it simple imagine you just want to translate a point along the xaxis. If you use rowmajor matrices the translation vector is located on the 13th, 14th and 16th coefficient of the matrix:
Ax Bx Cx 0
P[x y z] M Ay By Cy 0
Az Bz Cz 0
Tx Ty Tz 1
So imagine that you translate your camera along the xaxis to the right by 1 unit. Therefore your "right vector" is:
// translation along the xaxis thus Tx = 1
Right Vector = Rx Ry Rz Tx > 1 0 0 1
Up Vector = Ux Uy Uz Ty > 0 1 0 0
// no translation along the yaxis thus Ty = 0
Forward Vector = Fx Fy Fx Tz > 0 0 1 0
// no translation along the zaxis thus Tz = 0
If you put them in the matrix form:
Rx Ux Fx 0 1 0 0 0
P[x y z] M Ry Uy Fy 0 ==> P[x y z] * M 0 1 0 0
Rz Uz Fz 0 0 0 1 0
Tx Ty Tz 1 1 0 0 1
Now to know that this is the right way of putting the vector R, U and F in the matrix if you multiply the point 0 0 0 by the matrix then you should get 1 0 0 (since the matrix is supposed to translate your point by 1 unit towards the right along the xaxis). So just compute and verify that it's actually the case:
P'x = 0 * 1 + 0 * 0 + 0 * 0 + 1 = 1
P'y = 0 * 0 + 0 * 1 + 0 * 0 + 0 = 0
P'z = 0 * 0 + 0 * 0 + 0 * 1 + 0 = 0
Hope it helps a bit. This should be maybe clearer on scratchapixel indeed. I would be you I would contact them and asked them questions when you don't know or can't find information on their website. I work with them and know they are keen on improving their website, etc.
Hope I didn't make things more messy in your mind though ;)
#2mast4as
Posted 07 January 2013  02:13 PM
Hi Kevin,
I hope I am not too late to help you with your problem/question. You did right to watch on scratchapixel but you should look at this page in particular:
http://www.scratchapixel.com/lessons/3dbasiclessons/lesson4geometry/conventionsagainrowmajorvscolumnmajorvector/
Basically knowing whether you use a right or left hand coordinate system is indeed important but this is in fact in that particular case, little to do with whether you matrix is correct or not. What is important for constructing your matrix from the 3 vectors (up, right, forward) is whether you renderer uses row or columnmajor notation for your matrices. As mentioned in the page above if you use rowmajor your 3 vectors should written vertically in the matrix and if you use columnmajor they should be written horizontally. In other words, assuming you have the vectors A B C (representing the right, top and forward vector from your camera coordinate system) you should write:
Ax Bx Cx
Ay By Cy
Az Bz Cz
If you use rowmajor notation. Now I will explain you why (there's a way an easy of checking how you should write the matrix if you can't remember it by heart). Remember that if you use rowmajor vector then the vectormatrix multiplication needs to be written as:
Ax Bx Cx
V[x y z] M Ay By Cy
Az Bz Cz
Computing the multiplication can be done like that:
V'x = Vx * Ax + Vy * Ay + Vz * Az
V'y = Vx * Bx + Vy * By + Vz * Bz
V'z = Vx * Cx + Vy * Cy + Vz * Cz
Okay so that doesn't help you much maybe. But imagine now that you actually want to transform a point using this technique. And to make it simple imagine you just want to translate a point along the xaxis. If you use rowmajor matrices the translation vector is located on the 13th, 14th and 16th coefficient of the matrix:
Ax Bx Cx 0
P[x y z] M Ay By Cy 0
Az Bz Cz 0
Tx Ty Tz 1
So imagine that you translate your camera along the xaxis to the right by 1 unit. Therefore your "right vector" is:
Right Vector = Rx Ry Rz Tx > 1 0 0 1
Up Vector = Ux Uy Uz Ty > 0 1 0 0
// no translation along the yaxis thus Ty = 0
Forward Vector = Fx Fy Fx Tz > 0 0 1 0
// no translation along the zaxis thus Tz = 0
If you put them in the matrix form:
Rx Ux Fx 0 1 0 0 0
P[x y z] M Ry Uy Fy 0 ==> P[x y z] * M 0 1 0 0
Rz Uz Fz 0 0 0 1 0
Tx Ty Tz 1 1 0 0 1
Now to know that this is the right way of putting the vector R, U and F in the matrix if you multiply the point 0 0 0 by the matrix then you should get 1 0 0 (since the matrix is supposed to translate your point by 1 unit towards the right along the xaxis).
P'x = 0 * 1 + 0 * 0 + 0 * 0 + 1 = 1
P'y = 0 * 0 + 0 * 1 + 0 * 0 + 0 = 0
P'z = 0 * 0 + 0 * 0 + 0 * 1 + 0 = 0
Hope I helped a bit. This should be clearer on scratch indeed. I would be you I would contact them and asked them questions when you don't know or can't find information on their website. I work with them and know they are keen on improving their website, etc.
Hope I didn't make things more messy in your mind though ;)
#1mast4as
Posted 07 January 2013  02:10 PM
Hi Kevin,
I hope I am not too late to help you with your problem/question. You did right to watch on scratchapixel but you should look at this page in particular:
Basically knowing whether you use a right or left hand coordinate system is indeed important but this is in fact in that particular case, little to do with whether you matrix is correct or not. What is important for constructing your matrix from the 3 vectors (up, right, forward) is whether you renderer uses row or columnmajor notation for your matrices. As mentioned in the page above if you use rowmajor your 3 vectors should written vertically in the matrix and if you use columnmajor they should be written horizontally. In other words, assuming you have the vectors A B C (representing the right, top and forward vector from your camera coordinate system) you should write:
Ax Bx Cx
Ay By Cy
Az Bz Cz
If you use rowmajor notation. Now I will explain you why (there's a way an easy of checking how you should write the matrix if you can't remember it by heart). Remember that if you use rowmajor vector then the vectormatrix multiplication needs to be written as:
Ax Bx Cx
V[x y z] M Ay By Cy
Az Bz Cz
Computing the multiplication can be done like that:
V'x = Vx * Ax + Vy * Ay + Vz * Az
V'y = Vx * Bx + Vy * By + Vz * Bz
V'z = Vx * Cx + Vy * Cy + Vz * Cz
Okay so that doesn't help you much maybe. But imagine now that you actually want to transform a point using this technique. And to make it simple imagine you just want to translate a point along the xaxis. If you use rowmajor matrices the translation vector is located on the 13th, 14th and 16th coefficient of the matrix:
Ax Bx Cx 0
P[x y z] M Ay By Cy 0
Az Bz Cz 0
Tx Ty Tz 1
So imagine that you translate your camera along the xaxis to the right by 1 unit. Therefore your "right vector" is:
Right Vector = Rx Ry Rz Tx > 1 0 0 1
Up Vector = Ux Uy Uz Ty > 0 1 0 0 (no translation along the yaxis thus Ty = 0)
Forward Vector = Fx Fy Fx Tz > 0 0 1 0
If you put them in the matrix form:
Rx Ux Fx 0 1 0 0 0
P[x y z] M Ry Uy Fy 0 ==> P[x y z] * M 0 1 0 0
Rz Uz Fz 0 0 0 1 0
Tx Ty Tz 1 1 0 0 1
Now to know that this is the right way of putting the vector R, U and F in the matrix if you multiply the point 0 0 0 by the matrix then you should get 1 0 0 (since the matrix is supposed to translate your point by 1 unit towards the right along the xaxis).
P'x = 0 * 1 + 0 * 0 + 0 * 0 + 1 = 1
P'y = 0 * 0 + 0 * 1 + 0 * 0 + 0 = 0
P'z = 0 * 0 + 0 * 0 + 0 * 1 + 0 = 0