Transforming a 3D position to a screen (2D) position
Hi
I'm trying to transform a 3D spacial position to a 2D screen one (I'm looking to align various sprites to 3D objects rendered on the screen).
The following codekind ofworks although It does not align directly. I'm probably missing something somewhere. Any help/advice appreciated!
Vector3 v =Vector3.Transform(Player.Position, ProjectionMatrix);v =Vector3.Transform(v, ViewMatrix);
Vector2 p =newVector2(v.X/2, -v.Y/2);
spriteBatch.Draw(Textures["white1x1"],newRectangle(640+(int)p.X, 360+(int)p.Y, 32, 32),Color.White);
Its the...
Vector2 p =newVector2(v.X/2, -v.Y/2);
Code line that confuses me. Why I have to halve the X & Y values (including negating Y) to get it close to the 3D object on screen (a Player object).
Any help or advice on accurately working out 3D object screen co-ordinates much appreciated!
BTW... The view an projection matrices are set up as follows...
privatevoid InitializeTransform(){
viewMatrix =
Matrix.CreateLookAt(CameraPosition,
CameraLookAt,
CameraUpVector
);
projectionMatrix =
Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45),(
float)GraphicsDevice.Viewport.Width / (float)GraphicsDevice.Viewport.Height,1.0f, 10000.0f);
}

