World, View and Projection

Started by
2 comments, last by chucara 13 years, 9 months ago
I am messing around with some augmented reality library, which I have working. Now, I don't actually plan to use it for augmented reality, but rather to help me track markers.

Now, the output of the library algorithm is a transformation matrix. What I really need, is screen coordinates.

Now, my question is this:

Given my transformation (World) matrix, my View matrix, my Projection matrix and the Vector3 that is the position of my model, can I get the screen coordinates?

I tried:

Vector3.Transform(Positon, World*Projection*View), but that leaves me with another Vector3.

I'm a but lost here, so any advice you can give is appreciated.

On a second note, should I be using a different library for this? (as in: not an augmented reality library)

I want to create a board game where a projector projects the board and a webcam tracks the pieces. So basically, I just want a plane in 3D space. (I cannot be certain that the webcam and the projector are perfectly aligned*)

*some would even argue that it is a physical impossibility.
Advertisement
You don't mention what API you're using. For C#, you can use Project(viewport,projection,view,world). In DX (C++), D3DXVec3Project(...).

The vector returned has x & y values as screen coordinates (floats which can be converted to integers). The z value is a normalized depth (and can be ignored if you don't need it).

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

Quote:Original post by chucara
I tried:

Vector3.Transform(Positon, World*Projection*View), but that leaves me with another Vector3.
That is the correct approach, though I expect that you need to change the order in which you multiply the matrices.

The x and y coordinates of the result will be screen-space x and y, while the z coordinate will be the depth into the scene. You can safely ignore the z component, and just use x, y as a point in screen coordinates.

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

Indeed.. In XNA, GraphicsDevice.Viewport.Project(...) does the trick.

Thanks for your help!

This topic is closed to new replies.

Advertisement