Synopsis: What I have is an object rendered on the screen. I need to calculate the top-left / bottom-right of it's location on the screen in Screen Coordinates.
Explanation: The object is basically a box that I'm trying to draw sprite textures into at specific locations, but due to the screen resolution being a variable (dependent on player settings), I can't hard-code in these translations. So what I need to do is find out what the bounding box of the object is in Screen-Coordinates. Once I know the bounding box, I can calculate the offsets to the positions within it.
I can calculate the center position of the box already with a function I scavenged:
public Vector2 GetScreenPoint(Matrix objMatrix) { Matrix mat = objMatrix * mCamera.mViewMatrix * mCamera.mProjMatrix; Vector4 v4 = Vector4.Transform(new Vector3(0, 0, 0), mat); return new Vector2((int)((v4.X / v4.W + 1) * (pGame.GraphicsDevice.PresentationParameters.BackBufferWidth / 2)), (int)((1 - v4.Y / v4.W) * (pGame.GraphicsDevice.PresentationParameters.BackBufferHeight / 2))); } But now I need to go from that to the actual extents of the bounding box. I've tried converting the BoundingSphere of the model into a BoundingBox and then translating the object matrix by the BoundingBox.Min values, but I'm nowhere near the left side of the object.
Am I going about this backwards, or what am I not seeing? This would seem a simple enough thing to do, but I just can't figure it out. Or is there a complete different way I should be approaching this?