You can recreate the matrix by doing the same thing DBP does for you:
If an object is rotated in the XYZ order, then you:
- rotate X
- rotate Y
- rotate Z
- translate X,Y,Z (T)
so mat = X * Y * Z * T
Like so:
sync on
sync rate 100
#constant TO_RAD 3.141592654 / 180.0
`Matrices and vectors
r = make matrix4(1)
r = make matrix4(2) : `Temp
r = make vector4(3) : `Temp
`Create objects for visual
make object cube 1, 2
make object cube 2, 0.5
hide object 2
`Set camera
position camera 20, 20, -20
point camera 0, 0, 0
ink rgb(0, 255, 0), 0
do
position object 1, object position x(1) + (rightkey() - leftkey()) * 0.1, 0.0, object position z(1) + (upkey() - downkey()) * 0.1
rotate object 1, wrapvalue(object angle x(1) + shiftkey() - controlkey()), 0.0, wrapvalue(object angle z(1) + spacekey() - returnkey())
GetMatrix4(1)
DrawTransformCoord(2, 1.0, 1.0, 1.0)
DrawTransformCoord(2, -1.0, 1.0, 1.0)
DrawTransformCoord(2, 1.0, 1.0, -1.0)
DrawTransformCoord(2, -1.0, 1.0, -1.0)
DrawTransformCoord(2, 1.0, -1.0, 1.0)
DrawTransformCoord(2, -1.0, -1.0, 1.0)
DrawTransformCoord(2, 1.0, -1.0, -1.0)
DrawTransformCoord(2, -1.0, -1.0, -1.0)
sync
loop
function GetMatrix4(obj)
translate matrix4 1, object position x(obj), object position y(obj), object position z(obj)
rotate z matrix4 2, object angle z(obj) * TO_RAD
multiply matrix4 1, 2, 1
rotate y matrix4 2, object angle y(obj) * TO_RAD
multiply matrix4 1, 2, 1
rotate x matrix4 2, object angle x(obj) * TO_RAD
multiply matrix4 1, 2, 1
endfunction
function DrawTransformCoord(obj, x#, y#, z#)
set vector4 3, x#, y#, z#, 1.0
transform vector4 3, 3, 1
w# = w vector4(3)
`Show on screen
position object obj, x vector4(3) / w#, y vector4(3) / w#, z vector4(3) / w#
box object screen x(obj) - 2, object screen y(obj) - 2, object screen x(obj) + 2, object screen y(obj) + 2
endfunction
Using the function GetMatrix4(obj), you can obtain the world matrix of that object.
[edit] I forgot the scaling in there, but I don't think it should be that much of a problem. You have to multiply by the scaling matrix:
mat = S * X * Y * Z * T, where S is built using
scale matrix4.
Cheers!
Sven B