I believe this was what you wanted to achieve:
LOCAL local_r as DWORD
GLOBAL global_Obj as DWORD
GLOBAL global_Obj2 as DWORD
GLOBAL global_Limb1 as DWORD
GLOBAL Global_Mesh as DWORD
#constant DEG2RAD 3.1415926535 / 180.0
LOCAL local_x as float
set display mode 800,600,32,1
sync on
sync rate 60
autocam off
#constant WorldMatrix 1
#constant ViewMatrix 2
#constant ProjectionMatrix 3
#constant PosMatrix 4
#constant RotMatrix 5
#constant ResMatrix 6
#constant ObjectVector 7
#constant COLOR_BACKGROUND RGB(32,32,32)
local_r=make matrix4(WorldMatrix)
local_r=make matrix4(ViewMatrix)
local_r=make matrix4(ProjectionMatrix)
local_r=make matrix4(PosMatrix)
local_r=make matrix4(RotMatrix)
local_r=make matrix4(ResMatrix)
local_r=make vector4(ObjectVector)
color backdrop 0, COLOR_BACKGROUND
position camera 0, 0.0,30, -40.0
point camera 0, 0.0, 0.0, 0.0
global_Obj = 1
make object cube global_Obj,1
global_Obj2 = 2
make object sphere global_Obj2,2
Global_Mesh = 1
MAKE MESH FROM OBJECT Global_Mesh, global_Obj
global_Limb1 = 1
ADD LIMB global_Obj,global_Limb1,Global_Mesh
OFFSET LIMB global_Obj, global_Limb1, 5, 0, 0
position object global_Obj,-30,1,1
do
xTest()
local_x=local_x+0.1
if local_x>29 then local_x=-30
position object global_Obj,local_x,1,1
rotate object global_Obj,0,wrapvalue(object angle y(global_Obj)+1),0
while keystate(57)=1: endwhile
sync
loop
end
Function xTest()
LOCAL local_newmatrix as DWORD
LOCAL local_txty as DWORD
LOCAL l_m0 as FLOAT
LOCAL l_m1 as FLOAT
LOCAL l_m2 as FLOAT
LOCAL l_m3 as FLOAT
LOCAL l_m4 as FLOAT
LOCAL l_m5 as FLOAT
LOCAL l_m6 as FLOAT
LOCAL l_m7 as FLOAT
LOCAL l_m8 as FLOAT
LOCAL l_m9 as FLOAT
LOCAL l_m10 as FLOAT
LOCAL l_m11 as FLOAT
LOCAL l_m12 as FLOAT
LOCAL l_m13 as FLOAT
LOCAL l_m14 as FLOAT
LOCAL l_m15 as FLOAT
LOCAL local_r as DWORD
LOCAL local_x as FLOAT
LOCAL local_y as FLOAT
LOCAL local_z as FLOAT
LOCAL local_rx as FLOAT
LOCAL local_ry as FLOAT
LOCAL local_rz as FLOAT
LOCAL local_limbx as FLOAT
LOCAL local_limby as FLOAT
LOCAL local_limbz as FLOAT
local_x = OBJECT POSITION X(global_Obj)
local_y = OBJECT POSITION Y(global_Obj)
local_z = OBJECT POSITION Z(global_Obj)
local_rx = OBJECT ANGLE X(global_Obj)
local_ry = OBJECT ANGLE Y(global_Obj)
local_rz = OBJECT ANGLE Z(global_Obj)
ROTATE YPR MATRIX4 RotMatrix, local_ry * DEG2RAD,local_rx * DEG2RAD,local_rz * DEG2RAD
TRANSLATE MATRIX4 PosMatrix, local_x,local_y,local_z
Multiply Matrix4 ResMatrix, RotMatrix, PosMatrix
WORLD MATRIX4 WorldMatrix
`local_r = INVERSE MATRIX4(ResMatrix, ResMatrix)
MULTIPLY MATRIX4 ResMatrix, WorldMatrix, ResMatrix
l_m0 = GET MATRIX4 ELEMENT(ResMatrix, 0)
l_m1 = GET MATRIX4 ELEMENT(ResMatrix, 1)
l_m2 = GET MATRIX4 ELEMENT(ResMatrix, 2)
l_m3 = GET MATRIX4 ELEMENT(ResMatrix, 3)
l_m4 = GET MATRIX4 ELEMENT(ResMatrix, 4)
l_m5 = GET MATRIX4 ELEMENT(ResMatrix, 5)
l_m6 = GET MATRIX4 ELEMENT(ResMatrix, 6)
l_m7 = GET MATRIX4 ELEMENT(ResMatrix, 7)
l_m8 = GET MATRIX4 ELEMENT(ResMatrix, 8)
l_m9 = GET MATRIX4 ELEMENT(ResMatrix, 9)
l_m10 = GET MATRIX4 ELEMENT(ResMatrix, 10)
l_m11 = GET MATRIX4 ELEMENT(ResMatrix, 11)
l_m12 = GET MATRIX4 ELEMENT(ResMatrix, 12)
l_m13 = GET MATRIX4 ELEMENT(ResMatrix, 13)
l_m14 = GET MATRIX4 ELEMENT(ResMatrix, 14)
l_m15 = GET MATRIX4 ELEMENT(ResMatrix, 15)
`Set the vector to limb position
set vector4 ObjectVector, 5.0, 0.0, 0.0, 1.0
`Multiply it with ResMatrix
transform vector4 ObjectVector, ObjectVector, ResMatrix
position object global_Obj2, x vector4(ObjectVector), y vector4(ObjectVector), z vector4(ObjectVector)
`position object global_Obj2, limb position x(global_Obj, global_Limb1), limb position y(global_Obj, global_Limb1), limb position z(global_Obj, global_Limb1)
local_txty=20
text 10,local_txty,"m0:"+str$(l_m0) : inc local_txty,20
text 10,local_txty,"m1:"+str$(l_m1) : inc local_txty,20
text 10,local_txty,"m2:"+str$(l_m2) : inc local_txty,20
text 10,local_txty,"m3:"+str$(l_m3) : inc local_txty,40
text 10,local_txty,"m4:"+str$(l_m4) : inc local_txty,20
text 10,local_txty,"m5:"+str$(l_m5) : inc local_txty,20
text 10,local_txty,"m6:"+str$(l_m6) : inc local_txty,20
text 10,local_txty,"m7:"+str$(l_m7) : inc local_txty,40
text 10,local_txty,"m8:"+str$(l_m8) : inc local_txty,20
text 10,local_txty,"m9:"+str$(l_m9) : inc local_txty,20
text 10,local_txty,"m10:"+str$(l_m10) : inc local_txty,20
text 10,local_txty,"m11:"+str$(l_m11) : inc local_txty,40
text 10,local_txty,"m12:"+str$(l_m12) : inc local_txty,20
text 10,local_txty,"m13:"+str$(l_m13) : inc local_txty,20
text 10,local_txty,"m14:"+str$(l_m14) : inc local_txty,20
text 10,local_txty,"m15:"+str$(l_m15) : inc local_txty,20
inc local_txty,20
text 10,local_txty,"x:"+str$(local_x)+",y:"+str$(local_y)+",z:"+str$(local_z) : inc local_txty,20
text 10,local_txty,"rx:"+str$(local_rx)+",ry:"+str$(local_ry)+",rz:"+str$(local_rz) : inc local_txty,20
EndFunction
The commands I added are written in lowercase.
There were 3 problems in your code:
- You were translating your matrix with the limb offset. But, the limb offset is actually a vector that rotates along with the object, and so it should be used in the vector that you want to transform.
- There was no need to use the inverse of the matrix4. I don't know where you got this, but using these matrices usually means rotation of vectors (eg you say 'rotate 30°', then it will rotate 30° and not -30° which is the case when changing coordinate system). Besides, the inverse of a rotation matrix is a rotation matrix, but using its negative angle, and the inverse of a translation matrix is a translation matrix over its negative translation vector.
- You weren't using any vectors that eventually would hold the object position
You basically set a vector to the offset you want to have (in this example you picked the offset (5.0, 0.0, 0.0, 1.0) which you can see as the local position vector of the limb. Then you transform that vector using the matrix you built. In your example that matrix4 will rotate the vector YPR and then translate it over the object's position.
Cheers!
Sven