The Matrix 4 - How Neo Got His Groove Back.

BlitzMax Forums/BlitzMax OpenGL Programming/The Matrix 4 - How Neo Got His Groove Back.

Having some wierd issues with using matrixes in gl rather than it's usual rotatef funcs,

This code, embeded into v2's camera bind for testing,

  glRotatef 0,1,0,0
  glRotatef 1,0,Angle,0


Works as expected. The box arcing around the scene(As the camera is position 250 units away from it)

But, when I try to use the entities local(or global, it has both) matrix to define the rotation of the camera, something very wierd happens.
Instead of an arcing box I get a black screen, except for a brief full screen of white.

Which to me indicates something in matrix code(Which does work, tested as I was doing it 2dally.) isn't reallying conforming to the gl matrix layout..

Here's the matrix code I'm using,



Type Matrix
	
	Method New()
	
		Mat=New Double[16]
			
	End Method
	
	Method Delete()
	
	'	Release Mat
		Mat=Null
	
	End Method
	
	Method Identity()
	
		Local Index:Int
		
		Mat[ 0 ] = 1
		For Index=1 To 15
			Mat[ Index ]=0
		Next
	
	End Method
	
	Method Pitch( nPitch:Double )
	
		Self.Identity()
		mat[5]=Cos( nPitch )
		mat[6]=Sin( nPitch )
		mat[9]=-Sin( nPitch )
	    mat[10]=Cos( nPitch )
	    mat[15]=1
	
	End Method
	
	Method Yaw( nYaw:Double )
	
	   Self.Identity()
		mat[0]=Cos( nYaw )
		mat[2]=-Sin( nYaw )
		mat[5]=1
		mat[8]=Sin( nYaw )
		Mat[10]=Cos( nYaw )
	
	End Method
	
	Method Roll( nRoll:Double )
	
	   Self.Identity()
		mat[0]=Cos( nRoll )
		mat[1]=Sin( nRoll )
		mat[4]=-Sin( nRoll )
		mat[5]=Cos( nRoll )
	
	End Method
		
	Method Position( nX:Double,nY:Double,nZ:Double )
	
		Self.Identity()
		mat[0] = 1
		mat[3] = nX
		mat[5] = 1
		mat[7] = nY
		mat[11] = nZ
		mat[15] = 1
	
	End Method
	
	Method Copy( IN:Matrix)
	
	   Local Index:Int,Val:Double
	
	   For Index=0 To 15
		Mat[Index]=IN.Mat[Index]
	   Next	
	
	End Method
	
	Method Rotate( nPitch:Double,nYaw:Double,nRoll:Double,X:Double=0,Y:Double=0,Z:Double=0 )
		
		Self.identity()
		Local Temp:Matrix = New Matrix
				
		Self.Pitch( nPitch )
		Temp.Copy( Self )
		Self.Yaw( nYaw ) 
		Temp.Multiply( Self )
		Self.Roll( nRoll )
		Temp.Multiply( Self )
		Self.Position( X,Y,Z )
		Temp.Multiply( Self )
		
		Self.Copy( Temp )
		
	End Method
		
	Method TForm_Point( X:Double,Y:Double,Z:Double )
	
		tFormX = (mat[0] * X) + (mat[1] * Y) + (mat[2] * Z) + mat[3]
		tFormY = (mat[4] * X) + (mat[5] * Y) + (mat[6] * Z) + mat[7]
		tFormZ = (mat[8] * X) + (mat[9] * Y) + (Mat[10] * Z) + mat[11]
	
	End Method
	
	Method TForm_Point2D( X:Double,Y:Double )
		
		Local Z=0
		tFormX = (mat[0] * X) + (mat[1] * Y) + (mat[2] * Z) + mat[3]
		tFormY = (mat[4] * X) + (mat[5] * Y) + (mat[6] * Z) + mat[7]
		
	End Method
	
	
	
	Method Multiply( With:Matrix )
	
		Local Temp:Matrix = New Matrix
		Local M:Int,m1:Int,m2:Int
	
		For m=0 To 3
			For m1=0 To 3
				Temp.Mat[ m1*4+m]=0
				For m2=0 To 3
					Temp.Mat[ m1*4+m]:+With.Mat[m2*4+m]*Mat[m1*4+m2]
				Next
			Next
	   Next
	
	   Local Index:Int,Val:Double 
	
	   For Val:Double =EachIn Temp.mat
		Mat[Index]=Val
		Index:+1
	   Next
	   'Release Temp
	
	End Method
	
	Method Debug( PrintFunc:Int(Out:String) )
		
		For Local J=0 To 15
			
			printFunc (J+1)+":"+Mat[J]
			
		Next
			
	End Method
	
	Field Mat:Double[]
	Field tFormX:Double,tFormY:Double,tFormZ:Double,tW:Double
End Type



This is the code from the entity class that generates the 'correct' matrix for rotations.

Method Rotate( Pitch:Double,Yaw:Double,Roll:Double,GlobalRotation = True )
	
		If GlobalRotation
			
			Rotation.Rotate( Pitch,Yaw,Roll )
			LocalRot.Copy( Rotation )
			
			If Parent<>Null
				
				Rotation.Multiply( Parent.Rotation )
			'	Self.UpdateSubs()
						
			Else
			
				LocalRot.Rotate( 0,0,0 )
			
			EndIf
			
			Self.UpdateSubs()
						
		Else
			
			If Parent<>Null
			
				Local Temp:Matrix = New Matrix
				Temp.Rotate( Pitch,Yaw,Roll )
				Rotation.Copy( Parent.Rotation )
				Rotation.Multiply( Temp )
				Self.UpdateSubs()
			Else
				
				Rotation.Rotate( Pitch,Yaw,Roll )
				LocalRot.Rotate( 0,0,0 )
				Self.UpdateSubs()
				
			EndIf
			
		EndIf
	End Method



Any ideas would be nice, I've hit a brick wall, but don't really want to switch back to glrotatef etc...