I've nicked some of trinity's matrix stuff for the basis of v2's entity system. It's working fine, with sub-entities etc, but I really need to figure out how to point a matrix towards a point in 3d space.
Any links or tutorials or even code that cover this or anyone here know?
Here's the matrix code as is, fairly simple, but works.
Any links or tutorials or even code that cover this or anyone here know?
Here's the matrix code as is, fairly simple, but works.
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