Sign in to follow this  
sune

Vector3.Project

Recommended Posts

sune    122
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 this post


Link to post
Share on other sites
paic    645
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 this post


Link to post
Share on other sites
sirob    1181
Quote:
Original post by paic
Z 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 this post


Link to post
Share on other sites
sune    122
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.

Thank you for the answers

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this