--
-- tur
-- Specialization class for turs
--
-- @author  MySQly
-- @date  10/06/09
--
-- Copyright (C) MySQly, All Rights Reserved.

tur = {};

function tur.prerequisitesPresent(specializations)
    Vehicle.registerJointType("frontloader");
    return true;
end;

function tur:load(xmlFile)

	hydraulic1SoundFile = Utils.getFilename("hydraulicUp.wav", self.baseDirectory);
    self.hydraulic1SoundId = createSample("hydraulic1Sound");
    loadSample(self.hydraulic1SoundId, hydraulic1SoundFile, false);
    local pitch = Utils.getNoNil(getXMLFloat(xmlFile, "vehicle.hydraulicUpSound#pitchOffset"), 0)
    setSamplePitch(self.hydraulic1SoundId, pitch);
    self.hydraulic1Playing = false;
	
	hydraulic2SoundFile = Utils.getFilename("hydraulicUp.wav", self.baseDirectory);
    self.hydraulic2SoundId = createSample("hydraulic2Sound");
    loadSample(self.hydraulic2SoundId, hydraulic2SoundFile, false);
    local pitch = Utils.getNoNil(getXMLFloat(xmlFile, "vehicle.hydraulicDownSound#pitchOffset"), 0)
    setSamplePitch(self.hydraulic2SoundId, pitch);
    self.hydraulic2Playing = false;
	
	hydraulic3SoundFile = Utils.getFilename("hydraulicUp.wav", self.baseDirectory);
    self.hydraulic3SoundId = createSample("hydraulic3Sound");
    loadSample(self.hydraulic3SoundId, hydraulic3SoundFile, false);
    local pitch = Utils.getNoNil(getXMLFloat(xmlFile, "vehicle.hydraulicTiltUpSound#pitchOffset"), 0)
    setSamplePitch(self.hydraulic3SoundId, pitch);
    self.hydraulic3Playing = false;
	
	hydraulic4SoundFile = Utils.getFilename("hydraulicUp.wav", self.baseDirectory);
    self.hydraulic4SoundId = createSample("hydraulic4Sound");
    loadSample(self.hydraulic4SoundId, hydraulic4SoundFile, false);
    local pitch = Utils.getNoNil(getXMLFloat(xmlFile, "vehicle.hydraulicTiltUpSound#pitchOffset"), 0)
    setSamplePitch(self.hydraulic4SoundId, pitch);
    self.hydraulic4Playing = false;

	self.frontloaderJointInvalid = false;
	local jointDesc = {};
    jointDesc.jointTransform = Utils.indexToObject(self.rootNode, getXMLString(xmlFile, "vehicle.frontLoaderJoint#index"));
    if jointDesc.jointTransform ~= nil then
        jointDesc.rotationNode = Utils.indexToObject(self.rootNode, getXMLString(xmlFile, "vehicle.frontLoaderJoint#rotationNode"));
        if jointDesc.rotationNode ~= nil then
            local x, y, z = Utils.getVectorFromString(getXMLString(xmlFile, "vehicle.frontLoaderJoint#maxRot"));
            jointDesc.maxRot = {};
            jointDesc.maxRot[1] = Utils.degToRad(Utils.getNoNil(x, 0));
            jointDesc.maxRot[2] = Utils.degToRad(Utils.getNoNil(y, 0));
            jointDesc.maxRot[3] = Utils.degToRad(Utils.getNoNil(z, 0));

            x, y, z = getRotation(jointDesc.rotationNode);
            jointDesc.minRot = {x,y,z};
        end;
        jointDesc.rotationNode2 = Utils.indexToObject(self.rootNode, getXMLString(xmlFile, "vehicle.frontLoaderJoint#rotationNode2"));
        if jointDesc.rotationNode2 ~= nil then
            local x, y, z = Utils.getVectorFromString(getXMLString(xmlFile, "vehicle.frontLoaderJoint#maxRot2"));
            jointDesc.maxRot2 = {};
            jointDesc.maxRot2[1] = Utils.degToRad(Utils.getNoNil(x, 0));
            jointDesc.maxRot2[2] = Utils.degToRad(Utils.getNoNil(y, 0));
            jointDesc.maxRot2[3] = Utils.degToRad(Utils.getNoNil(z, 0));

            x, y, z = getRotation(jointDesc.rotationNode2);
            jointDesc.minRot2 = {x,y,z};
        end;
        jointDesc.moveTime = Utils.getNoNil(getXMLFloat(xmlFile, "vehicle.frontLoaderJoint#moveTime"), 0.5)*1000;
        jointDesc.moveTime2 = Utils.getNoNil(getXMLFloat(xmlFile, "vehicle.frontLoaderJoint#moveTime2"), 0.5)*1000;

        jointDesc.moveDirection = 0; -- 1 = rotate up, -1 = rotate down
        jointDesc.moveDirection2 = 0;

        jointDesc.jointIndex = 0;
    end;

    self.frontLoaderJointDesc2 = jointDesc;
    self.frontLoaderAttachedObject = nil;
	
	local rotationPartNodeZylinderHub = Utils.indexToObject(self.rootNode, getXMLString(xmlFile, "vehicle.rotationPartZylinderHub#index"));
    if rotationPartNodeZylinderHub ~= nil then
        self.rotationPartZylinderHub = {};
        self.rotationPartZylinderHub.node = rotationPartNodeZylinderHub;

        local x, y, z = Utils.getVectorFromString(getXMLString(xmlFile, "vehicle.rotationPartZylinderHub#minRot"));
        self.rotationPartZylinderHub.minRot = {};
        self.rotationPartZylinderHub.minRot[1] = Utils.degToRad(Utils.getNoNil(x, 0));
        self.rotationPartZylinderHub.minRot[2] = Utils.degToRad(Utils.getNoNil(y, 0));
        self.rotationPartZylinderHub.minRot[3] = Utils.degToRad(Utils.getNoNil(z, 0));

        x, y, z = Utils.getVectorFromString(getXMLString(xmlFile, "vehicle.rotationPartZylinderHub#maxRot"));
        self.rotationPartZylinderHub.maxRot = {};
        self.rotationPartZylinderHub.maxRot[1] = Utils.degToRad(Utils.getNoNil(x, 0));
        self.rotationPartZylinderHub.maxRot[2] = Utils.degToRad(Utils.getNoNil(y, 0));
        self.rotationPartZylinderHub.maxRot[3] = Utils.degToRad(Utils.getNoNil(z, 0));

        self.rotationPartZylinderHub.rotTime = Utils.getNoNil(getXMLString(xmlFile, "vehicle.rotationPartZylinderHub#rotTime"), 2)*1000;
        self.rotationPartZylinderHub.touchRotLimit = Utils.degToRad(Utils.getNoNil(getXMLString(xmlFile, "vehicle.rotationPartZylinderHub#touchRotLimit"), 10));
    end;
	
	local rotationPartNodeZylinderKipp = Utils.indexToObject(self.rootNode, getXMLString(xmlFile, "vehicle.rotationPartZylinderKipp#index"));
    if rotationPartNodeZylinderKipp ~= nil then
        self.rotationPartZylinderKipp = {};
        self.rotationPartZylinderKipp.node = rotationPartNodeZylinderKipp;

        local x, y, z = Utils.getVectorFromString(getXMLString(xmlFile, "vehicle.rotationPartZylinderKipp#minRot"));
        self.rotationPartZylinderKipp.minRot = {};
        self.rotationPartZylinderKipp.minRot[1] = Utils.degToRad(Utils.getNoNil(x, 0));
        self.rotationPartZylinderKipp.minRot[2] = Utils.degToRad(Utils.getNoNil(y, 0));
        self.rotationPartZylinderKipp.minRot[3] = Utils.degToRad(Utils.getNoNil(z, 0));

        x, y, z = Utils.getVectorFromString(getXMLString(xmlFile, "vehicle.rotationPartZylinderKipp#maxRot"));
        self.rotationPartZylinderKipp.maxRot = {};
        self.rotationPartZylinderKipp.maxRot[1] = Utils.degToRad(Utils.getNoNil(x, 0));
        self.rotationPartZylinderKipp.maxRot[2] = Utils.degToRad(Utils.getNoNil(y, 0));
        self.rotationPartZylinderKipp.maxRot[3] = Utils.degToRad(Utils.getNoNil(z, 0));

        self.rotationPartZylinderKipp.rotTime = Utils.getNoNil(getXMLString(xmlFile, "vehicle.rotationPartZylinderKipp#rotTime"), 2)*1000;
        self.rotationPartZylinderKipp.touchRotLimit = Utils.degToRad(Utils.getNoNil(getXMLString(xmlFile, "vehicle.rotationPartZylinderKipp#touchRotLimit"), 10));
    end;
	
	local rotationPartNodeGelenk1 = Utils.indexToObject(self.rootNode, getXMLString(xmlFile, "vehicle.rotationPartGelenk1#index"));
    if rotationPartNodeGelenk1 ~= nil then
        self.rotationPartGelenk1 = {};
        self.rotationPartGelenk1.node = rotationPartNodeGelenk1;

        local x, y, z = Utils.getVectorFromString(getXMLString(xmlFile, "vehicle.rotationPartGelenk1#minRot"));
        self.rotationPartGelenk1.minRot = {};
        self.rotationPartGelenk1.minRot[1] = Utils.degToRad(Utils.getNoNil(x, 0));
        self.rotationPartGelenk1.minRot[2] = Utils.degToRad(Utils.getNoNil(y, 0));
        self.rotationPartGelenk1.minRot[3] = Utils.degToRad(Utils.getNoNil(z, 0));

        x, y, z = Utils.getVectorFromString(getXMLString(xmlFile, "vehicle.rotationPartGelenk1#maxRot"));
        self.rotationPartGelenk1.maxRot = {};
        self.rotationPartGelenk1.maxRot[1] = Utils.degToRad(Utils.getNoNil(x, 0));
        self.rotationPartGelenk1.maxRot[2] = Utils.degToRad(Utils.getNoNil(y, 0));
        self.rotationPartGelenk1.maxRot[3] = Utils.degToRad(Utils.getNoNil(z, 0));

        self.rotationPartGelenk1.rotTime = Utils.getNoNil(getXMLString(xmlFile, "vehicle.rotationPartGelenk1#rotTime"), 2)*1000;
        self.rotationPartGelenk1.touchRotLimit = Utils.degToRad(Utils.getNoNil(getXMLString(xmlFile, "vehicle.rotationPartGelenk1#touchRotLimit"), 10));
    end;
	
	local rotationPartNodeGelenk2 = Utils.indexToObject(self.rootNode, getXMLString(xmlFile, "vehicle.rotationPartGelenk2#index"));
    if rotationPartNodeGelenk2 ~= nil then
        self.rotationPartGelenk2 = {};
        self.rotationPartGelenk2.node = rotationPartNodeGelenk2;

        local x, y, z = Utils.getVectorFromString(getXMLString(xmlFile, "vehicle.rotationPartGelenk2#minRot"));
        self.rotationPartGelenk2.minRot = {};
        self.rotationPartGelenk2.minRot[1] = Utils.degToRad(Utils.getNoNil(x, 0));
        self.rotationPartGelenk2.minRot[2] = Utils.degToRad(Utils.getNoNil(y, 0));
        self.rotationPartGelenk2.minRot[3] = Utils.degToRad(Utils.getNoNil(z, 0));

        x, y, z = Utils.getVectorFromString(getXMLString(xmlFile, "vehicle.rotationPartGelenk2#maxRot"));
        self.rotationPartGelenk2.maxRot = {};
        self.rotationPartGelenk2.maxRot[1] = Utils.degToRad(Utils.getNoNil(x, 0));
        self.rotationPartGelenk2.maxRot[2] = Utils.degToRad(Utils.getNoNil(y, 0));
        self.rotationPartGelenk2.maxRot[3] = Utils.degToRad(Utils.getNoNil(z, 0));

        self.rotationPartGelenk2.rotTime = Utils.getNoNil(getXMLString(xmlFile, "vehicle.rotationPartGelenk2#rotTime"), 2)*1000;
        self.rotationPartGelenk2.touchRotLimit = Utils.degToRad(Utils.getNoNil(getXMLString(xmlFile, "vehicle.rotationPartGelenk2#touchRotLimit"), 10));
    end;
	
	local translationPartNodeZylinderKipp2 = Utils.indexToObject(self.rootNode, getXMLString(xmlFile, "vehicle.translationPartZylinderKipp2#index"));
    if translationPartNodeZylinderKipp2 ~= nil then
        self.translationPartZylinderKipp2 = {};
        self.translationPartZylinderKipp2.node = translationPartNodeZylinderKipp2;
        local x, y, z = Utils.getVectorFromString(getXMLString(xmlFile, "vehicle.translationPartZylinderKipp2#minTrans"));
        self.translationPartZylinderKipp2.minTrans = {};
        self.translationPartZylinderKipp2.minTrans[1] = Utils.getNoNil(x, 0);
        self.translationPartZylinderKipp2.minTrans[2] = Utils.getNoNil(y, 0);
        self.translationPartZylinderKipp2.minTrans[3] = Utils.getNoNil(z, 0);

        x, y, z = Utils.getVectorFromString(getXMLString(xmlFile, "vehicle.translationPartZylinderKipp2#maxTrans"));
        self.translationPartZylinderKipp2.maxTrans = {};
        self.translationPartZylinderKipp2.maxTrans[1] = Utils.getNoNil(x, 0);
        self.translationPartZylinderKipp2.maxTrans[2] = Utils.getNoNil(y, 0);
        self.translationPartZylinderKipp2.maxTrans[3] = Utils.getNoNil(z, 0);

        self.translationPartZylinderKipp2.transTime = Utils.getNoNil(getXMLString(xmlFile, "vehicle.translationPartZylinderKipp2#transTime"), 2)*1000;
        self.translationPartZylinderKipp2.touchTransLimit = Utils.getNoNil(getXMLString(xmlFile, "vehicle.translationPartZylinderKipp2#touchTransLimit"), 10);
    end;
	
	local translationPartNodeZylinderHub2 = Utils.indexToObject(self.rootNode, getXMLString(xmlFile, "vehicle.translationPartZylinderHub2#index"));
    if translationPartNodeZylinderHub2 ~= nil then
        self.translationPartZylinderHub2 = {};
        self.translationPartZylinderHub2.node = translationPartNodeZylinderHub2;
        local x, y, z = Utils.getVectorFromString(getXMLString(xmlFile, "vehicle.translationPartZylinderHub2#minTrans"));
        self.translationPartZylinderHub2.minTrans = {};
        self.translationPartZylinderHub2.minTrans[1] = Utils.getNoNil(x, 0);
        self.translationPartZylinderHub2.minTrans[2] = Utils.getNoNil(y, 0);
        self.translationPartZylinderHub2.minTrans[3] = Utils.getNoNil(z, 0);

        x, y, z = Utils.getVectorFromString(getXMLString(xmlFile, "vehicle.translationPartZylinderHub2#maxTrans"));
        self.translationPartZylinderHub2.maxTrans = {};
        self.translationPartZylinderHub2.maxTrans[1] = Utils.getNoNil(x, 0);
        self.translationPartZylinderHub2.maxTrans[2] = Utils.getNoNil(y, 0);
        self.translationPartZylinderHub2.maxTrans[3] = Utils.getNoNil(z, 0);

        self.translationPartZylinderHub2.transTime = Utils.getNoNil(getXMLString(xmlFile, "vehicle.translationPartZylinderHub2#transTime"), 2)*1000;
        self.translationPartZylinderHub2.touchTransLimit = Utils.getNoNil(getXMLString(xmlFile, "vehicle.translationPartZylinderHub2#touchTransLimit"), 10);
    end;
	
	local rotationPartNodeJoystick1 = Utils.indexToObject(self.rootNode, getXMLString(xmlFile, "vehicle.rotationPartJoystick1#index"));
    if rotationPartNodeJoystick1 ~= nil then
        self.rotationPartJoystick1 = {};
        self.rotationPartJoystick1.node = rotationPartNodeJoystick1;

        local x, y, z = Utils.getVectorFromString(getXMLString(xmlFile, "vehicle.rotationPartJoystick1#minRot"));
        self.rotationPartJoystick1.minRot = {};
        self.rotationPartJoystick1.minRot[1] = Utils.degToRad(Utils.getNoNil(x, 0));
        self.rotationPartJoystick1.minRot[2] = Utils.degToRad(Utils.getNoNil(y, 0));
        self.rotationPartJoystick1.minRot[3] = Utils.degToRad(Utils.getNoNil(z, 0));

        x, y, z = Utils.getVectorFromString(getXMLString(xmlFile, "vehicle.rotationPartJoystick1#maxRot"));
        self.rotationPartJoystick1.maxRot = {};
        self.rotationPartJoystick1.maxRot[1] = Utils.degToRad(Utils.getNoNil(x, 0));
        self.rotationPartJoystick1.maxRot[2] = Utils.degToRad(Utils.getNoNil(y, 0));
        self.rotationPartJoystick1.maxRot[3] = Utils.degToRad(Utils.getNoNil(z, 0));

        self.rotationPartJoystick1.rotTime = Utils.getNoNil(getXMLString(xmlFile, "vehicle.rotationPartJoystick1#rotTime"), 2)*1000;
        self.rotationPartJoystick1.touchRotLimit = Utils.degToRad(Utils.getNoNil(getXMLString(xmlFile, "vehicle.rotationPartJoystick1#touchRotLimit"), 10));
    end;
	
	local rotationPartNodeJoystick2 = Utils.indexToObject(self.rootNode, getXMLString(xmlFile, "vehicle.rotationPartJoystick2#index"));
    if rotationPartNodeJoystick2 ~= nil then
        self.rotationPartJoystick2 = {};
        self.rotationPartJoystick2.node = rotationPartNodeJoystick2;

        local x, y, z = Utils.getVectorFromString(getXMLString(xmlFile, "vehicle.rotationPartJoystick2#minRot"));
        self.rotationPartJoystick2.minRot = {};
        self.rotationPartJoystick2.minRot[1] = Utils.degToRad(Utils.getNoNil(x, 0));
        self.rotationPartJoystick2.minRot[2] = Utils.degToRad(Utils.getNoNil(y, 0));
        self.rotationPartJoystick2.minRot[3] = Utils.degToRad(Utils.getNoNil(z, 0));

        x, y, z = Utils.getVectorFromString(getXMLString(xmlFile, "vehicle.rotationPartJoystick2#maxRot"));
        self.rotationPartJoystick2.maxRot = {};
        self.rotationPartJoystick2.maxRot[1] = Utils.degToRad(Utils.getNoNil(x, 0));
        self.rotationPartJoystick2.maxRot[2] = Utils.degToRad(Utils.getNoNil(y, 0));
        self.rotationPartJoystick2.maxRot[3] = Utils.degToRad(Utils.getNoNil(z, 0));

        self.rotationPartJoystick2.rotTime = Utils.getNoNil(getXMLString(xmlFile, "vehicle.rotationPartJoystick2#rotTime"), 2)*1000;
        self.rotationPartJoystick2.touchRotLimit = Utils.degToRad(Utils.getNoNil(getXMLString(xmlFile, "vehicle.rotationPartJoystick2#touchRotLimit"), 10));
    end;
	
	local rotationPartNodeJoystick3 = Utils.indexToObject(self.rootNode, getXMLString(xmlFile, "vehicle.rotationPartJoystick3#index"));
    if rotationPartNodeJoystick3 ~= nil then
        self.rotationPartJoystick3 = {};
        self.rotationPartJoystick3.node = rotationPartNodeJoystick3;

        local x, y, z = Utils.getVectorFromString(getXMLString(xmlFile, "vehicle.rotationPartJoystick3#minRot"));
        self.rotationPartJoystick3.minRot = {};
        self.rotationPartJoystick3.minRot[1] = Utils.degToRad(Utils.getNoNil(x, 0));
        self.rotationPartJoystick3.minRot[2] = Utils.degToRad(Utils.getNoNil(y, 0));
        self.rotationPartJoystick3.minRot[3] = Utils.degToRad(Utils.getNoNil(z, 0));

        x, y, z = Utils.getVectorFromString(getXMLString(xmlFile, "vehicle.rotationPartJoystick3#maxRot"));
        self.rotationPartJoystick3.maxRot = {};
        self.rotationPartJoystick3.maxRot[1] = Utils.degToRad(Utils.getNoNil(x, 0));
        self.rotationPartJoystick3.maxRot[2] = Utils.degToRad(Utils.getNoNil(y, 0));
        self.rotationPartJoystick3.maxRot[3] = Utils.degToRad(Utils.getNoNil(z, 0));

        self.rotationPartJoystick3.rotTime = Utils.getNoNil(getXMLString(xmlFile, "vehicle.rotationPartJoystick3#rotTime"), 2)*1000;
        self.rotationPartJoystick3.touchRotLimit = Utils.degToRad(Utils.getNoNil(getXMLString(xmlFile, "vehicle.rotationPartJoystick3#touchRotLimit"), 10));
    end;
	
	local rotationPartNodeJoystick4 = Utils.indexToObject(self.rootNode, getXMLString(xmlFile, "vehicle.rotationPartJoystick4#index"));
    if rotationPartNodeJoystick4 ~= nil then
        self.rotationPartJoystick4 = {};
        self.rotationPartJoystick4.node = rotationPartNodeJoystick4;

        local x, y, z = Utils.getVectorFromString(getXMLString(xmlFile, "vehicle.rotationPartJoystick4#minRot"));
        self.rotationPartJoystick4.minRot = {};
        self.rotationPartJoystick4.minRot[1] = Utils.degToRad(Utils.getNoNil(x, 0));
        self.rotationPartJoystick4.minRot[2] = Utils.degToRad(Utils.getNoNil(y, 0));
        self.rotationPartJoystick4.minRot[3] = Utils.degToRad(Utils.getNoNil(z, 0));

        x, y, z = Utils.getVectorFromString(getXMLString(xmlFile, "vehicle.rotationPartJoystick4#maxRot"));
        self.rotationPartJoystick4.maxRot = {};
        self.rotationPartJoystick4.maxRot[1] = Utils.degToRad(Utils.getNoNil(x, 0));
        self.rotationPartJoystick4.maxRot[2] = Utils.degToRad(Utils.getNoNil(y, 0));
        self.rotationPartJoystick4.maxRot[3] = Utils.degToRad(Utils.getNoNil(z, 0));

        self.rotationPartJoystick4.rotTime = Utils.getNoNil(getXMLString(xmlFile, "vehicle.rotationPartJoystick4#rotTime"), 2)*1000;
        self.rotationPartJoystick4.touchRotLimit = Utils.degToRad(Utils.getNoNil(getXMLString(xmlFile, "vehicle.rotationPartJoystick4#touchRotLimit"), 10));
    end;
