--Vehicle Compass
--by Zen


VehicleCompass = {};




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

function VehicleCompass:load(xmlFile)



end;	

function VehicleCompass:delete()
end;


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

function VehicleCompass:keyEvent(unicode, sym, modifier, isDown)
end;

function VehicleCompass:update(dt)

	if self.isEntered then

	local x,y,z = localDirectionToWorld(self.rootNode, 0, 0, -121);
	local length = Utils.vector2Length(x,z);
	local dX = x/length;
	local dZ = z/length;
	local Azimuth = math.deg(math.atan2(dX,dZ));
	  if Azimuth < 0  then 
  		Azimuth = 360 - (Azimuth * -1);
    end;
  
	setTextColor(0.1,0.2,0.1,1);
	setTextBold(true);
	       if Azimuth > 270 then
	         renderText(0.834,0.955,0.020,"N");
          renderText(0.85,0.955,0.020,string.format("%3.0f ",360 - math.floor(Azimuth + 0.5)));
	         renderText(0.874,0.955,0.020,"°");
	         renderText(0.884,0.955,0.020,"E");
	       elseif Azimuth > 180 then
	         renderText(0.834,0.955,0.020,"E");
          renderText(0.85,0.955,0.020,string.format("%3.0f ",360 - math.floor(Azimuth + 0.5)));
	         renderText(0.874,0.955,0.020,"°");
	         renderText(0.884,0.955,0.020,"S");
	       elseif Azimuth > 90 then
	         renderText(0.834,0.955,0.020,"S");
          renderText(0.85,0.955,0.020,string.format("%3.0f ",360 - math.floor(Azimuth + 0.5)));
	         renderText(0.874,0.955,0.020,"°");
	         renderText(0.884,0.955,0.020,"W");
         else
	         renderText(0.834,0.955,0.020,"W");
          renderText(0.85,0.955,0.020,string.format("%3.0f ",360 - math.floor(Azimuth + 0.5)));
	         renderText(0.874,0.955,0.020,"°");         
	         renderText(0.884,0.955,0.020,"N");
				 end;
 	
 		
		end;
end;

function VehicleCompass:draw()  
end;

function VehicleCompass:onEnter()

    self.lepcsoMax = true;

end;



