#constant cameraFOV 61.9621391296
global ZDist# as integer
global HUDBaseX as integer
global HUDBaseY as integer
global ScreenX = 1024
global ScreenY = 768
ZDist# = (ScreenY / 2) / TAN(cameraFOV / 2) ` distance from cam to make plain scale to exact pixel size (10x10 plain takes up 10x 10 pixels on screen etc.)
HUDBaseX = 0 - ScreenX / 2 ` variables needed to convert GUI-objects x and y position to screen positions
HUDBaseY = ScreenY / 2
Type HUDobject
Obj as dword
CurX as integer
CurY as integer
PosX as integer
PosY as integer
Width as integer
Height as integer
Texture as integer
Ghost as integer
Status as integer ` on, off, moving
endtype
global MaxHUDPanels
MaxHUDPanels = 3
dim HUD(MaxHUDPanels) as HUDObject
`-------------------------------------------------------------------------------------------
autocam off
set display mode ScreenX, ScreenY, 32:sync on:sync rate 60
`-------------------------------------------------------------------------------------------
make matrix 1,5000,5000,50,50 ` set up a 3d matrix as a reference for camera movement
set matrix height 1,25,25,500
update matrix 1
position camera 2500, 500, -500
CreateHUD() ` create three plains that will be used as hud-panels
`-------------------------------------------------------------------------------------------
do
x#=x#+mousemovey() : y#=y#+mousemovex() : rotate camera 0,x#,y#,0 ` move camera with mouse
UpdateHUD() ` Update the hud postion relative to the screen position
sync
loop
`-------------------------------------------------------------------------------------------
function CreateHUD()
HUD(1).Obj = 80
HUD(1).Width = 150
HUD(1).Height = 250
HUD(1).PosX = 0
HUD(1).PosY = 0
HUD(1).Texture = 0
HUD(1).Ghost = 0
HUD(1).Status = 1
make object plain HUD(1).Obj, HUD(1).Width, HUD(1).Height
HUD(2).Obj = 81
HUD(2).Width = 100
HUD(2).Height = 100
HUD(2).PosX = ScreenX /2 - HUD(2).Width /2
HUD(2).PosY = ScreenY /2 - HUD(2).Height /2
HUD(2).Texture = 0
HUD(2).Ghost = 1
HUD(2).Status = 1
make object plain HUD(2).Obj, HUD(2).Width, HUD(2).Height
HUD(3).Obj = 82
HUD(3).Width = 150
HUD(3).Height = 250
HUD(3).PosX = ScreenX - Hud(3).Width
HUD(3).PosY = 0
HUD(3).Texture = 0
HUD(3).Ghost = 0
HUD(3).Status = 1
make object plain HUD(3).Obj, HUD(3).Width, HUD(3).Height
endfunction
`-------------------------------------------------------------------------------------------
function UpdateHUD() ` place the hud objects on screen in actual screen x and y positions
for Id = 1 to MaxHUDPanels
HudPosition(Hud(Id).Obj, Hud(Id).PosX, HUD(Id).PosY, HUD(Id).Width, HUD(Id).Height, HUD(Id).Ghost)
next Id
endfunction
`-------------------------------------------------------------------------------------------
Function HudPosition(Obj, PosX, PosY, Width, Height, Ghost) ` obj = plain nr., x & y = screen pos., height & width = obj. height + widtj, ghost = ghost the plain (1 or 0)
CurCamX = camera position x()
CurCamY = camera position y()
CurCamZ = camera position z()
CamAngX = camera angle x()
CamAngY = camera angle y()
CamAngZ = camera angle z()
position object obj, CurCamX, CurCamY, CurCamZ ` Place object at camera position
set object to camera orientation Obj ` Orient the object to the camera and face object towards camera
rotate object Obj, -CamAngX, wrapvalue(CamAngY+180), CamAngZ ` turn object left Obj, 180
move object obj, ZDist# * -1 ` Move object to pixel perfect distance...
move object left Obj, HUDBaseX + PosX + (Width /2) ` ...and postion it to screen co-ords
move object up Obj, HUDBaseY - PosY - (Height /2)
disable object zdepth Obj ` Ensure HUD appears on top of everything else
set object filter Obj, 0 ` Don't mipmap object texture. Plains will appear textured like sprites
if Ghost = 1 ` Ghost object if required (Ghosting only works if object is set to be effected by lighting).
set object light Obj, 1
ghost object on Obj
else
set object light Obj, 0 ` Don't react to any lights in the scene. This stops the hud changing brightness as the camera position...
ghost object off Obj ` ...is changed. The problem is that it stops ghosting working
endif
endFunction
Line 107:
rotate object Obj, CamAngX, wrapvalue(CamAngY+180), CamAngZ ` turn object left Obj, 180
Needs to be:
rotate object Obj,
-CamAngX, wrapvalue(CamAngY+180), CamAngZ ` turn object left Obj, 180
It's rotating the obj on the x axis in the wrong direction.
Everybody is a genius. But if you judge a fish by its ability to climb a tree, it will live its whole life believing that it is stupid.