One issue (there's more than one, believe me) with the vector/matrix commands in DBP is there missing loads. I ended up having to make my own set of Vector2d/3d/4d, Matrix2x2/3x3/4x4 and Quaternion classes. I remember I converted a move camera snippet by darkcoder:
gosub declareMath
sync on : sync rate 75
make object cube 2,0.5
offset limb 2,0,0.0,0.0,1.0
set object diffuse 2, 0xFFFF0000
make object cube 1,10.0
scale object 1,10.0,10.0,10.0
m4_1 as Matrix4x4
m4_2 as Matrix4x4
m4_3 as Matrix4x4
m4_4 as Matrix4x4
v3_1 as Vector3d //lX
v3_2 as Vector3d //lY
v3_3 as Vector3d //lZ
v3_4 as Vector3d //lZ
while not false
rX# = object angle x(1)
rY# = object angle y(1)
rZ# = object angle z(1)
Vector3( 1.0, 0.0, 0.0 ) : v3_1 = tVector3
Matrix4_BuildRotation( v3_1, rX# ) : m4_1 = tMatrix4x4
Vector3( 0.0, 1.0, 0.0 ) : v3_1 = tVector3
Matrix4_BuildRotation( v3_1, rY# ) : m4_2 = tMatrix4x4
Vector3( 0.0, 0.0, 1.0 ) : v3_1 = tVector3
Matrix4_BuildRotation( v3_1, rZ# ) : m4_3 = tMatrix4x4
Matrix4_Multiply( m4_2, m4_1 ) : m4_4 = tMatrix4x4
Matrix4_Multiply( m4_3, m4_4 ) : m4_4 = tMatrix4x4
Vector3( 1.0, 0.0, 0.0 ) : v3_1 = tVector3
Matrix4_TransformVector( v3_1, m4_4 ) : v3_1 = tVector3
Vector3( 0.0, 1.0, 0.0 ) : v3_2 = tVector3
Matrix4_TransformVector( v3_2, m4_4 ) : v3_2 = tVector3
Vector3( 0.0, 0.0, 1.0 ) : v3_3 = tVector3
Matrix4_TransformVector( v3_3, m4_4 ) : v3_3 = tVector3
movementX# = ( RightKey() - LeftKey() ) * 0.1
movementY# = ( ShiftKey() - ControlKey() ) * 0.1
movementZ# = ( UpKey() - DownKey() ) * 0.1
x# = Object Position X( 1 ) + v3_1.x * movementX#
y# = Object Position Y( 1 ) + v3_1.y * movementX#
z# = Object Position Z( 1 ) + v3_1.z * movementX#
x# = x# + v3_2.x * movementY#
y# = y# + v3_2.y * movementY#
z# = z# + v3_2.z * movementY#
x# = x# + v3_3.x * movementZ#
y# = y# + v3_3.y * movementZ#
z# = z# + v3_3.z * movementZ#
Position Object 1, x#, y#, z#
// Position and orient marker to the main object
Position Object 2, x#, y#, z#
Rotate Object 2, rX#, rY#, rZ#
if SpaceKey()
Rotate object 1, rnd(360), rnd(360), rnd(360)
Position Object 1, 0.0, 0.0, 0.0
endif
set cursor 0,0
element=0
for y=0 to 3
for x=0 to 3
print str$(Matrix4_GetElement( m4_4,element));" ";
inc element
next x
print
next y
print
print "Press Space to reset position/rotation"
print "Directional Keys to move"
sync
endwhile
declareMath:
global tVector3 as Vector3d // temp passing Vector3d
global tMatrix4x4 as Matrix4x4 // temp passing Matrix4x4
return
type Vector3d
x as float
y as float
z as float
endtype
function Vector3( x as float, y as float, z as float )
tVector3.x = x : tVector3.y = y : tVector3.z = z
endfunction
type Matrix4x4
e00 as float
e01 as float
e02 as float
e03 as float
e10 as float
e11 as float
e12 as float
e13 as float
e20 as float
e21 as float
e22 as float
e23 as float
e30 as float
e31 as float
e32 as float
e33 as float
identity as boolean
endtype
function Matrix4_Multiply( m1 as Matrix4x4, m2 as Matrix4x4 )
tMatrix4x4.e00 = m1.e00*m2.e00 + m1.e01*m2.e10 + m1.e02*m2.e20 + m1.e03*m2.e30
tMatrix4x4.e01 = m1.e00*m2.e01 + m1.e01*m2.e11 + m1.e02*m2.e21 + m1.e03*m2.e31
tMatrix4x4.e02 = m1.e00*m2.e02 + m1.e01*m2.e12 + m1.e02*m2.e22 + m1.e03*m2.e32
tMatrix4x4.e03 = m1.e00*m2.e03 + m1.e01*m2.e13 + m1.e02*m2.e23 + m1.e03*m2.e33
tMatrix4x4.e10 = m1.e10*m2.e00 + m1.e11*m2.e10 + m1.e12*m2.e20 + m1.e13*m2.e30
tMatrix4x4.e11 = m1.e10*m2.e01 + m1.e11*m2.e11 + m1.e12*m2.e21 + m1.e13*m2.e31
tMatrix4x4.e12 = m1.e10*m2.e02 + m1.e11*m2.e12 + m1.e12*m2.e22 + m1.e13*m2.e32
tMatrix4x4.e13 = m1.e10*m2.e03 + m1.e11*m2.e13 + m1.e12*m2.e23 + m1.e13*m2.e33
tMatrix4x4.e20 = m1.e20*m2.e00 + m1.e21*m2.e10 + m1.e22*m2.e20 + m1.e23*m2.e30
tMatrix4x4.e21 = m1.e20*m2.e01 + m1.e21*m2.e11 + m1.e22*m2.e21 + m1.e23*m2.e31
tMatrix4x4.e22 = m1.e20*m2.e02 + m1.e21*m2.e12 + m1.e22*m2.e22 + m1.e23*m2.e32
tMatrix4x4.e23 = m1.e20*m2.e03 + m1.e21*m2.e13 + m1.e22*m2.e23 + m1.e23*m2.e33
tMatrix4x4.e30 = m1.e30*m2.e00 + m1.e31*m2.e10 + m1.e32*m2.e20 + m1.e33*m2.e30
tMatrix4x4.e31 = m1.e30*m2.e01 + m1.e31*m2.e11 + m1.e32*m2.e21 + m1.e33*m2.e31
tMatrix4x4.e32 = m1.e30*m2.e02 + m1.e31*m2.e12 + m1.e32*m2.e22 + m1.e33*m2.e32
tMatrix4x4.e33 = m1.e30*m2.e03 + m1.e31*m2.e13 + m1.e32*m2.e23 + m1.e33*m2.e33
endfunction
function Matrix4_BuildRotation( v as Vector3d, angle as float )
local sintheta as float
local costheta as float
local tcostheta as float
local x as float
local y as float
local z as float
sintheta = sin(angle)
costheta = cos(angle)
tcostheta = (1-costheta)
x = v.x
y = v.y
z = v.z
tMatrix4x4.e00 = x*x+costheta*(1-x*x)
tMatrix4x4.e01 = x*y*tcostheta-z*sintheta
tMatrix4x4.e02 = z*x*tcostheta+y*sintheta
tMatrix4x4.e03 = 0.0
tMatrix4x4.e10 = x*y*tcostheta+z*sintheta
tMatrix4x4.e11 = y*y+costheta*(1-y*y)
tMatrix4x4.e12 = y*z*tcostheta-x*sintheta
tMatrix4x4.e13 = 0.0
tMatrix4x4.e20 = z*x*tcostheta-y*sintheta
tMatrix4x4.e21 = y*z*tcostheta+x*sintheta
tMatrix4x4.e22 = z*z+costheta*(1-z*z)
tMatrix4x4.e23 = 0.0
tMatrix4x4.e30 = 0.0
tMatrix4x4.e31 = 0.0
tMatrix4x4.e32 = 0.0
tMatrix4x4.e33 = 1.0
endfunction
function Matrix4_TransformVector( v as Vector3d, m as Matrix4x4 )
local x as float
local y as float
local z as float
x = m.e00*v.x + m.e01*v.y + m.e02*v.z
y = m.e10*v.x + m.e11*v.y + m.e12*v.z
z = m.e20*v.x + m.e21*v.y + m.e22*v.z
Vector3( x, y, z )
endfunction
function Matrix4_GetElement( m as Matrix4x4, e as integer )
local out as float
select e
case 0 : out = m.e00 : endcase
case 1 : out = m.e01 : endcase
case 2 : out = m.e02 : endcase
case 3 : out = m.e03 : endcase
case 4 : out = m.e10 : endcase
case 5 : out = m.e11 : endcase
case 6 : out = m.e12 : endcase
case 7 : out = m.e13 : endcase
case 8 : out = m.e20 : endcase
case 9 : out = m.e21 : endcase
case 10 : out = m.e22 : endcase
case 11 : out = m.e23 : endcase
case 12 : out = m.e30 : endcase
case 13 : out = m.e31 : endcase
case 14 : out = m.e32 : endcase
case 15 : out = m.e33 : endcase
endselect
endfunction out
A dream is a fantasy, if you achieve that fantasy it was never a dream to begin with.