Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm working in XNA on a 2d isometric world/game and I'm using DrawUserPrimitives to draw some geometric figures...

I saw some tutorials about creating dynamic shadows but I didn't understood why they use a "3d" matrix to control the transformations since the figure I'm drawing is in 2d perspective.

I know I'm drawing a 2d figure in 3d but I still can't understand if I really need to work with the matrix.

Is there any advantage in using a 3d Matrix to control camera and view?

Any reason why I can't just update my vertex's positions by using a regular method since the view is always the same... And since I want to work only with single figures, won't this cause all the geometric figures have the same transformations simultaneously?

To understand better what I mean here's a video http://www.youtube.com/watch?v=LjvsGHXaGEA&feature=player_embedded

share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

Is there any advantage in using a 3d Matrix to control camera and view?

You don't have a choice. It's not really about advantage or disadvantage; it's the only way to go.

XNA doesn't have a 2D graphics API; it's rendering API is only 3D. You can implement 2D in terms of 3D by simply only considering your X and Y dimensions, and you can abstract this out to provide wrapper interfaces that look like they are fully 2D, but in order to submit any kind of rendering operations to the XNA API you're going to have to speak it's language (the language of the underlying Direct3D implementation), which is 3D.

Any reason why I can't just update my vertex's positions by using a regular method since the view is always the same... And since I want to work only with single figures, won't this cause all the geometric figures have the same transformations simultaneously?

Constantly updating the vertex buffer every frame is less efficient, because that data must be copied back and forth to the GPU repeatedly. Conversely, initializing your vertex buffer once and simply transforming it on the GPU is much more efficient.

share|improve this answer
    
But right now Im updating my triangles vertex positions just by changing the value of the VertexPositionColor array and its working fine on drawing. I'm not working with any matrix or camera. What kind of rendering options are you talking about? This works fine if you have order vertexes but maybe with more vertexes/arrys won't work because you won't know where to apply the changes(???) –  Navy Seal Jul 2 '12 at 22:21
    
I don't understand what you mean, but I've edited my answer to point that constantly updating a vertex buffer is less efficient than alternatives. –  Josh Petrie Jul 2 '12 at 23:16
    
To clarify: even with DrawUserPrimitives a matrix is going to be faster. Reason why is that offsetting the position values in a system memory array is still happening on the CPU, whereas sending a matrix to the GPU allows the calculation to happen on the GPU - which is much much much faster (and more parallel) at this kind of operation than the CPU. So despite more calculations happening, they're happening on the faster processor and getting much better parallelism - hence: win. If your geometry is static a matrix will also allow you to use a static vertex buffer for even more win. –  Jimmy Shelter Jul 3 '12 at 23:45
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.