tform vector

Blitz3D Forums/Blitz3D Programming/tform vector

slenkar(Posted 2004) [#1]
what does tform mean and what do all the tform commands do?>


jhocking(Posted 2004) [#2]
"tform" is short for "transform." The TForm commands are used to transform/convert coordinates and vectors between coordinate systems. For example, you can use TForm commands to get the global coordinates of a point defined in the local coordinate space of a parent entity.

These commands are very useful for handling a lot of 3D math. For example, I use TFormVector so that characters will strafe correctly regardless of which way the camera is facing. That is, I get the global vector which corresponds to the left vector (or whichever) defined in the camera's local coordinates.


Tom(Posted 2004) [#3]
Hi Slenkar,

Let me have a go at explaining :)

Imagine standing in the middle of a room, the room is your 'world space', facing north (Z+). Let's say your right shoulder is exactly in the center of the room (x=0,y=0,z=0)

Hold out your right arm and point it directly forward. For arguments sake let's say your arm is 1meter or 1blitz unit long.

Your hand is now at position 0,0,1 in world/room space, and also in 'local/object space' (think 'relative to shoulder' space)

With me so far? :)

Ok, you then take 1 step to the right, 2 steps forward, then turn right 45 degrees.

In local 'shoulder' space, your hand is still at position 0,0,1

To find your hands position in world/room space we use the TFormPoint command:

; shoulderSpace is the entity the coordinates 0,0,1 are relative to

TFormPoint 0,0,1,shoulderSpace,0 ; 0=world space (room space to us)

Now TFormedX(), TFormedY() and TFormedZ() contain the world/global or 'room' position of your hand.

For vectors the principal is the same:

TFormVector transforms a vector from 1 objects coordinate system, to another

TFormNormal does the same thing as TFormVector, except after conversion it Normalizes the result, i.e. it manipulates the final vector so it has a unit length of 1.0

A vector is a Unit vector if sqr(x*x + y*y + z*z) = 1.0

Hope I made some sense! :)
Tom


slenkar(Posted 2004) [#4]
I think I get it, but cant I just use entity z(hand,1) ??

the 1 flag makes it global instead of local.

why would you use tform instead of entityy entityz..


jhocking(Posted 2004) [#5]
Because not everything is an entity. Obviously the EntityX etc. commands only work on entities. What if you want to transform the coordinates of a vertex from local to global space? What about a vector?


slenkar(Posted 2004) [#6]
ah ok thanks, sounds useful


CyberHeater(Posted 2004) [#7]
Mark should add some of those explanations to the book. Great. I know understand it.