; ==============================================================================
; This is the camera through which the player views the game.

Global cam_pitch#, cam_yaw#, targetpitch#, targetyaw#		; used for first-person free-look modes only


Function SuperCam(cam,ent,cspeed#,dist#,height#,pitch#,roll#)

	TFormPoint 0,height,-dist, ent,0
	
	dx#=(TFormedX()-EntityX(cam,True)) * cspeed
	dy#=(TFormedY()-EntityY(cam,True)) * cspeed
	dz#=(TFormedZ()-EntityZ(cam,True)) * cspeed

	TranslateEntity cam,dx,dy,dz,True
	
	RotateEntity cam,EntityPitch(ent,True),EntityYaw(ent,True),EntityRoll(ent,True),True
	
End Function

Global g_corecurs = LoadSprite("coreTarget.tga", 3, cam)

ScaleSprite g_corecurs,0.05,0.05
EntityOrder g_corecurs,-3
PositionEntity g_corecurs, 0,0,1
HideEntity g_corecurs


Function CoreFreeLook()
	pivot = archer\loc\campivot
	
	;***
	;***  Damped Camera FreeLook (adapted from Barliesque)
	;***
	;mxspd# = -MouseXSpeed()*0.05
	;myspd# =  MouseYSpeed()*0.05

	targetpitch# 	= ClampValue(targetpitch + myspd*0.05, -80, 80)
	targetyaw#		= targetyaw - mxspd*0.05
	
	cam_pitch#  	= cam_pitch + (targetpitch - cam_pitch)/8.0
	cam_yaw#    	= cam_yaw 	+ (targetyaw - cam_yaw)/8.0

	RotateEntity pivot,		cam_pitch, cam_yaw, 0
	
	ShowEntity g_corecurs
End Function

Function OrbitFreeLook()
	pivot = archer\loc\campivot
	
	;***
	;***  Damped Camera Planet Rotatation (adapted from Barliesque)
	;***
	;mxspd# = MouseXSpeed()*0.05
		
	targetyaw# 	= targetyaw + mxspd*0.03
	cam_yaw#    = cam_yaw + (targetyaw - cam_yaw)/8.0

	RotateEntity pivot,		0, cam_yaw, 0
End Function


Function InitChaseCam.ChaseCam( entity, state )
	c.ChaseCam = New ChaseCam
	c\state = state
	
	c\camera=cam
	;EntityType SL_GetLeftCamera(),TYPE_CAMERA		; if camera collides with environment, slide off
	;EntityType SL_GetRightCamera(),TYPE_CAMERA		; if camera collides with environment, slide off
	;EntityRadius SL_GetRightCamera(),0.1
	;EntityRadius SL_GetLeftCamera(),0.1
	
	Return c
End Function

Function UpdateChaseCam( c.ChaseCam )
	Select archer\state
		Case AT_SURFACE ; following player in third person
			target = archer\model
			;        cam, ent,           spd,   dist,   height,     pitch,     roll
			SuperCam(cam,target,  		 0.1,    2.0,      1.5,         0,       0)
	End Select
;	If archer\loc = Null Then
;		scale# = 1;
;	Else
;		scale# = archer\loc\radius# * plrscl#
;	EndIf
;	ScaleEntity cam,scale,scale,scale
End Function