end;

function tur:delete()

end;

function tur:mouseEvent(posX, posY, isDown, isUp, button)

end;

function tur:keyEvent(unicode, sym, modifier, isDown)
	if Input.isKeyPressed(Input.KEY_KP_8) then
		self.rotationMaxJoystick1 = isDown;
		self.rotationMinZylinderHub = isDown;
		self.translationMinZylinderHub2 = isDown;
		if not self.hydraulic1Playing then
			playSample(self.hydraulic1SoundId,0,1,0);
			self.hydraulic1Playing = true;
		end;
	else
		if self.hydraulic1Playing then
			stopSample(self.hydraulic1SoundId);
			self.hydraulic1Playing = false;
		end;
	end;
	if Input.isKeyPressed(Input.KEY_KP_2) then
		self.rotationMaxJoystick2 = isDown;
		self.rotationMaxZylinderHub = isDown;
		self.translationMaxZylinderHub2 = isDown;
		if not self.hydraulic2Playing then
			playSample(self.hydraulic2SoundId,0,1,0);
			self.hydraulic2Playing = true;
		end;
	else
		if self.hydraulic2Playing then
			stopSample(self.hydraulic2SoundId);
			self.hydraulic2Playing = false;
		end;
	end;
	if Input.isKeyPressed(Input.KEY_KP_4) then
		self.rotationMaxJoystick3 = isDown;
		self.rotationMaxGelenk1 = isDown;
		self.rotationMaxGelenk2 = isDown;
		self.rotationMaxZylinderKipp = isDown;
		self.translationMaxZylinderKipp2 = isDown;
		if not self.hydraulic3Playing then
			playSample(self.hydraulic3SoundId,0,1,0);
			self.hydraulic3Playing = true;
		end;
	else
		if self.hydraulic3Playing then
			stopSample(self.hydraulic3SoundId);
			self.hydraulic3Playing = false;
		end;
	end;
	if Input.isKeyPressed(Input.KEY_KP_6) then
		self.rotationMaxJoystick4 = isDown;
		self.rotationMinGelenk1 = isDown;
		self.rotationMinGelenk2 = isDown;
		self.rotationMinZylinderKipp = isDown;
		self.translationMinZylinderKipp2 = isDown;
		if not self.hydraulic4Playing then
			playSample(self.hydraulic4SoundId,0,1,0);
			self.hydraulic4Playing = true;
		end;
	else
		if self.hydraulic4Playing then
			stopSample(self.hydraulic4SoundId);
			self.hydraulic4Playing = false;
		end;
	end;
	
	if self.frontLoaderAttachedObject ~= nil then
        self.frontLoaderAttachedObject:keyEvent(unicode, sym, modifier, isDown)
    end;

    local jointDesc = self.frontLoaderJointDesc2;
    if sym == Input.KEY_KP_4 or sym == Input.KEY_KP_6 then
        jointDesc.moveDirection2 = 0;
        if isDown then
        	if sym == Input.KEY_KP_6 then
                jointDesc.moveDirection2 = 1;
        	elseif sym == Input.KEY_KP_4 then
                jointDesc.moveDirection2 = -1;
        	end;
        end;
    end;
	
    if sym == Input.KEY_KP_8 or sym == Input.KEY_KP_2 then
        jointDesc.moveDirection = 0;
        if isDown then
        	if sym == Input.KEY_KP_8 then
                jointDesc.moveDirection = 1;
        	elseif sym == Input.KEY_KP_2 then
                jointDesc.moveDirection = -1;
        	end;
        end;
    end;
	

