; TFormedZ Example ; ---------------- ; The TForm commands (TFormPoint, TFormVector, TFormNormal) store ; their result internally; TFormedZ reads back the z component. ; Here TFormPoint tracks the muzzle tip of a spinning turret, and ; TFormedZ supplies the marker's world z coordinate. 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 ; Transform the local muzzle point (0,0,1.5) into world space TFormPoint 0,0,1.5,turret,0 ; Read back the result - TFormedZ is the documented command z#=TFormedZ() PositionEntity marker,TFormedX(),TFormedY(),z ; 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,"TFormedZ() = "+z Text 0,40,"The marker's world z swings as the turret spins" Flip Wend End