Mike
I couldn't get your method to work properly, however I've found another way which works:
Here's how to do it, for anyone interested. Obviously the function needs tweaking for your own engine to pass in matrixes and viewport sizes. However, this code works a treat:
public static Point Convert3DPointTo2D(Vector3 point, XNAViewPort objVP)
{
Vector4 result4 = Vector4.Transform(point,
objVP.MatrixView * objVP.MatrixProjection);
if (result4.W == 0)
result4.W = 0.000001f;
Vector3 result = new Vector3(
result4.X / result4.W,
result4.Y / result4.W,
result4.Z / result4.W);
return new Point(
(int)Math.Round(+result.X * (800 / 2)) + (800 / 2)+100,
(int)Math.Round(-result.Y * (600 / 2)) + (600 / 2)+100);
}
I can't take credit for this code as it was modified from the rocket commander source code
