Sunday, 26 May 2013

How to translate 3D-Coordinates to 2D with Viewport.Project?

How to translate 3D-Coordinates to 2D with Viewport.Project?

My 3D Hero-Model is positioned at a certain point in 3D-Coordinates. Whenever he's colliding with a coin, I want to place an animated sprite sheet there (where they collided). But my following implementation won't give me useful result.
Could you assist me with this?
PerspectiveCamera _cam = new PerspectiveCamera();
Viewport vP = GraphicDevice.Viewport;
Vector3 unitPos = modelPos.LocalPosition;

Vector3 screenSpace = vP.Project(unitPos, _cam.Projection, _cam.View, Matrix.Identity);
MySprite sprite = new MySprite(unitPos.X, unitPos.Y);

//... Won't draw sprite where the model is

No comments:

Post a Comment