• Create Account

### #ActualKaptein

Posted 29 November 2012 - 06:17 PM

if you have a simple modelview matrix, the 3x3 part is the rotation, or look-vectors if you will
a simple modelview matrix has only rotation and translation
if you scale your matrix, its look-vectors will no longer be unit-length, and you'll have to normalize all operations in the shader
the 4 columns: right, up, forward, translation
the 4th row is useless, except the perspective divide w in the translation vector, which is used in transformation

in GLSL:
vec3 rotatedVector = mat3(matview) * someVec3;
or
vec3 rotatedVector = vec3(matview * someVec4);
or
vec3 rotatedVector = (matview * someVec4).xyz // swizzles are powerful

if your matrix has a scale other than 1.0:
vec3 something = normalize(mat3(matview) * in_something.xyz);

using swizzles (.xyz, .xz, .x, .xw, .xxx, .xyxy) doesn't cost anything, it just as fast using "vector.xyz" as using "vector"
so use them liberally to explain to your future self what you are doing

the w coordinate is the homogenous coordinate, usually only being 1.0 and 0.0
where 1.0 is euclidian space, as in, not infinite
lights usually are placed at (x, y, z, 0) because they are "infinitely far away"
so, if you want to transform a vec3 with a vec4 matrix, for example by providing your vertex position in xyz only:
gl_Position = matproj * matview * vec4(in_vertex.xyz, 1.0);

and finally, I notice it's another GLM question, to which i have no answer..
in any case, if you know what the contents of the matrix is, which i have explained, you should be able to grab the 3x3 part

### #2Kaptein

Posted 29 November 2012 - 06:11 PM

if you have a simple modelview matrix, the 3x3 part is the rotation, or look-vectors if you will
a simple modelview matrix has only rotation and translation
if you scale your matrix, its look-vectors will no longer be unit-length, and you'll have to normalize all operations in the shader
the 4 columns: right, up, forward, translation
the 4th row is useless, except the perspective divide w in the translation vector, which is used in transformation

in GLSL:
vec3 rotatedVector = mat3(matview) * someVec3;
or
vec3 rotatedVector = vec3(matview * someVec4);
or
vec3 rotatedVector = (matview * someVec4).xyz // swizzles are powerful

if your matrix has a scale other than 1.0:
vec3 something = normalize(mat3(matview) * in_something.xyz);

using swizzles (.xyz, .xz, .x, .xw, .xxx, .xyxy) doesn't cost anything, it just as fast using "vector.xyz" as using "vector"
so use them liberally to explain to your future self what you are doing

the w coordinate is the homogenous coordinate, usually only being 1.0 and 0.0
where 1.0 is euclidian space, as in, not infinite
lights usually are placed at (x, y, z, 0) because they are "infinitely far away"
so, if you want to transform a vec3 with a vec4 matrix, for example by providing your vertex position in xyz only:
gl_Position = matproj * matview * vec4(in_vertex.xyz, 1.0);

### #1Kaptein

Posted 29 November 2012 - 06:08 PM

if you have a simple modelview matrix, the 3x3 part is the rotation, or look-vectors if you will
a simple modelview matrix has only rotation and translation
if you scale your matrix, its look-vectors will no longer be unit-length, and you'll have to normalize all operations in the shader
the 4 columns: right, up, forward, translation
the 4th row is useless, except the perspective divide w in the translation vector, which is used in transformation

in GLSL:
vec3 rotatedVector = mat3(matview) * someVec3;
or
vec3 rotatedVector = vec3(matview * someVec4);
or
vec3 rotatedVector = (matview * someVec4).xyz // swizzles are powerful

if your matrix has a scale other than 1.0:
vec3 something = normalize(mat3(matview) * in_something.xyz);

using swizzles (.xyz, .xz, .x, .xw, .xxx, .xyxy) doesn't cost anything, it just as fast using "vector.xyz" as using "vector"
so use them liberally to explain to your future self what you are doing

PARTNERS