Blitz3D+ Command Reference

EntityX# ( entity[,global] )

Parameters

entity - entity handle

global (optional) - true to return the world x coordinate, false to return the coordinate relative to the entity's parent; false (default)

Description

Returns the x coordinate of an entity.

With global false (the default) the coordinate is in the entity's parent's local space. If the entity has no parent, local and global coordinates are the same - you can think of the 3D world as the parent.

Global coordinates refer to the 3D world. Blitz3D uses a left-handed system:

X+ is to the right
Y+ is up
Z+ is forward (into the screen)

Every entity also has its own local coordinate system. The global system never changes, but the local system is carried along as an entity moves and turns. This is the same idea used by the movement commands: MoveEntity entity,0,0,1 always moves one unit forward along the entity's own z axis, whatever its orientation.

Gotcha: for a child entity, the default (local) result is its offset from its parent, not where it is on screen. Pass true for global when you want the entity's actual position in the world - for distance checks, spawning things at it, and so on.

See also: EntityY, EntityZ, PositionEntity, EntityDistance.

Example

; EntityX Example
; ---------------

Graphics3D 640,480,0,2
SetBuffer BackBuffer()

camera=CreateCamera()
PositionEntity camera,0,3,-10
RotateEntity camera,15,0,0

light=CreateLight()
RotateEntity light,45,45,0

; A satellite parented to a pivot, offset 2 units along the pivot's x axis
pivot=CreatePivot()
satellite=CreateCube(pivot)
ScaleEntity satellite,0.5,0.5,0.5
PositionEntity satellite,2,0,0
EntityColor satellite,0,200,255

While Not KeyDown(1)

    ; The pivot spins, so the satellite's GLOBAL x changes constantly,
    ; while its LOCAL x (relative to its parent pivot) stays fixed at 2
    TurnEntity pivot,0,1,0

    ; 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"
    ; EntityX with the global flag True returns the world-space x coordinate
    Text 0,20,"EntityX(satellite,True) global = "+EntityX(satellite,True)
    Text 0,40,"EntityX(satellite) local = "+EntityX(satellite)

    Flip

Wend

End

Index