Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Pet123

LensFlare_WorldSpace to Screenspace

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

i am now doing the LensFlare effect, to decide whether the ''sun'' is visible or not, i must know the sun''s screen coordinates(in pixels), any one here knows how to do that (converting a point''s location from worldspace to screenspace), thank you.

Share this post


Link to post
Share on other sites
Advertisement
Yeah i wouldnt mind knowing that either, but i think its real easy - bung the world coordinates through all 3 matrices (world, view and projection), and I think out pops the screen coordinates (except they need scaling depending on your screen resolution). Not sure tho, so will tag this post. Any other solutions?

Yratelev

Share this post


Link to post
Share on other sites
hi, Yratelev,
i tried your method to get a 3d-point''s screen coordinates,
i did it this way :
///////////////////////////////////////////////////
D3DXVEC3 PosWorld <-- Sun''s WorldSpace Coordinates
D3DXVEC3 PosScreen <-- Result
D3DXMATRIX MtxWorld; <-- Identity Matrix
D3DXMATRIX MtxCamera; <-- Camrea Matrix
D3DXMATRIX MtxProject; <-- Projection Matrix

/// So the Final Screen Coordinates should be :
///
D3DXMATRIX Mtx = MtxWorld * MtxCamera * MtxProject;
D3DXVec3TransformNormal(&PosScreen, &PosWorld, &Mtx);
///
///////////////////////////////////////////////////
but the Final Result PosScreen is just not right and i dont know what it is.

Share this post


Link to post
Share on other sites
Try D3DXVec3TransformCoord () instead of D3DXVec3TransformNormal ()
I don't know if it'll work, but try.

[Edit] I'm gonna try it too


KaMiKaZe

[edited by - Kamikaze15 on February 13, 2003 11:56:29 AM]

Share this post


Link to post
Share on other sites
It's working for me, here's my code:

void WorldToScreen( D3DXVECTOR3 WorldPos, D3DXVECTOR3 *OutScreen )
{
D3DXMATRIX MatView = pCamera[pCamera_Sel].gGetMatrix(); // Get View Matrix
D3DXMATRIX MatProj = pCamera[pCamera_Sel].gGetProjectionMatrix(); // Get Projection Matrix
D3DXMATRIX MatTmp = MatView*MatProj;

D3DXVec3TransformCoord( OutScreen, &WorldPos, &MatTmp );
}

The values of OutScreen are between -1.0f and 1.0f if the point is inside the screen

Oh, I use Right Handed coords system...

[Edit:] Corrected one bad comment line


KaMiKaZe

[edited by - Kamikaze15 on February 13, 2003 12:14:54 PM]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!