# C# DirectX - World Coordinates to Screen Coodinates for sprite overlay

This topic is 3848 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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]

bumpedy bump!

##### Share on other sites
It's pretty simple:

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]

##### Share on other sites
thanks very much for that, I'll give it a try when I get home :)

##### Share on other sites
worked like a charm ;)

thanks for taking the time to help me out :)

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 15
• 11
• 9
• 9
• 42
• ### Forum Statistics

• Total Topics
634131
• Total Posts
3015716
×