Decomposing a 4x4 3D matrix

BlitzMax Forums/BlitzMax Programming/Decomposing a 4x4 3D matrix

For my opensource module assimp blitzmax I'm having major trouble decomposing and applying a 4x4 matrix into minib3d space.

I need to decompose this matrix: http://assimp.sourceforge.net/lib_html/data.html

see also http://assimp.svn.sourceforge.net/viewvc/assimp/trunk/include/aiMatrix4x4.inl?view=markup

into miniB3D space witch I think is a lefthanded coordinate system?

The Decompositions I have tried to make, are in the Decompose function here: http://code.google.com/p/blitzmax-assimp/source/browse/trunk/assimp.bmx

they are then applied in my test program:

http://code.google.com/p/blitzmax-assimp/source/browse/trunk/examples/hierarchy.bmx

in the ProccesIaNodeAndChildren() function.

Values does not look all bad, but I really need some help to find out where I'm going wrong.

(I've tried a lot of sign swapping and axis changing, but can't seem to get it right.)

Any help is mush appreciated!

greetings :) a long while back i wrote something similar for minib3d that utilized the mesh loading features of irrlicht to load models into minib3d. i will take a peek when i get home tonight (about 6 hours from now). if you dont have an answer by then i will see if there is anything in that project that can help you out.

greetings :) Sounds great gman.

I seem to be onto something with this one

rx = bank
ry = heading
rz = attitude


	Method Decompose()
	
		Tx = a4
		Ty = b4 
		Tz = c4
	
	
		Sx = Sqr( a1*a1 + a2*a2 + a3*a3 )
		Sy = Sqr( b1*b1 + b2*b2 + b3*b3 ) 
		Sz = Sqr( c1*c1 + c2*c2 + c3*c3 )
		
		Local rm:aiMatrix3x3 = New aiMatrix3x3	
			
		rm.a1 = a1 ; rm.a2 = a2 ; rm.a3 = a3
		rm.b1 = b1 ; rm.b2 = b2 ; rm.b3 = b3
		rm.c1 = c1 ; rm.c2 = c2 ; rm.c3 = c3		
				
		If sx Then
			rm.a1:/sx	
			rm.a2:/sx	
			rm.a3:/sx	
		EndIf
		If sy Then
			rm.b1:/sy
			rm.b2:/sy	
			rm.b3:/sy	
		EndIf
		If sz Then
			rm.c1:/sz
			rm.c2:/sz	
			rm.c3:/sz	
		EndIf
		
		
		Local heading:Float
		Local bank :Float
		Local attitude :Float		


		If (b1 > 0.998) ' singularity at north pole
			heading = ATan2(rm.a3,rm.c3)
			attitude = 90 'Pi/2
			bank = 0
			Return
		EndIf
		
		If (b1 < -0.998)' singularity at south pole
			heading = ATan2(rm.a3,rm.c3)
			attitude = - 90 '-Pi/2
			bank = 0
			Return
		EndIf
	
		heading = ATan2(-rm.c1,rm.a1)
		bank = ATan2(-rm.b3,rm.b2)
		attitude = ASin(rm.b1)

	End Method 


greetings :) my apologies on the delay. it looks like the only thing i did to accomplish it was to change the Z to negative Z while loading the tris. didnt really have to do anything with the matrices at all. it might be a bit different than what you are trying to do. my goal was to load the tris from the models loaded in Irrlicht and then load them into minib3d surfaces. here is a running project with source:

http://www.gprogs.com/irrlicht.mod/model_loader.zip

the beef is in minib3d_meshloader.bmx. specifically in the CreateSurfaceFromMeshBuffer() method. also included is the underlying C file (imeshbuffer_wrap.h) that does the translation. the bSwap parameter was added for minib3d. in specific, check out the function:

IrrScene_IMeshBuffer_fillS3DVertexVerticesPtrs()

if you have any questions shoot :) dont mind all the ramblings in there. i type comments while i ideate :)

hi again. thanks gman.

You're right, I can't find any decomposition formulas in there :-)

Your tip on the z negation helped me out, so that now everything looks ok.

I'll have to do a little more swapping, to get Y_UP, but it seems ok for now.

fantastic :) glad i could help out! cant wait to see the results :)