include( "shared.lua" )

function ENT:Initialize()
	function self:BuildBonePositions( bones, physicsBones )
		local boneTable = { "ValveBiped.Bip01_Head1" };
		
		if ( !self:GetOwner():InVehicle() ) then
			boneTable = { "ValveBiped.Bip01_Head1", "ValveBiped.Bip01_Neck1", "ValveBiped.Bip01_Spine", "ValveBiped.Bip01_Spine1", "ValveBiped.Bip01_Spine2", "ValveBiped.Bip01_Spine4", "ValveBiped.Bip01_L_Hand", "ValveBiped.Bip01_L_Forearm", "ValveBiped.Bip01_L_UpperArm", "ValveBiped.Bip01_L_Clavicle", "ValveBiped.Bip01_R_Hand", "ValveBiped.Bip01_R_Forearm", "ValveBiped.Bip01_R_UpperArm", "ValveBiped.Bip01_R_Clavicle" };
		else
			boneTable = { "ValveBiped.Bip01_Head1", "ValveBiped.Bip01_Neck1", "ValveBiped.Bip01_Spine" };
		end;
		
		for k, v in pairs( boneTable ) do
			local bone = self:LookupBone( v );
			local matrix = self:GetBoneMatrix( bone );
			
			matrix:Scale( Vector(0, 0, 0) ); self:SetBoneMatrix( bone, matrix );
		end;
	end;
end;

function ENT:Draw()
	local owner = self:GetOwner();
	
	if ( ValidEntity( owner ) ) then
		local moveType = owner:GetMoveType();
		
		if ( LocalPlayer() == owner and GetViewEntity():GetClass() != "gmod_cameraprop" ) then
			if ( moveType != MOVETYPE_OBSERVER and moveType != 0 ) then
				if ( owner:InVehicle() ) then
					if ( GetConVarNumber( "gmod_vehicle_viewmode" ) != 1 ) then
						if ( ValidEntity( owner:GetVehicle() ) ) then
							local entityModel = string.lower( owner:GetVehicle():GetModel() );
							
							if ( string.find( entityModel, "chair" ) or string.find( entityModel, "seat" ) ) then
								if ( owner:EyeAngles().yaw > -180 and owner:EyeAngles().yaw < 180 ) then
									if ( owner:EyeAngles().pitch > 12 ) then
										self:DrawModel();
									end;
								elseif ( owner:EyeAngles().pitch > 32 ) then
									self:DrawModel();
								end;
							elseif ( string.find( entityModel, "prisoner" ) ) then
								if ( owner:EyeAngles().yaw > -180 and owner:EyeAngles().yaw < 180 ) then
									self:DrawModel();
								elseif ( owner:EyeAngles().pitch > 83 ) then
									self:DrawModel();
								end;
							elseif ( owner:EyeAngles().yaw > -180 and owner:EyeAngles().yaw < 180 ) then
								self:DrawModel();
							elseif ( owner:EyeAngles().pitch > 6 ) then
								self:DrawModel();
							end;
						else
							self:DrawModel();
						end;
					end;
				elseif ( owner:EyeAngles().pitch > 55 ) then
					self:DrawModel();
				end;
			end;
		end;
	end;
end;

function ENT:DrawTranslucent() self:Draw(); end;
function ENT:Think() end;