end;

function tur:update(dt)
	self.frontloaderJointInvalid = false;
	if self.rotationPartJoystick1 ~= nil then
		local x, y, z = getRotation(self.rotationPartJoystick1.node);
		local rot = {x,y,z};
		local newRot = Utils.getMovedLimitedValues(rot, self.rotationPartJoystick1.maxRot, self.rotationPartJoystick1.minRot, 3, self.rotationPartJoystick1.rotTime, dt, not self.rotationMaxJoystick1);
		setRotation(self.rotationPartJoystick1.node, unpack(newRot));
		self.frontloaderJointInvalid = true;
	end;
	
	if self.rotationPartJoystick2 ~= nil then
		local x, y, z = getRotation(self.rotationPartJoystick2.node);
		local rot = {x,y,z};
		local newRot = Utils.getMovedLimitedValues(rot, self.rotationPartJoystick2.maxRot, self.rotationPartJoystick2.minRot, 3, self.rotationPartJoystick2.rotTime, dt, not self.rotationMaxJoystick2);
		setRotation(self.rotationPartJoystick2.node, unpack(newRot));
		self.frontloaderJointInvalid = true;
	end;
	
	if self.rotationPartJoystick3 ~= nil then
		local x, y, z = getRotation(self.rotationPartJoystick3.node);
		local rot = {x,y,z};
		local newRot = Utils.getMovedLimitedValues(rot, self.rotationPartJoystick3.maxRot, self.rotationPartJoystick3.minRot, 3, self.rotationPartJoystick3.rotTime, dt, not self.rotationMaxJoystick3);
		setRotation(self.rotationPartJoystick3.node, unpack(newRot));
		self.frontloaderJointInvalid = true;
	end;
	
	if self.rotationPartJoystick4 ~= nil then
		local x, y, z = getRotation(self.rotationPartJoystick4.node);
		local rot = {x,y,z};
		local newRot = Utils.getMovedLimitedValues(rot, self.rotationPartJoystick4.maxRot, self.rotationPartJoystick4.minRot, 3, self.rotationPartJoystick4.rotTime, dt, not self.rotationMaxJoystick4);
		setRotation(self.rotationPartJoystick4.node, unpack(newRot));
		self.frontloaderJointInvalid = true;
	end;
	
	local doTranslate = self.translationMaxZylinderHub2 or self.translationMinZylinderHub2
	if self.translationPartZylinderHub2 ~= nil and doTranslate then
		local x, y, z = getTranslation(self.translationPartZylinderHub2.node);
		local trans = {x,y,z};
		local newTrans = Utils.getMovedLimitedValues(trans, self.translationPartZylinderHub2.maxTrans, self.translationPartZylinderHub2.minTrans, 3, self.translationPartZylinderHub2.transTime, dt, not self.translationMaxZylinderHub2);
		setTranslation(self.translationPartZylinderHub2.node, unpack(newTrans));
	end;
	
	local doRotate = self.rotationMaxZylinderHub or self.rotationMinZylinderHub
	if self.rotationPartZylinderHub ~= nil and doRotate then
		local x, y, z = getRotation(self.rotationPartZylinderHub.node);
		local rot = {x,y,z};
		local newRot = Utils.getMovedLimitedValues(rot, self.rotationPartZylinderHub.maxRot, self.rotationPartZylinderHub.minRot, 3, self.rotationPartZylinderHub.rotTime, dt, not self.rotationMaxZylinderHub);
		setRotation(self.rotationPartZylinderHub.node, unpack(newRot));
	end;
	
	local doTranslate = self.translationMaxZylinderKipp2 or self.translationMinZylinderKipp2
	if self.translationPartZylinderKipp2 ~= nil and doTranslate then
		local x, y, z = getTranslation(self.translationPartZylinderKipp2.node);
		local trans = {x,y,z};
		local newTrans = Utils.getMovedLimitedValues(trans, self.translationPartZylinderKipp2.maxTrans, self.translationPartZylinderKipp2.minTrans, 3, self.translationPartZylinderKipp2.transTime, dt, not self.translationMaxZylinderKipp2);
		setTranslation(self.translationPartZylinderKipp2.node, unpack(newTrans));
	end;
	
	local doRotate = self.rotationMaxZylinderKipp or self.rotationMinZylinderKipp
	if self.rotationPartZylinderKipp ~= nil and doRotate then
		local x, y, z = getRotation(self.rotationPartZylinderKipp.node);
		local rot = {x,y,z};
		local newRot = Utils.getMovedLimitedValues(rot, self.rotationPartZylinderKipp.maxRot, self.rotationPartZylinderKipp.minRot, 3, self.rotationPartZylinderKipp.rotTime, dt, not self.rotationMaxZylinderKipp);
		setRotation(self.rotationPartZylinderKipp.node, unpack(newRot));
	end;
	
	local doRotate = self.rotationMaxGelenk1 or self.rotationMinGelenk1
	if self.rotationPartGelenk1 ~= nil and doRotate then
		local x, y, z = getRotation(self.rotationPartGelenk1.node);
		local rot = {x,y,z};
		local newRot = Utils.getMovedLimitedValues(rot, self.rotationPartGelenk1.maxRot, self.rotationPartGelenk1.minRot, 3, self.rotationPartGelenk1.rotTime, dt, not self.rotationMaxGelenk1);
		setRotation(self.rotationPartGelenk1.node, unpack(newRot));
	end;
	
	local doRotate = self.rotationMaxGelenk2 or self.rotationMinGelenk2
	if self.rotationPartGelenk2 ~= nil and doRotate then
		local x, y, z = getRotation(self.rotationPartGelenk2.node);
		local rot = {x,y,z};
		local newRot = Utils.getMovedLimitedValues(rot, self.rotationPartGelenk2.maxRot, self.rotationPartGelenk2.minRot, 3, self.rotationPartGelenk2.rotTime, dt, not self.rotationMaxGelenk2);
		setRotation(self.rotationPartGelenk2.node, unpack(newRot));
	end;
	
	for k,implement in pairs(self.attachedImplements) do
		implement.object:onAttach(self);
	end;
	
    local jointDesc = self.frontLoaderJointDesc2;
    local jointFrameInvalid = false;
    if jointDesc.rotationNode ~= nil then
        if jointDesc.moveDirection ~= 0 then
            local x, y, z = getRotation(jointDesc.rotationNode);
            local rot = {x,y,z};
            local newRot = Utils.getMovedLimitedValues(rot, jointDesc.maxRot, jointDesc.minRot, 3, jointDesc.moveTime, dt, jointDesc.moveDirection == 1);
            setRotation(jointDesc.rotationNode, unpack(newRot));
            for i=1, 3 do
                if math.abs(newRot[i] - rot[i]) > 0.001 then
                    jointFrameInvalid = true;
                end;
            end;
        end;
    end;
    if jointDesc.rotationNode2 ~= nil then
        if jointDesc.moveDirection2 ~= 0 then
            local x, y, z = getRotation(jointDesc.rotationNode2);
            local rot = {x,y,z};
            local newRot = Utils.getMovedLimitedValues(rot, jointDesc.maxRot2, jointDesc.minRot2, 3, jointDesc.moveTime2, dt, jointDesc.moveDirection2 == 1);
            setRotation(jointDesc.rotationNode2, unpack(newRot));
            for i=1, 3 do
                if math.abs(newRot[i] - rot[i]) > 0.001 then
                    jointFrameInvalid = true;
                end;
            end;
        end;
    end;
end;

function tur:draw()

end;

function tur:onEnter()
	
end;

function tur:onLeave()

end;
