Just putting this here in case it should be needed by anyone.
I was trying to work out how to use the matrix functions for dbpro. I got stuck and so wrote my own.
Here's the snippet to be included in your program (yeah the array names are really stupid...this is to limit the chance that you wuld already have used these arrays in your program)
SetupMatrixSystem:
dim gdertsamx#(50,4,4)
Dim Tgdertsamx#(2,4,4)
Return
Function MultiplyMatrixVector3(VecRes,VecSource,Matrix)
Tgdertsamx#(1,1,1)=x vector3(vecsource)
Tgdertsamx#(1,1,2)=y vector3(vecsource)
Tgdertsamx#(1,1,3)=z vector3(vecsource)
Tgdertsamx#(1,1,4)=1
x=1
for y=1 to 4
Tgdertsamx#(2,x,y)=((gdertsamx#(Matrix,1,y)*Tgdertsamx#(1,x,1)) + (gdertsamx#(Matrix,2,y)*Tgdertsamx#(1,x,2)) + (gdertsamx#(Matrix,3,y)*Tgdertsamx#(1,x,3)) + (gdertsamx#(Matrix,4,y)*Tgdertsamx#(1,x,4)))
next y
set vector3 vecres, tgdertsamx#(2,1,1), tgdertsamx#(2,1,2), tgdertsamx#(2,1,3)
Endfunction
Function MultiplyMatrix(mres,m1,m2)
for y=1 to 4
for x=1 to 4
Tgdertsamx#(2,x,y)=((gdertsamx#(m1,1,y)*gdertsamx#(m2,x,1)) + (gdertsamx#(m1,2,y)*gdertsamx#(m2,x,2)) + (gdertsamx#(m1,3,y)*gdertsamx#(m2,x,3)) + (gdertsamx#(m1,4,y)*gdertsamx#(m2,x,4)))
next x
next y
for y=1 to 4
for x=1 to 4
gdertsamx#(mres,x,y)=Tgdertsamx#(2,x,y)
next x
next y
Endfunction
Function MakeIdentityMatrix(Mnum)
gdertsamx#(mnum,1,1)=1
gdertsamx#(mnum,2,1)=0
gdertsamx#(mnum,3,1)=0
gdertsamx#(mnum,4,1)=0
gdertsamx#(mnum,1,2)=0
gdertsamx#(mnum,2,2)=1
gdertsamx#(mnum,3,2)=0
gdertsamx#(mnum,4,2)=0
gdertsamx#(mnum,1,3)=0
gdertsamx#(mnum,2,3)=0
gdertsamx#(mnum,3,3)=1
gdertsamx#(mnum,4,3)=0
gdertsamx#(mnum,1,4)=0
gdertsamx#(mnum,2,4)=0
gdertsamx#(mnum,3,4)=0
gdertsamx#(mnum,4,4)=1
Endfunction
Function MakeXRotationMatrix(Mnum,angle#)
gdertsamx#(mnum,1,1)=1
gdertsamx#(mnum,2,1)=0
gdertsamx#(mnum,3,1)=0
gdertsamx#(mnum,4,1)=0
gdertsamx#(mnum,1,2)=0
gdertsamx#(mnum,2,2)=cos(angle#)
gdertsamx#(mnum,3,2)=-sin(angle#)
gdertsamx#(mnum,4,2)=0
gdertsamx#(mnum,1,3)=0
gdertsamx#(mnum,2,3)=sin(angle#)
gdertsamx#(mnum,3,3)=cos(angle#)
gdertsamx#(mnum,4,3)=0
gdertsamx#(mnum,1,4)=0
gdertsamx#(mnum,2,4)=0
gdertsamx#(mnum,3,4)=0
gdertsamx#(mnum,4,4)=1
Endfunction
Function MakeYRotationMatrix(Mnum,angle#)
gdertsamx#(mnum,1,1)=cos(angle#)
gdertsamx#(mnum,2,1)=0
gdertsamx#(mnum,3,1)=sin(angle#)
gdertsamx#(mnum,4,1)=0
gdertsamx#(mnum,1,2)=0
gdertsamx#(mnum,2,2)=1
gdertsamx#(mnum,3,2)=0
gdertsamx#(mnum,4,2)=0
gdertsamx#(mnum,1,3)=-sin(angle#)
gdertsamx#(mnum,2,3)=0
gdertsamx#(mnum,3,3)=cos(angle#)
gdertsamx#(mnum,4,3)=0
gdertsamx#(mnum,1,4)=0
gdertsamx#(mnum,2,4)=0
gdertsamx#(mnum,3,4)=0
gdertsamx#(mnum,4,4)=1
Endfunction
Function MakeZRotationMatrix(Mnum,angle#)
gdertsamx#(mnum,1,1)=cos(angle#)
gdertsamx#(mnum,2,1)=-sin(angle#)
gdertsamx#(mnum,3,1)=0
gdertsamx#(mnum,4,1)=0
gdertsamx#(mnum,1,2)=sin(angle#)
gdertsamx#(mnum,2,2)=cos(angle#)
gdertsamx#(mnum,3,2)=0
gdertsamx#(mnum,4,2)=0
gdertsamx#(mnum,1,3)=0
gdertsamx#(mnum,2,3)=0
gdertsamx#(mnum,3,3)=1
gdertsamx#(mnum,4,3)=0
gdertsamx#(mnum,1,4)=0
gdertsamx#(mnum,2,4)=0
gdertsamx#(mnum,3,4)=0
gdertsamx#(mnum,4,4)=1
Endfunction
Function MakeTranslationMatrix(Mnum,X#,y#,z#)
gdertsamx#(mnum,1,1)=1
gdertsamx#(mnum,2,1)=0
gdertsamx#(mnum,3,1)=0
gdertsamx#(mnum,4,1)=x#
gdertsamx#(mnum,1,2)=0
gdertsamx#(mnum,2,2)=1
gdertsamx#(mnum,3,2)=0
gdertsamx#(mnum,4,2)=y#
gdertsamx#(mnum,1,3)=0
gdertsamx#(mnum,2,3)=0
gdertsamx#(mnum,3,3)=1
gdertsamx#(mnum,4,3)=z#
gdertsamx#(mnum,1,4)=0
gdertsamx#(mnum,2,4)=0
gdertsamx#(mnum,3,4)=0
gdertsamx#(mnum,4,4)=1
Endfunction
Function MakeScaleMatrix(Mnum,x#,y#,z#)
gdertsamx#(mnum,1,1)=x#
gdertsamx#(mnum,2,1)=0
gdertsamx#(mnum,3,1)=0
gdertsamx#(mnum,4,1)=0
gdertsamx#(mnum,1,2)=0
gdertsamx#(mnum,2,2)=y#
gdertsamx#(mnum,3,2)=0
gdertsamx#(mnum,4,2)=0
gdertsamx#(mnum,1,3)=0
gdertsamx#(mnum,2,3)=0
gdertsamx#(mnum,3,3)=z#
gdertsamx#(mnum,4,3)=0
gdertsamx#(mnum,1,4)=0
gdertsamx#(mnum,2,4)=0
gdertsamx#(mnum,3,4)=0
gdertsamx#(mnum,4,4)=1
Endfunction
And here are a list of functions (just the basics at the mo...if i make more I'll add them)
Gosub SetupMatrixSystem: This must be called at the begining of your program to initialise the arrays for use by the matrix functions.
MakeIdentityMatrix(Mnum): Sets the specified matrix to be an identity matrix.
MakeXRotationMatrix(Mnum,angle#): Sets the specified matrix to be a rotation matrix in the x axies for the specified number of degrees
MakeYRotationMatrix(Mnum,angle#): Sets the specified matrix to be a rotation matrix in the y axies for the specified number of degrees
MakeZRotationMatrix(Mnum,angle#): Sets the specified matrix to be a rotation matrix in the z axies for the specified number of degrees
MakeTranslationMatrix(Mnum,X#,y#,z#): Sets the specified matrix to be a translation matrix. It is set to translate the specified distance in the x,y and z axies.
MakeScaleMatrix(Mnum,x#,y#,z#): Sets the specified matrix to be a scale matrix. The scales are specified in the x,y and z axies.
MultiplyMatrix(mres,m1,m2): Multipies 2 matrices (m1 & m2) together and stores the result in matrix 'mres'
MultiplyMatrixVector3(VecRes,VecSource,Matrix): Multiplies the matrix 'matrix' with the vector 'vecsource' and stores the resultant vector in 'vecres'. This is basically the magic function that uses your matrix to transform a vector.
Ok without further adure....an example of a function to rotate a vector in all three axies.
Function RotateVector(VectorNum, x#, y#, z#)
`Ok so first we need a matrix to do the x rotating, this will`
`be matrix '1' and the angle is obviously x#
MakeXRotationMatrix(1,x#)
`next we need a matrix to do the y rotating, this will be matrix 2`
MakeYRotationMatrix(2,y#)
`finally we need a matrix to do the z rotating, this will be matrix 3`
MakeZRotationMatrix(3,z#)
`Ok it should be know that by multiplying two matrices together we `
`end up with one matrix that does the job of both. So lets multiply
`our matrices.`
MultiplyMatrix(1,1,2)
MultiplyMatrix(1,1,3)
`Ok so all our matrices are multiplied so now we have matrix '1' which
`holds the ability to translate a vector in all three axies in the
`values specified earlier. So now the magic bit
MultiplyMatrixVector3(VectorNum,VectorNum,1)
`This bit takes our vector, transforms it using matrix 1 and then puts
`the result back in our vector
`So thats it, our vector now has been rotated. And you can use this
`function wherever you like.`
Endfunction
So I hope this is helpful to someone. It's as usual free to use in any project though a little nod of the head in my direction in any credits wouldnt go a miss.
Goodnight then !
p.s. If someone would test that example function for me...this computer I am on cant compile...though I have tested the matrix functions it uses.
Thanks people
[EDIT]
Ahh booger....chances that this might not be working right folks...I'm having a play around with it now.
Sorry
[Edit]
Ok think it's fixed !
[Edit]
Being the fool I am I managed to not see that some of the matrices use -sin() instead of sin()....ah well...fixing now.
Anything else anyone spots please let me know !