Code archives/3D Graphics - Misc/Fast 3D hud design system

This code has been declared by its author to be Public Domain code.

Download source code

Fast 3D hud design system by Rob2002
This set of functions will help you design a set of 3D HUD overlays. It is faster than displaying sprites and will adapt to any fov or resolution.

Enquire at rob@... for any bugs or queries.
;fov is the same as your camerazoom.
Function Sprite2D(sprite,x#,y#,fov#)
	PositionEntity sprite,2*(x-320),-2*(y-240),fov#*640
End Function

;scale sprite in screen pixels relative to a 640x480 res when used with Sprite2D
Function ScaleSprite2(sprite,x,y)
	ScaleEntity sprite,x,y,1
End Function

;please pass camera to this function or 0 for a billboard type with mesh.
Function CreateSprite2(parent)
	If parent<>0
		m=CreateMesh(parent)
	Else
		m=CreateMesh()
	EndIf
	s=CreateSurface(m)
	AddVertex s,-1,+1,-1,0,0:AddVertex s,+1,+1,-1,1,0
	AddVertex s,+1,-1,-1,1,1:AddVertex s,-1,-1,-1,0,1
	AddTriangle s,0,1,2:AddTriangle s,0,2,3
	ScaleEntity m,100,100,1
	Return m
End Function

Comments

Chroma2009
Rob, 7 years later...and I get first post!

This code rocks man. I combined it with the SetCameraFOV from sswift and it's perfect for perfect pixel sizing and placement for a 2D in 3D hud. Hat's off to you man!


Code Archives Forum