static private Dir vec3ToDir(Vec3 pos)
{
/* XXX: Only check axis X and Z */
int[] axisOrder = { 0, 2 };
Dir[,] perAxis =
{
{ Dir.Left, Dir.Right },
{ Dir.Bottom, Dir.Top },
{ Dir.Back, Dir.Front },
};
float absDist = 0.0f;
Dir d = Dir.None;
/* Select the direction of the axis with the greater distance, so the
* entity will follow the last position of the targeted object */
for (int i = 0; i < axisOrder.Length; i++)
{
int axis = axisOrder[i];
if (Math.Abs(pos[axis]) > absDist)
{
absDist = Math.Abs(pos[axis]);
if (pos[axis] < 0)
{
d = perAxis[axis, 0];
}
else if (pos[axis] > 0)
{
d = perAxis[axis, 1];
}
}
}
return(d);
}