--
-- internalCamera
-- author: Manuel Leithner (SFM-Modding), werik
--

internalCamera = {};

function internalCamera.prerequisitesPresent(specializations)
    return SpecializationUtil.hasSpecialization(Motorized, specializations);
end;

function internalCamera:load(xmlFile)
	---------------------CAM INTERNA MOBILE---------------------
	self.internalCamera = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.internalCamera#index"));
	self.camPositionX = 0;
	self.camPositionZ = 0;
	self.camPositionY = 0;
	------------REALISTIC INDOOR CAM------------
	self.ric = {};
	self.ric.directionPart = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.realisticIndoorCam#directionPart"));
end;

function internalCamera:readStream(streamId, connection)
end;

function internalCamera:writeStream(streamId, connection)
end;

function internalCamera:delete()
end;

function internalCamera:mouseEvent(posX, posY, isDown, isUp, button)
end;

function internalCamera:keyEvent(unicode, sym, modifier, isDown)
end;
 
function internalCamera:update(dt)
	---------------------CAM INTERNA MOBILE---------------------
     if self.camIndex == 1 then
	 if self:getIsActive() then
		if InputBinding.isPressed(InputBinding.MOVECAMLEFT2) then
			self.camPositionX = self.camPositionX + 0.03;
			if self.camPositionX >= 0.15 then
				self.camPositionX = 0.15;
			end;
		end;
		if InputBinding.isPressed(InputBinding.MOVECAMRIGHT2) then
			self.camPositionX = self.camPositionX - 0.03;
			if self.camPositionX <= -0.15 then
				self.camPositionX = -0.15;
			end;
		end;
		if InputBinding.isPressed(InputBinding.MOVECAMFORWARD2) then
			self.camPositionZ = self.camPositionZ + 0.03;
			if self.camPositionZ >= 0.3 then
				self.camPositionZ = 0.3;
			end;
		end;
				if InputBinding.isPressed(InputBinding.MOVECAMBACK2) then
			self.camPositionZ = self.camPositionZ - 0.03;
			if self.camPositionZ <= -0.22 then
				self.camPositionZ = -0.22;
			end;
		end;
		if Input.isMouseButtonPressed(Input.MOUSE_BUTTON_WHEEL_UP) then
			self.camPositionY = self.camPositionY + 0.02;
			if self.camPositionY >= 0.15 then
				self.camPositionY = 0.15;
			end;
		end;
		if Input.isMouseButtonPressed(Input.MOUSE_BUTTON_WHEEL_DOWN) then
			self.camPositionY = self.camPositionY - 0.02;
			if self.camPositionY <= -0.2 then
				self.camPositionY = -0.2;
			end;
		end;
		if Input.isMouseButtonPressed(Input.MOUSE_BUTTON_MIDDLE) then
			self.camPositionX = 0;
			self.camPositionZ = 0;
			self.camPositionY = 0;
		end;
		if self.internalCamera ~= nil then
			setTranslation(self.internalCamera, self.camPositionX, self.camPositionZ, self.camPositionY);
		end;
   	       end;
             end;
	--------------REALISTIC INDOOR CAM------------------------
	if self:getIsActive() then
			local ax, ay, az = getWorldTranslation(self.ric.directionPart);
			local bx = 0;
			local by = 1100000;
			local bz = 0;
			x, y, z = worldDirectionToLocal(getParent(self.ric.directionPart), bx-ax, by-ay, bz-az);
			setDirection(self.ric.directionPart, x, y, z, 0, 0, 1);

	end;
end;

function internalCamera:onLeave()
end;

function internalCamera:draw()
end;
