entityx verses tformedx

Blitz3D Forums/Blitz3D Beginners Area/entityx verses tformedx

I have been using entity(entity,true) to get global coordinates. It seems like it works just fine to move explosions and other entities to the position of the entity, but when I look at those coordinates in the debugger and put them into my game, the coordinates seem to be completely wrong. Is there a reason for this?

Also, I was looking through the docs, and found the tform commands. Are these what I am wanting and for what purpose would entityx(entity,global) be used for?

If the entity your positioning had a parent, make sure you also use positionentity with the global value set. Post some code if that doesn't help.

No need for tformpoint here.

Stevie

I am sorry for making the question unclear. What I really want to know is when do you use tformed comands over entityx,y,z... comands? What is the difference between entityx(entity,true) and tformedx()?

If you want to transform between local and global coordinates, that is when you use it.

So if you want, for instance, to know where in the 'world' a point is that is say 1 unit to the left of an entity, relative to the entity's orientation, then you would use the tformed commands. In the example given you would do this:


TformPoint -1,0,0,My3DModelWhichCouldBeFacingAnyDirection,0

Xpos#=TformedX() ;the x coordinate in the world of a point which lies 1 unit to the left of the 3d model listed above
YPos#=Tformedy() ;the y coordinate in the world of a point which lies 1 unit to the left of the 3d model listed above
zPos#=TformedZ() ;the z coordinate in the world of a point which lies 1 unit to the left of the 3d model listed above



perhaps a few more examples could be given such as:

Let us say you wanted to know if a particular entity "EntityA" is in front of another entity "EntityB" then to do this you would simply do this:

XPositionOfEntityARelativeToEntityB#=EntityX(EntityA,true)-EntityX(EntityB,true)
YPositionOfEntityARelativeToEntityB#=EntityY(EntityA,true)-EntityY(EntityB,true)
ZPositionOfEntityARelativeToEntityB#=EntityZ(EntityA,true)-EntityZ(EntityB,true)

;then we use tformvector or tformnormal to transform this vector from 'world space' to 'local space' of EntityB

TformNormal XPositionOfEntityARelativeToEntityB#,YPositionOfEntityARelativeToEntityB#,ZPositionOfEntityARelativeToEntityB#,0,EntityB

If TFormedZ()>0.0 then 
;Entity A must be in front of Entity B


endif 
If TFormedZ()<0.0 then
;EntityA must be behind Entity B
endif 
If TFormedX()<0.0 then 
;Entity A must be to the left of Entity B
endif 
If TFormedX()>0.0 then 
;Entity A must be to the right of Entity B
endif 
;Same logic applies to TFormedY() ie if TFormedY()>0.0 then Entity A must be above Entity B, although the actual value of TFormedX,Y,Z() will tell you just how much to the front/left/up/down/right/back the entity is.


I think the main usage of tformpoint commands, is to get vertex positions.

Thanks, especially Matty, for all the help. That cleared it up for me.