Ok, I know this is a noob question.. but with 3D I'm a noob so, well..
How do you calculate the screen-coordinates of a 3d vector?
And then I mean exactly how, because I know that it probably "has something to do with multiplying your world, view, and projection matrices with it" but that's not exactly it.. or is it..?
[XNA] screencoordinates
Moderator: MaxCoderz Staff
I am answering this with only 3D experience, no XNA experience.
But usually aren't 3D vectors attached to the origin? Usually I have never seen them used for displaying anything on the screen, but more so for an intermediate data format for calculations.
Why do you need to display it on screen though?
But usually aren't 3D vectors attached to the origin? Usually I have never seen them used for displaying anything on the screen, but more so for an intermediate data format for calculations.
Why do you need to display it on screen though?
-
- Calc King
- Posts: 1513
- Joined: Sat 05 Aug, 2006 7:22 am
- benryves
- Maxcoderz Staff
- Posts: 3087
- Joined: Thu 16 Dec, 2004 10:06 pm
- Location: Croydon, England
- Contact:
A matrix represents a transformation of some sort (it could be translation, rotation, skewing, whatever you want really). You can combine matrices by multiplying them.
I'm not sure how you've structured your vertex shader and are setting the matrices, but assuming you're using world (moving an object to its location in the world), view (translating and rotating around the camera) and projection ("project" a 3D point to 2D and depth buffer information) then you can just multiply them together (and your point) and you'll get the screen position out (though to get absolute coordinates you'll need to scale and offset by the backbuffer dimensions).
The quick answer, however, is to look up billboarded sprites and render them normally in 3D rather than using a 2D workaround. (Matrix.CreateBillboard).
I'm not sure how you've structured your vertex shader and are setting the matrices, but assuming you're using world (moving an object to its location in the world), view (translating and rotating around the camera) and projection ("project" a 3D point to 2D and depth buffer information) then you can just multiply them together (and your point) and you'll get the screen position out (though to get absolute coordinates you'll need to scale and offset by the backbuffer dimensions).
The quick answer, however, is to look up billboarded sprites and render them normally in 3D rather than using a 2D workaround. (Matrix.CreateBillboard).
-
- Calc King
- Posts: 1513
- Joined: Sat 05 Aug, 2006 7:22 am
- benryves
- Maxcoderz Staff
- Posts: 3087
- Joined: Thu 16 Dec, 2004 10:06 pm
- Location: Croydon, England
- Contact:
SpriteBatch is rather more complicated in my experience, as it tends to mess up renderstates. Using billboards is exactly what you seem to need to do; drawing 2D sprites in 3D locations.King Harold wrote:Billboarding is a bit complicated though..
I'd rather let the SpriteBatch deal with the trouble and only have to calculate a few coordinates
Should be, depends on how you're dealing with all the other vertices in your vertex shader. I'm not sure of the exact values output by the projection matrices that D3D generates, but I'm guessing they'll be normalised (in X and Y). You should be able to guess with a bit of debugging...So is that just
world * view * projection * point
and then do some magic to scale/offset it?
-
- Calc King
- Posts: 1513
- Joined: Sat 05 Aug, 2006 7:22 am
It has a savestate option, I don't know how well it works though, but for what I'm doing it doesn't matter much really..benryves wrote:SpriteBatch is rather more complicated in my experience, as it tends to mess up renderstates. Using billboards is exactly what you seem to need to do; drawing 2D sprites in 3D locations.King Harold wrote:Billboarding is a bit complicated though..
I'd rather let the SpriteBatch deal with the trouble and only have to calculate a few coordinates
I'll try it, but probably not today (have to finish reversi today, for Imperative Programming)benryves wrote:Should be, depends on how you're dealing with all the other vertices in your vertex shader. I'm not sure of the exact values output by the projection matrices that D3D generates, but I'm guessing they'll be normalised (in X and Y). You should be able to guess with a bit of debugging...