Spritebatch.Begin() Transform Matrix

前端 未结 1 616
轻奢々
轻奢々 2021-01-15 13:36

I have been wondering for a while about how the transform matrix in spriteBatch is implemented. I\'ve created a 2D camera, and the transform matrix is as follows:

         


        
1条回答
  •  孤街浪徒
    2021-01-15 14:16

    I see you've answered your own question, but to provide complete information - SpriteBatch provides a similar interface to the traditional world-view-projection system of transformations.

    The SpriteBatch class has an implicit projection matrix that takes coordinates in the "client space" of the viewport ((0,0) at the top left, one unit per pixel) and puts them on screen.

    The Begin call has an overload that accepts a transformation matrix, which is the equivalent of a view matrix used for moving the camera around.

    And the Draw call, while not actually using a matrix, allows you to specify position, rotation, scale, etc - equivalent to a world matrix used for positioning a model in the scene (model space to world space).

    So you start with your "model" equivalent - which for SpriteBatch is a quad (sprite) of the size of the texture (or source rectangle). When drawn, that quad is transformed to its world coordinates, then that is transformed to its view coordinates, and then finally that is transformed to its projection coordinates.

    0 讨论(0)
提交回复
热议问题