ofxMatrix4x4

Hi,

I am currently working on a matrix4x4 class because that is really useful for lighting calculations and everything related to openGL matrices. I want to build it similar to the matrix3x3 class that allredy comes with of. Unfortunatelly I am not getting a few things on my own though. especially the inversion part. the method used there is new to me and I could not get that done on my own. Any ideas?

  
  
void ofxMatrix3x3::invert() {  
	 double det = determinant();  
	 ofxMatrix3x3 B;  
  
	 //included in these calculations: minor, cofactor (changed signs), transpose (by the order of "="), division through determinant  
	 B.a = ( e * i - h * f) / det;  
	 B.b = (-b * i + h * c) / det;  
	 B.c = ( b * f - e * c) / det;  
	 B.d = (-d * i + g * f) / det;  
	 B.e = ( a * i - g * c) / det;  
	 B.f = (-a * f + d * c) / det;  
	 B.g = ( d * h - g * e) / det;  
	 B.h = (-a * h + g * b) / det;  
	 B.i = ( a * e - d * b) / det;  
  
	 *this = B;  
}  
  

I want to make this for 4x4, so how would that look? this method looks alot shorter and faster compared to the ones I saw until now so I would like to stick with that. Thanks!

PS: I also want to extend the vec3f class with same basic matrix multiplication features.

Oh and another thing I noticed is this:

  
void ofxMatrix3x3::operator*=(const ofxMatrix3x3& B) {  
	a *= B.a;  
	b *= B.b;  
	c *= B.c;  
	d *= B.d;  
	e *= B.e;  
	f *= B.f;  
	g *= B.g;  
	h *= B.h;  
	i *= B.i;  
}  
  

isn’t this wrong? I am new to matrix calculations but should’t it be more something like this:

  
  
void ofxMatrix3x3::operator*=(const ofxMatrix3x3& B) {  
	ofxMatrix3x3 C;  
	C.a = a * B.a + b * B.d + c * B.g;  
	C.b = a * B.b + b * B.e + c * B.h;  
	C.c = a * B.c + b * B.h + c * B.i;  
	C.d = d * B.a + e * B.d + f * B.g;  
	C.e = d * B.b + e * B.e + f * B.h;  
	C.f = d * B.c + e * B.h + f * B.i;  
	C.g = g * B.a + h * B.d + i * B.g;  
	C.h = g * B.b + h * B.e + i * B.h;  
	C.i = g * B.c + h * B.h + i * B.i;  
	*this = C;  
}  

or am I misunderstanding that part?

perhaps you can check your implementation against some working ones. See the implementation of osg::Matrix for example.

Or just use the Matrix, Vector and Quat-classes from osg :wink:

http://www.openscenegraph.org/

Hey, thanks, I will take a look at their class. I want to write my own thing though because that helps me to better understand the things going on. I might also write an addon which extends ofxVectorMath with some more advanced things. Any ideas on the code snippets I posted?

Nobody? Not even the one who wrote the addon? Pleaase :slight_smile:

hey yes, it looks like you are right – this is definitely a bug in the matrix class.

it would really be great if you can extend/improve the matrix part of the addon. it is in great need, but my knowledge of matrix math is rather limited so I havn’t tried tackling it yet. look like there might be some useful info here:

http://www.gamedev.net/reference/list.a-…-goryid=259

Hi Chris,

Yes, I will definately keep on working on that class and as soon as it is something complete I will release it!
Still any help is welcome, thanks!

Hi,

I’m also currently need a matrix4x4, to work some stuf in terrain picking, so i was wonder, if you have allready some code done ?

maybe , we can also extend a bit ofxCamera class, with some function that we always need.

I can help, if some one is interessed.

Carlos

hi

take a look at this library, well it’s just a .h file with implementations for the most used operations for vector math including 4x4 matrixes. only thing is it’s templated so the code can be a bit difficult to read if you’re not used to templates:

http://bartipan.net/vmath/

Hi arturo,

Thanks so much for the link, it will be very helpfull.

Hi moka,

Just saw this thread … The Matrix code in ofxVectorMath would definitely need a brushup. While I have been heavily contributing and maintaining to vector classes nobody has really touched the matrix code for over a year now.

If you need more example code, trimesh2 lib has a pretty sick vector math implementation, although not as extensive as vmath. I attched the two files of interest. Matrix stuff is in XForm.h

http://www.cs.princeton.edu/gfx/proj/trimesh2/

Also it would be cool to do the same union trick in the matrix classes that allows us to address elements in a vector through x,y,z and v[]. This makes it much easier to integrate with other libs that use either or convention.

trimesh2-vectormath.zip

Hi,

I was wondering when there will be the next “stable” update to ofxVectorMath including the new matrix and quaternion classes since I am currently starting to work on a deferred rendering engine in openGL and I would need those things.-
Is there a new release anytime soon? Otherwise I would propably make my own classes or try to find some that fit my needs.
Thanks!

EDIT:

I jsut came across this lib: http://cmldev.net/

seems to be just what I need, so I will look into that!