Type TCam

	Field cam:TCamera										' camera entity
	Field parent:TEntity									' camera parent

	Field X:Float = 0.0										' Position X
	Field Y:Float = 0.0										' Position Y
	Field Z:Float = 0.0										' Position Z

	Field OX:Float = 0.0									' Old Position X
	Field OY:Float = 0.0									' Old Position Y
	Field OZ:Float = 0.0									' Old Position Z
	
	Field Pitch:Float = 0.0									' Pitch
	Field Yaw:Float = 0.0									' Yaw
	Field Roll:Float = 0.0									' Roll

	Field CLScolor:Int[] = [0, 0, 0]						' Background color
	Field FOGcolor:Int[] = [0, 0, 0]						' Fog color
		
	Field fov:Float											' Field of View
	Field FOGmode:Int = False								' Fog Mode
	Field zoom:Float = 1.0									' Zoom factor

	Field rangemin:Float = 1.0								' Frustum start
	Field rangemax:Float = 10000.0							' Frustum end
	Field FOGrangemin:Float = 1.0							' Fog Frustum start
	Field FOGrangemax:Float = 10000.0						' Fog Frustum end
	
	Field viewx:Int = 0										' Viewport X Position
	Field viewy:Int = 0										' Viewport Y Position
	Field width:Int = GraphicsWidth()						' Viewport width
	Field height:Int = GraphicsHeight()						' Viewport height
	
	Field factor1:Float = 1.0								' Camera distance factor #1
	Field factor2:Float = 1.0								' Camera distance factor #2
	Field factor3:Float = 1.0								' Camera distance factor #3
	
	Field PX:Int											' Projected X
	Field PY:Int											' Projected Y

	' --------------------------------------------------------------------------------------------
	' Add new camera
	' --------------------------------------------------------------------------------------------
	Method Add()
	
		cam = CreateCamera(parent)
		
	End Method
	
	' --------------------------------------------------------------------------------------------
	' Show Camera
	' --------------------------------------------------------------------------------------------
	Method Show()
	
		ShowEntity cam
	
	End Method

	' --------------------------------------------------------------------------------------------
	' Hide Camera
	' --------------------------------------------------------------------------------------------
	Method Hide()
	
		HideEntity cam
	
	End Method
	
	' --------------------------------------------------------------------------------------------
	' Update Camera
	' --------------------------------------------------------------------------------------------
	Method Update()

		OX = EntityX(cam)
		OY = EntityY(cam)
		OZ = EntityZ(cam)
	
		PositionEntity cam, x, y, z
		RotateEntity cam, pitch, yaw, roll
		CameraRange cam, rangemin, rangemax
		CameraFogRange cam, FOGrangemin, FOGrangemax
		CameraClsColor cam, CLScolor[0], CLScolor[1], CLScolor[2]
		CameraZoom cam, zoom
		CameraViewport cam, viewx, viewy, width, height
	
	End Method
	
	Method Moved:Int()
	
		If (ox <> x) Or (oy <> y) Or (oz <> z) Then Return True
		
		Return False
			
	End Method
	
	' --------------------------------------------------------------------------------------------
	' Calculate Screen Projection coordinates
	' --------------------------------------------------------------------------------------------
	Method Project(x:Float = 0.0, y:Float = 0.0, z:Float = 0.0)
		
		CameraProject cam, x, y, z
		PX = ProjectedX()
		PY = ProjectedY()
	
	End Method
		
	' --------------------------------------------------------------------------------------------
	' Store current camera position
	' --------------------------------------------------------------------------------------------
	Method GetCameraPosition(glob:Int = False)
	
		X = EntityX(cam, glob)
		Y = EntityY(cam, glob)
		Z = EntityZ(cam, glob)
		
		factor1 = 1.0 / Exp(1.0 / Y) * (Y * 0.25)
		'factor2 = 1.0 / Exp(1.0 / y) * (y * 0.75)
		'factor2 = Log(1 + Y) * Sqr(Y ^ (2.0 + Cos(Normalize(Y, 0, 10000, 0, 360))))
		factor2 = Y
		factor3 = 0
	
	End Method
	
End Type