Java-Gaming.org Hi !
 Featured games (90) games approved by the League of Dukes Games in Showcase (769) Games in Android Showcase (230) games submitted by our members Games in WIP (856) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
 Home Help Search Login Register
Pages: [1]
 ignore  |  Print
 Vec3 * Mat4x4  (Read 2907 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.
 Games published by our own members! Check 'em out!
Roquen

JGO Kernel

Medals: 518

 « 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

 EgonOlsen (1668 views) 2018-06-10 19:43:48 EgonOlsen (1705 views) 2018-06-10 19:43:44 EgonOlsen (1155 views) 2018-06-10 19:43:20 DesertCoockie (1583 views) 2018-05-13 18:23:11 nelsongames (1183 views) 2018-04-24 18:15:36 nelsongames (1707 views) 2018-04-24 18:14:32 ivj94 (2531 views) 2018-03-24 14:47:39 ivj94 (1756 views) 2018-03-24 14:46:31 ivj94 (2833 views) 2018-03-24 14:43:53 Solater (969 views) 2018-03-17 05:04:08
 Deployment and Packagingby mudlee2018-08-22 18:09:50Java Gaming Resourcesby gouessej2018-08-22 08:19:41Deployment and Packagingby gouessej2018-08-22 08:04:08Deployment and Packagingby gouessej2018-08-22 08:03:45Deployment and Packagingby philfrei2018-08-20 02:33:38Deployment and Packagingby philfrei2018-08-20 02:29:55Deployment and Packagingby philfrei2018-08-19 23:56:20Deployment and Packagingby philfrei2018-08-19 23:54:46
 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