C# DirectX - World Coordinates to Screen Coodinates for sprite overlay
Aloha all
I'm having trouble finding a good method for converting world space coordinates into screen space coordinates.
My situation is this: When a players projectile hits an object, I want a cloud of smoke (my sprite) to appear on screen at the point of intersection. I don't need fancy scaling code or anything, as my game has a 2.5D overhead view point, and I already know my intersection point. I just need to convert it (a vector3) to it's on screen coordinates.
I've been browsing the net most of the evening, and most of the guides I found were for raytracing a point from screen space to world space. Any others were overcomplicated, or contradicted with other "useful" articles I had found. I did find a useful article on the D3DXVec3Project function, but I don't believe I can use it in c#. I also found some info on multiplying my world position by my wvp matrix, but it wasn't clear on the actual maths involved.
Can anybody help me out?
Cheers all
[Edited by - FoDDa on July 10, 2008 8:32:17 AM]
It's pretty simple:
[Edited by - MJP on July 10, 2008 2:02:11 PM]
Vector2 WorldSpaceToScreenSpace(Vector3 worldSpacePos){ Vector4 clipSpacePos = Vector4.Transform(new Vector4(worldSpacePos, 1.0f), viewProjMatrix); Vector2 screenSpacePos; screenSpacePos.x = (clipSpacePos.x / clipSpacePos.w) * 0.5f + 0.5f; screenSpacePos.y = 1.0f - ((clipSpacePos.y / clipSpacePos.w) * 0.5f + 0.5f); screenSpacePos.x *= viewPortWidth; screenSpacePos.y *= viewPortHeight; return screenSpacePos;}
[Edited by - MJP on July 10, 2008 2:02:11 PM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement