I am a newbie at matrices.
So my question is simple, how would I go about doing the following multiplication ?
Vec3 * Mat4x4
I am a newbie at matrices.
So my question is simple, how would I go about doing the following multiplication ?
Vec3 * Mat4x4
Very carefully…
public void transform(Matrix4x4 m, Vec3 in, Vec3i out) {
out.x = (in.x * m.e00) + (in.y * m.e01) + (in.z * m.e02) + m.e03;
out.y = (in.x * m.e10) + (in.y * m.e11) + (in.z * m.e12) + m.e13;
out.z = (in.x * m.e20) + (in.y * m.e21) + (in.z * m.e22) + m.e23;
}
Thanks a lot, that finally finished my skinning process!
I really need to take some time to sit down and learn more of them matrices.
My opinion here is that you’d be better off understanding vectors and coordinate frames first. Linear algebra is ‘just’ folding a couple of operations into a logically single one for affine transforms.
“coordinate frames” ?
Just to elaborate on ClickerMonkey’s perfectly correct answer:
You can’t generally multiply a vector of 3 components with a 4x4 matrix, but the standard geometric interpretation of a 4x4 matrix is of an affine transform in homogeneous coordinate space. A vector in 3d Cartesian space (x,y,z) is a vector in homogeneous space (x,y,z,w) where w=1. So long story short, you turn your vec3(x,y,z) into a vec4(x,y,z,1) and then do normal matrix multiplication with it.
Agreed! Transforming vectors need a w value of 0 and transforming points need a value of 1!
w is this neat part of a vector, if you set it to the square root of a point, the point is interpreted by OpenGL or a Matrix as a normalized vector.
v.w = (float)Math.sqrt(v.x * v.x + v.y * v.y + v.z * v.z);
Point/Vector is now normalized!
Full transform method with Vec4
out.x = (in.x * e00) + (in.y * e01) + (in.z * e02) + (in.w * e03);
out.y = (in.x * e10) + (in.y * e11) + (in.z * e12) + (in.w * e13);
out.z = (in.x * e20) + (in.y * e21) + (in.z * e22) + (in.w * e23);
out.w = (in.x * e30) + (in.y * e31) + (in.z * e32) + (in.w * e33);