TFormPoint x#,y#,z#,source_entity,dest_entity
Parameters
|
x# - x coordinate of the point y# - y coordinate of the point z# - z coordinate of the point source_entity - entity whose space the point is given in, or 0 for world space dest_entity - entity whose space to convert the point into, or 0 for world space |
Description
|
Converts a position from one entity's coordinate space to another's. Every entity has its own local space, with its pivot at 0,0,0. TFormPoint takes a point given relative to source_entity and works out where that same point is relative to dest_entity, applying position, rotation and scale along the way. Use 0 for either entity to mean plain world space. The result is read afterwards with TFormedX, TFormedY and TFormedZ. Think of a sphere: its north pole is always at 0,1,0 in its own space, wherever the sphere has been moved, turned or scaled. TFormPoint 0,1,0,sphere,0 tells you where the pole currently sits in the world - perfect for spawning a shot at a gun muzzle, or finding where a mesh vertex (which VertexX and friends report in mesh space) really is. For directions rather than positions, use TFormVector (unaffected by position) or TFormNormal (also normalised). See also: TFormedX, TFormedY, TFormedZ, TFormVector, TFormNormal, EntityX. |
Example
; TFormPoint Example ; ------------------ ; TFormPoint converts a position from one entity's coordinate space ; to another's (use 0 for world space). The muzzle tip of a spinning ; turret is a fixed LOCAL point (0,0,1.5); TFormPoint maps it into ; world space so a marker sphere can track it as the turret turns. Graphics3D 640,480 SetBuffer BackBuffer() camera=CreateCamera() PositionEntity camera,0,3,-6 RotateEntity camera,20,0,0 light=CreateLight() RotateEntity light,30,40,0 ; A base and a long turret barrel on top of it base=CreateCylinder() ScaleEntity base,1,0.4,1 EntityColor base,110,110,130 turret=CreateCube() ScaleMesh turret,0.25,0.25,1.5 ; barrel runs from local z -1.5 to 1.5 PositionEntity turret,0,1,0 EntityColor turret,90,180,90 ; The marker lives in WORLD space and follows the muzzle tip marker=CreateSphere() ScaleEntity marker,0.15,0.15,0.15 EntityColor marker,255,255,0 EntityFX marker,1 While Not KeyDown(1) TurnEntity turret,0,1.5,0 ; The documented command: local muzzle point -> world coordinates TFormPoint 0,0,1.5,turret,0 PositionEntity marker,TFormedX(),TFormedY(),TFormedZ() ; Arrow keys move the camera If KeyDown(200) Then MoveEntity camera,0,0,0.1 If KeyDown(208) Then MoveEntity camera,0,0,-0.1 If KeyDown(203) Then TurnEntity camera,0,1,0 If KeyDown(205) Then TurnEntity camera,0,-1,0 RenderWorld Text 0,0,"Arrow keys: move camera Esc: exit" Text 0,20,"TFormPoint 0,0,1.5,turret,0 (muzzle tip into world space)" Text 0,40,"World position: "+TFormedX()+", "+TFormedY()+", "+TFormedZ() Flip Wend End
Index