Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (408)
games submitted by our members
Games in WIP (293)
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 455 times)
0 Members and 1 Guest are viewing this topic.
Offline Meanz

Junior Newbie





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

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

Vec3 * Mat4x4
Offline ClickerMonkey

Senior Member


Medals: 11


Game Engineer


« Reply #1 - Posted 2013-01-30 13: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;
}



Offline Meanz

Junior Newbie





« Reply #2 - Posted 2013-01-30 13: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!
Legends of Yore - The Casual Retro Roguelike
Offline Roquen

JGO Ninja


Medals: 66



« Reply #3 - Posted 2013-01-30 13: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.
Offline Meanz

Junior Newbie





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

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

The linear algebra course on Khan Academy is pretty good.
Offline sproingie
« Reply #6 - Posted 2013-01-31 03: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. 
Offline ClickerMonkey

Senior Member


Medals: 11


Game Engineer


« Reply #7 - Posted 2013-01-31 03: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  
 
 

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Browse for soundtracks for your game!

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (147 views)
2013-05-17 21:29:12

alaslipknot (155 views)
2013-05-16 21:24:48

gouessej (186 views)
2013-05-16 00:53:38

gouessej (180 views)
2013-05-16 00:17:58

theagentd (190 views)
2013-05-15 15:01:13

theagentd (174 views)
2013-05-15 15:00:54

StreetDoggy (218 views)
2013-05-14 15:56:26

kutucuk (243 views)
2013-05-12 17:10:36

kutucuk (241 views)
2013-05-12 15:36:09

UnluckyDevil (247 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!
Page created in 0.103 seconds with 21 queries.