dxEntityX#(entity%,global%)

Parameters

entity = handle of Loaded or Created Entity
global = True for Global coordinates, False for Local. Optional, defaults to False.

Description

The X-coordinate of the entity.
If the global flag is set to False then the parent's local coordinate system is used.

NOTE: If the entity has no parent then local and global coordinates are the same.
In this case you can think of the 3d world as the parent.

Global coordinates refer to the 3d world. Blitz 3D 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 same concept is used in the entity movement commands:

dxMoveEntity entity, 0,0,1

No matter what the orientation this moves one unit forward.

Example

; dxEntityX / dxEntityY / dxEntityZ example.

; Escape quits, other keys move or pause the display.

Const width = 640, height = 480
Const KEY_ESC = 1, KEY_LEFT = 203, KEY_RIGHT = 205

dxGraphics3D 640, 480
dxAmbientLight 50, 50, 50

Global isMoving = False ; used to pause/resume movement
Global count ; how many updates have been done


; Set up a camera, light and three entities...

cam = dxCreateCamera()
dxPositionEntity cam, 0, 2, -50
dxCameraZoom cam, 4

lt = dxCreateLight() : dxTurnEntity lt, 30, 40, 0


Global oSphere, pCone, cSphere

oSphere = dxCreateSphere()
dxEntityColor oSphere, 250, 50, 0 ; Orange = Origin, parent of cone

pCone = dxCreateCone( 8, True, oSphere) ; will be a parent of small sphere
dxScaleEntity pCone, .8, 2.0, .8
dxPositionEntity pCone, 8, 0, 0
dxEntityColor pCone, 255, 255, 0

cSphere = dxCreateSphere( 8, pCone ) ; child of the cone
dxEntityColor cSphere, 150, 150, 0
dxScaleEntity cSphere, .4/.8, .4/2.0, .4/.8 ; try commenting out this dxLine
dxPositionEntity cSphere, 0, 2, 0 ; above parent

; ... and we are ready run.

While Not dxKeyDown( KEY_ESC )

UpdateEverything
dxRenderWorld
ShowInfo

dxFlip

Wend

End



Function UpdateEverything( )

; Nothing moves relative to its parent, so local coordinates are constant.
; Try uncommenting the dxPositionEntity command to change this.


If GetKey() Then isMoving = Not isMoving

If isMoving
dxTurnEntity oSphere, 0, .5, 0
dxTurnEntity pCone, .2, 0, 0

count = count + 1
a# = count Mod 360
; dxPositionEntity cSphere, 0, 2 + Sin( a ), 0 ; experiment with this

End If

End Function

Function ShowInfo( ) ; global and local coordinates for all entities
Local x$, y$, z$

dxColor 255, 255, 255
dxText 185, 20, "Global"
dxText 495, 20, "Local"

dxColor 250, 50, 0
dxText 20, 50, "oSphere: " + XYZ( oSphere, True )
dxText 400, 50, XYZ( oSphere, False )

dxColor 255, 255, 0
dxText 20, 75, " pCone: " + XYZ( pCone, True )
dxText 400, 75, XYZ( pCone, False )

dxColor 150, 150, 0
dxText 20, 100, "cSphere: " + XYZ( cSphere, True )
dxText 400, 100, XYZ( cSphere, False )

End Function

; ******************************************************************

; These two functions just format the dxText display.
; Without them there are too many numbers crowding the screen.

Function Round#( x#, m# ) ; returns x rounded to multiple of m
If m < 0.0 Then m = -m
s# = Sgn( x )
If x < 0.0 Then x = -x
diff# = x Mod m
If diff < .5 * m
Return ( x - diff ) * s
Else
Return ( m + x - diff ) * s
End If
End Function


Function XYZ$( entity, globalFlag )

ex# = Round( dxEntityX( entity, globalFlag ), .001 )
ey# = Round( dxEntityY( entity, globalFlag ), .001 )
ez# = Round( dxEntityZ( entity, globalFlag ), .001 )

Return RSet( ex, 8 ) + RSet( ey, 8 ) + RSet( ez, 8 )

End Function

Index