Java-Gaming.org Hi !
 Featured games (90) games approved by the League of Dukes Games in Showcase (754) Games in Android Showcase (229) games submitted by our members Games in WIP (842) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
Pages: [1]
 ignore  |  Print
 Vec3 * Mat4x4  (Read 2756 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

JGO Kernel

Medals: 517

 « 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

 DesertCoockie (20 views) 2018-05-13 18:23:11 nelsongames (68 views) 2018-04-24 18:15:36 nelsongames (65 views) 2018-04-24 18:14:32 ivj94 (749 views) 2018-03-24 14:47:39 ivj94 (79 views) 2018-03-24 14:46:31 ivj94 (595 views) 2018-03-24 14:43:53 Solater (95 views) 2018-03-17 05:04:08 nelsongames (168 views) 2018-03-05 17:56:34 Gornova (378 views) 2018-03-02 22:15:33 buddyBro (1038 views) 2018-02-28 16:59:18
 Java Gaming Resourcesby philfrei2017-12-05 19:38:37Java Gaming Resourcesby philfrei2017-12-05 19:37:39Java Gaming Resourcesby philfrei2017-12-05 19:36:10Java Gaming Resourcesby philfrei2017-12-05 19:33:10List 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:05
 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