TForm Functions

Blitz3D Forums/Blitz3D Programming/TForm Functions

Zach3D(Posted 2007) [#1]
What exactly do the TForm Functions do? (TFormPoint,TFormVector,TFormNormal ect.)

The blitz manual says "transforms between coordinate systems" But That doesn't explain it to me, what does it do and what is the use?


b32(Posted 2007) [#2]
When a mesh is loaded in b3d, it consists of vertices. These vertices have a (x,y,z) coordinate.
To save memory, one mesh can be used for several entities. An entity takes the original mesh data and transforms it using a transformation matrix.
This matrix is scaled, rotated and moved using the entity commands, such as PositionEntity, ScaleEntity and RotateEntity.
This means the actual data is not altered, but projected differently when RenderWorld() is called.
So with one mesh, you can make multiple entities.

The TForm commands allow you to do the same with a point. You can rotate, scale and move the point along with an entity.
Say we have a cube:
cube = CreateCube()

If you now use TFormPoint to convert the point (0, 0, 1) from the cube to the world (=zero), it will stay the same:
TFormPoint 0, 0, 1, cube, 0
print TFormedX()
print TFormedY()
print TFormedZ()
--> result = (0,0,1) .. nothing happened

However, if you rotate the cube:
RotateEntity cube, 0, 90, 0
and call TFormPoint again
print TFormedX()
print TFormedY()
print TFormedZ()
--> result = (-1,0,0) .. rotated 90 degrees
The point will be rotated 90 degrees over the y-axis, just as the cube is.

The main use for this, is when you read the vertex coordinates with VerteX() VertexY() and VertexZ()
They will return the original mesh data, so no matter if you Rotate/Scale and Move the entity, they will keep returning the same values.
With TFormPoint you can calculate where the vertices are in 'world-space coordinates'.
But it can also help determining where a certain 3d point on an object is, in relation to another object, such as a camera.

The syntax of TFormPoint is
TFormPoint x, y, z, from, to
Where 'from' and 'to' can be entities, but they can also be zero. When a zero is entered, that means global or world-space coordinates.

I think the TFormPoint commands are very handy. Especially because my maths are not too good. I wouldn't like to rotate points myself.


_PJ_(Posted 2007) [#3]
Thanks, that really clears a lot up.

This has inspired some thoughts on more detailed colision testing.

Would this be fast enough to use in such a way? Of course, dependant on how many points of how many entities/meshes


SoggyP(Posted 2007) [#4]
Hello.

That's a good explanation that I can understand - are you sure it's correct?

:o)

Goodbye.


Stevie G(Posted 2007) [#5]

They will return the original mesh data, so no matter if you Rotate/Scale and Move the entity, they will keep returning the same values



Not strictly true. If you use Scaleentity the transformations will be scaled accordingly.

The tform commands are probably the most useful in the whole blitz command set imo so you should take the time to get used to them.

There are far more and better uses for these commands though. One thing I use them for is in simulating friction relative to a tire which is attached to a vehicle for example, the direction the tire is pointing and it's velocity vector are generally going to differ/

What the following does is convert a global velocity vector into the tire entities local coordinate space. From there you can simulate a different friction on each axis, relative to the direction/rotation of the tire. As you can see I reduce the speed by half in the direction perpendicular to the tire direction but not so much for the velocity component facing forward relative to the tire rotation. The next step is to convert the resulting velocity vector back into world/global coords.

TFormVector p\Velocity\x, p\Velocity\y , p\Velocity\z , 0 , TIRE
p\Velocity\x = TFormedX() * .5
p\Velocity\y = TFormedY() 
p\Velocity\z = TFormedZ() * .99
TFormVector p\Velocity\x , p\Velocity\y , p\Velocity\z , TIRE , 0	



Ross C(Posted 2007) [#6]
I'm using the tform commands for a couple of things. I use them with linepick, to make sure the line is picked downwards from the bottom of the entity, but, in the direction of the entities Y axis.

I'm also using it so my entities in my editor, move in the direction of the mouse. Super useful, as Stevie says, well worth getting to know them :o)


Gabriel(Posted 2007) [#7]
Take it from someone who just spent best part of a week figuring out how to write his own TFormVector TFormPoint and TFormNormal using quaternion math and no helper functions, these three functions are an absolute lifesaver.

When you see people saying "I don't care if X has shaders and all that cool stuff, I'm sticking with B3D." it's because of functions like this which make your life so much easier.

I like Ross's example, because I've always used TFormVector for that too. When you want your objects to be moved with the mouse but have a completely free camera, being able to convert a vector from camera space into world space so that you can transform the entity by it is just great.