Tforming Rotation?

Blitz3D Forums/Blitz3D Programming/Tforming Rotation?

Hey guys,

I have a program that needs a math function that can convert an entity's local orientation to that of the world. I know I can use tform to tranform positions just fine, but what about rotations. I'm converting this to the ODE lib, which doesn't seem to understand rotating things(applying force) locally, so I can't really use built in functions to do this.

This should work ...

Stevie


global Gpivot=createpivot()
global Groll#, Gpitch#, Gyaw#

function Gorientation( Entity )

   tformvector 1,0,0,Entity, 0
   aligntovector Gpivot, tformedx(), tformedy(), tformedz(), 1

   tformvector 0,0,1,Entity, 0
   aligntovector Gpivot, tformedx(), tformedy(), tformedz(), 3

    Groll = entityroll( Gpivot )
    Gpitch = entitypitch( Gpivot )
    Gyaw = entityyaw( Gpivot )

end function



Stevie, don't you just call EntityPitch() ..Yaw & ..Roll with the Global flag set to True?
worldPitch# = EntityPitch(entity,True)
worldYaw# = EntityYaw(entity,True)
worldRoll# = EntityRoll(entity,True)


If the entity isn't parented, then it's local & world orientation is the same, i.e, EntityPitch(entity) will return the same as EntityPitch(entity,True)



To expand on this...

If the program required a Matrix, you could use GetMatElement(entity,row,column) to build a matrix that you can pass directly as a pointer to many DLLs/Math libs and even DirectX.

This function always returns the x, y & z axis vectors & position in 'world' space.

So to get the X axis vector in world space, you could do:
TFormVector 1,0,0,ent,0
xAxis\x# = TFormedX()
xAxis\y# = TFormedY()
xAxis\z# = TFormedZ()


or, much easier..
xAxis\x# = GetMatElement(ent,0,0)
xAxis\y# = GetMatElement(ent,0,1)
xAxis\z# = GetMatElement(ent,0,2)

yAxis\x# = GetMatElement(ent,1,0)
yAxis\y# = GetMatElement(ent,1,1)
yAxis\z# = GetMatElement(ent,1,2)

zAxis\x# = GetMatElement(ent,2,0)
zAxis\y# = GetMatElement(ent,2,1)
zAxis\z# = GetMatElement(ent,2,2)

position\x# = GetMatElement(ent,3,0)
position\y# = GetMatElement(ent,3,1)
position\z# = GetMatElement(ent,3,2)


Many programs use a Matrix class that is just a float array#[16] or 16 float fields, like DirectX. This is useful as you can just pass a B3D type instance pointer as a valid Matrix class pointer.


Type Mat4
 Field m00#,m01#,m02#,m03# ;X axis
 Field m10#,m11#,m12#,m13# ;Y axis
 Field m20#,m21#,m22#,m23# ;Z axis
 Field m30#,m31#,m32#,m33# ;Position
End Type


A simple function to get the 'world' matrix for an entity:

Function GetEntityMatrix(ent,m.mat4)
 ;Entitys world X axis vector
 m\m00 = GetMatElement(ent,0,0)
 m\m01 = GetMatElement(ent,0,1)
 m\m02 = GetMatElement(ent,0,2)
 m\m03 = 0

 ;Y..
 m\m10 = GetMatElement(ent,1,0)
 m\m11 = GetMatElement(ent,1,1)
 m\m12 = GetMatElement(ent,1,2)
 m\m13 = 0
 
 ;Z..
 m\m20 = GetMatElement(ent,2,0)
 m\m21 = GetMatElement(ent,2,1)
 m\m22 = GetMatElement(ent,2,2)
 m\m23 = 0

 ;World Position
 m\m30 = GetMatElement(ent,3,0)
 m\m31 = GetMatElement(ent,3,1)
 m\m32 = GetMatElement(ent,3,2)
 m\m33 = 1
End Function


Depending on if the DLL/lib you're working with accepts a matrix class, just pass a mat4 type instance pointer:
Local m.mat4 = new mat4
entity = CreateCube()

GetEntityMatrix entity,m

myDxFunctionSetMatrix m


I've used this method with DirectX and it works perfectly!


Tom

Please never delete this post! This is wicked useful! Thanks for asking the question and thanks for the replies.

Stevie, don't you just call EntityPitch() ..Yaw & ..Roll with the Global flag set to True?



... I'll get my coat ;)