   2D on 3D objects
  I'm looking for a way to draw some 2D sprites which depend on the location of 3d objects in the scene. For instance drawing a box around objects that are targetable. Also along the same lines but not quite the same, I'm looking for a way to have a lead target for a targeted object, a target sign that gives the location of where you need to shoot to hit an object given the objects current orientation and speed and the speed of your projectile. I have some ideas as do how to determine the position in 3d space, and would like to see if I'm close, but I still don't know the best way to place a 2d sprite given that location is determined.If there are any tutorials that are known out there, could you point me in the right direction, or possilbly give me a clue as to how to accomplish this?ThanxVartrigor   
  To convert to 2D, you need to transform the 3D position by your view and projection matrices, then divide the x and y coordinates by the z coordinate. I have the view and projection matrices multiplied together as ViewProj in my project. Here's some code that will convert the coordinate using DirectX matrix math:FLOAT screenx = ViewProj._41 + (pos.x * ViewProj._11) + (pos.y * ViewProj._21) + (pos.z * ViewProj._31);FLOAT screeny = ViewProj._42 + (pos.x * ViewProj._12) + (pos.y * ViewProj._22) + (pos.z * ViewProj._32);FLOAT screenz = ViewProj._43 + (pos.x * ViewProj._13) + (pos.y * ViewProj._23) + (pos.z * ViewProj._33);screenx = ((screenx / screenz) + 1.0f) * 0.5f;screeny = ((screeny / screenz) - 1.0f) * -0.5f;screenx *= Screen_Size_X;screeny *= Screen_Size_Y;screenz = 1.0f;pos = 3D world position to convertScreen_Size_X = Pixel width of the screenScreen_Size_Y = Pixel height of the screenBefore the screenx *= Screen_Size_X; type code, the screen coordinates will be in the range of 0 to 1, being the percentage of the screen. You may prefer that instead of pixels.There is one catch. If the 3D coordinate is behind the camera, it will still return a valid screen coordinate. So you should check for that situation before you use this code. If you have the forward vector of your camera, it's just..FLOAT distance = CameraForwardVector.Dot( pos - CameraPosition );If that distance is less than the near plane distance, don't draw the 2D objects.Hope that helps.   ;Quote:Original post by KestTo convert to 2D, you need to transform the 3D position by your view and projection matrices, then divide the x and y coordinates by the z coordinate. I have the view and projection matrices multiplied together as ViewProj in my project. Here's some code that will convert the coordinate using DirectX matrix math:*** Source Snippet Removed ***pos = 3D world position to convertScreen_Size_X = Pixel width of the screenScreen_Size_Y = Pixel height of the screenBefore the screenx *= Screen_Size_X; type code, the screen coordinates will be in the range of 0 to 1, being the percentage of the screen. You may prefer that instead of pixels.There is one catch. If the 3D coordinate is behind the camera, it will still return a valid screen coordinate. So you should check for that situation before you use this code. If you have the forward vector of your camera, it's just..FLOAT distance = CameraForwardVector.Dot( pos - CameraPosition );If that distance is less than the near plane distance, don't draw the 2D objects.Hope that helps.Yes, this helps immensely, thank you very much