Java-Gaming.org Hi !
 Featured games (90) games approved by the League of Dukes Games in Showcase (731) Games in Android Showcase (217) games submitted by our members Games in WIP (799) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
Pages: [1]
 ignore  |  Print
 Vec3 * Mat4x4  (Read 2002 times) 0 Members and 1 Guest are viewing this topic.
Meanz

Junior Newbie

 « Posted 2013-01-30 12:15:49 »

I am a newbie at matrices.
So my question is simple, how would I go about doing the following multiplication ?

Vec3 * Mat4x4
ClickerMonkey

JGO Coder

Medals: 26
Exp: 10 years

Game Engineer

 « Reply #1 - Posted 2013-01-30 12:18:40 »

Very carefully..

 1  2  3  4  5 `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;}`

Meanz

Junior Newbie

 « Reply #2 - Posted 2013-01-30 12:26:48 »

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.
Roquen
 « Reply #3 - Posted 2013-01-30 12:56:16 »

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.
Meanz

Junior Newbie

 « Reply #4 - Posted 2013-01-30 15:17:28 »

"coordinate frames" ?
Spasi
 « Reply #5 - Posted 2013-01-30 19:29:48 »

The linear algebra course on Khan Academy is pretty good.
sproingie

JGO Kernel

Medals: 202

 « Reply #6 - Posted 2013-01-31 02:32:18 »

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.
ClickerMonkey

JGO Coder

Medals: 26
Exp: 10 years

Game Engineer

 « Reply #7 - Posted 2013-01-31 02:50:05 »

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.

 1 `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

 1  2  3  4 `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);`

Pages: [1]
 ignore  |  Print

You cannot reply to this message, because it is very, very old.

 Archive (341 views) 2017-04-27 17:45:51 buddyBro (538 views) 2017-04-05 03:38:00 CopyableCougar4 (988 views) 2017-03-24 15:39:42 theagentd (1020 views) 2017-03-24 15:32:08 Rule (995 views) 2017-03-19 12:43:22 Rule (978 views) 2017-03-19 12:42:17 Rule (975 views) 2017-03-19 12:36:21 theagentd (1077 views) 2017-03-16 05:07:07 theagentd (997 views) 2017-03-15 22:37:06 theagentd (771 views) 2017-03-15 22:32:18
 List of Learning Resourcesby elect2017-03-13 14:05:44List of Learning Resourcesby elect2017-03-13 14:04:45SF/X Librariesby philfrei2017-03-02 08:45:19SF/X Librariesby philfrei2017-03-02 08:44:05SF/X Librariesby SkyAphid2017-03-02 06:38:56SF/X Librariesby SkyAphid2017-03-02 06:38:32SF/X Librariesby SkyAphid2017-03-02 06:38:05SF/X Librariesby SkyAphid2017-03-02 06:37:51
 java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org