# Vector3.Project

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

## Recommended Posts

Hi, As handy as Project can be it seems tricky to use correctly. Im trying to determine the length of a world space vector in screen space. I assume that Project treat the Vector3 as a point and projects that into screen space. Something like this is the code for projecting a single point. Matrix world = ...; Matrix view = Matrix.LookAt(...; Matrix projection = Matrix.PerspectiveFovLH(...; Viewport vp = device.Viewport; Vector3 point = ...; point.Project(vp,projection,view,world); Now... this i would expect to produce coordinates in the ranges point.X in [-1,1] point.Y in [-1,1] point.Z in [0,1] However this does not seem to be the result. Does anyone know what exactly is the output of the method ? Is it screen space coordinates without perspective division ?

##### Share on other sites
Hum, I didn't play with project for a long time, so I might not remember correctly, but :

it project your point from world space into screen space. The origin (the <0, 0> point) of the screenspace is the upper-left corner, and the bottom-right corner correspond to the point <viewport.Width, viewport.Height>

So when you project something, you get results like :

X in [0, viewport.Width]
Y in [0, viewport.Height]
Z in [viewport.MinZ, viewport.MaxZ] (I'm not sure for this one, but anyway, you never use it ^^)

I hope it helps.

##### Share on other sites
Quote:
 Original post by paicZ in [viewport.MinZ, viewport.MaxZ] (I'm not sure for this one, but anyway, you never use it ^^)

Z would be in the range of [0..1].

@ OP: I think providing a null for the Viewport might get you results in the ranges you expect, so it's worth a try. On the other hand, it might not work at all :).

Hope this helps.

##### Share on other sites
Actually the z-value is explained in the documentation, the others are'nt.

EDIT: I think u are right, when u say the screen values given are
x in [0,vp.Width]
y in [0,vp.Height]
for a Viewport, vp.

• 14
• 12
• 23
• 10
• 19
×

## Important Information

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!