-- Using the desired target rotation and elevation, determine where the gun should point right now (smoothly turn)

function getSmoothRotation(rotations)
	
	local targElev = rotations[1];
	local targRot = rotations[2];	
	
	local maxGunDepression = tankStats.GunDepression.Value;
	
	-- Restrict the height of travel of the gun
	if math.abs(targElev) > maxGunDepression then
		targElev = maxGunDepression*sign(targElev);
	end
	
	-- Once target angles are set, slowly turn turret towards them
	-- Elevation
	local elevDiff = targElev - currentElev;
	if math.abs(elevDiff) < 0.01 then -- If they're close
		currentElev = targElev;
	else -- Move towards it
		currentElev = currentElev + 0.01*sign(elevDiff);
	end
	
	-- Rotation
	local rotDiff = targRot - currentRot;
	
	if rotDiff > math.pi then
		rotDiff = rotDiff - 2*math.pi;
	elseif rotDiff < -math.pi then
		rotDiff = rotDiff + 2*math.pi;
	end
	
	local turretSpeed = tankStats.TurretSpeed.Value;
	
	if math.abs(rotDiff) < turretSpeed then -- If they're close
		currentRot = targRot;
	else -- Move towards it
		currentRot = currentRot + turretSpeed*sign(rotDiff);
	end
	
	-- Put rotation and elevation into an array
	local rotations = {};
	rotations[1] = targElev;
	rotations[2] = targRot;
	
	return rotations;
end
