--
-- 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 == 2 then
	 if self:getIsActive() then
		if Input.isKeyPressed(Input.KEY_KP_9) then
			self.camPositionX = self.camPositionX + 0.03;
			if self.camPositionX >= 0.7 then
				self.camPositionX = 0.7;
			end;
		end;
		if Input.isKeyPressed(Input.KEY_KP_8) then
			self.camPositionX = self.camPositionX - 0.03;
			if self.camPositionX <= -0.15 then
				self.camPositionX = -0.15;
			end;
		end;
		if Input.isKeyPressed(Input.KEY_KP_divide) then
			self.camPositionZ = self.camPositionZ + 0.03;
			if self.camPositionZ >= 0.23 then
				self.camPositionZ = 0.23;
			end;
		end;
		if Input.isKeyPressed(Input.KEY_KP_multiply) 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;
