Original Post
🔒 Locked
🎮 Unity
Quick Question
Advertisement
Hmm, I'm not sure what level of maths experience you have (are you aware of the basic maths required to transform a vector by a matrix for example?) - so this may/may not be clear as mud. If it doesn't make any sense, read up on how to transform a vector by a matrix and write a few examples out on paper.
1) Transform()
a. expands the vector to homogenous form by including a w component.
b. the w component is set to 1 so the vector is x,y,z,1
c. the 4d homogenous vector is then multiplied by the full 4x4 matrix.
d. the output is the 4d homogenous vector: x',y',z',w'
e. if last column (or row depending on how you think of matrices) of your matrix isn't being used, the output w' component of the vector will be 1 (w'=1). Rotation, translation, scaling won't use the the last column of the matrix, so the w' that is output can be ignored.
f. if you work through the maths of multiplying a vector by a matrix, you'll see that the w=1 is necessary to apply translation.
g. Take away point: for most world or view matrices, you won't be using the last column - and so this is the type of transform you'll use most.
2) TransformCoordinate()
a. expands the vector to homogenous form by including a w component.
b. the w component is set to 1 so the vector is x,y,z,1
c. the 4d homogenous vector is then multiplied by the full 4x4 matrix.
d. the output is the 4d homogenous vector: x',y',z',w'
e. to "project" a 4D homogenous coordinate back to a 3D one, you divide all the components of the coordinate by w': x''=x'/w', y''=y'/w', z''=z'/w' TransformCoord() does this.
f. if the last column of your matrix is being used, then the matrix will be something like a projection matrix, and does something which can't be represented by a plain linear transform (such as needing to divide).
g. Take away point: if you want to use a matrix which contains a projection, TransformCoordinate() is probably the one to use.
3) TransformNormal()
a. normal vectors (as in vertex normals, face normals, etc) describe a "direction" and only a direction (there are uses of non unit normals, but they don't matter to this discussion).
b. because of that, when you're transforming a normal, you don't want to "translate" it at all.
c. so TransformNormal() transforms the 3D vector by the top left 3x3 part of the matrix; this doesn't translate the vector so is what you want to do.
d. Take away point: if you only want to rotate, scale or skew the vector without any translations or projections, use TransformNormal()
1) Transform()
a. expands the vector to homogenous form by including a w component.
b. the w component is set to 1 so the vector is x,y,z,1
c. the 4d homogenous vector is then multiplied by the full 4x4 matrix.
d. the output is the 4d homogenous vector: x',y',z',w'
e. if last column (or row depending on how you think of matrices) of your matrix isn't being used, the output w' component of the vector will be 1 (w'=1). Rotation, translation, scaling won't use the the last column of the matrix, so the w' that is output can be ignored.
f. if you work through the maths of multiplying a vector by a matrix, you'll see that the w=1 is necessary to apply translation.
g. Take away point: for most world or view matrices, you won't be using the last column - and so this is the type of transform you'll use most.
2) TransformCoordinate()
a. expands the vector to homogenous form by including a w component.
b. the w component is set to 1 so the vector is x,y,z,1
c. the 4d homogenous vector is then multiplied by the full 4x4 matrix.
d. the output is the 4d homogenous vector: x',y',z',w'
e. to "project" a 4D homogenous coordinate back to a 3D one, you divide all the components of the coordinate by w': x''=x'/w', y''=y'/w', z''=z'/w' TransformCoord() does this.
f. if the last column of your matrix is being used, then the matrix will be something like a projection matrix, and does something which can't be represented by a plain linear transform (such as needing to divide).
g. Take away point: if you want to use a matrix which contains a projection, TransformCoordinate() is probably the one to use.
3) TransformNormal()
a. normal vectors (as in vertex normals, face normals, etc) describe a "direction" and only a direction (there are uses of non unit normals, but they don't matter to this discussion).
b. because of that, when you're transforming a normal, you don't want to "translate" it at all.
c. so TransformNormal() transforms the 3D vector by the top left 3x3 part of the matrix; this doesn't translate the vector so is what you want to do.
d. Take away point: if you only want to rotate, scale or skew the vector without any translations or projections, use TransformNormal()
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement