#### Archived

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

# 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.

## 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 on other sites
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 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 on other sites
hmmmm not sure.... actually, i have no idea then!

Yratelev

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

 I'm gonna try it too

KaMiKaZe

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

##### 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]

1. 1
Rutin
69
2. 2
3. 3
4. 4
5. 5

• 21
• 10
• 33
• 20
• 9
• ### Forum Statistics

• Total Topics
633430
• Total Posts
3011831
• ### Who's Online (See full list)

There are no registered users currently online

×