XNA 3.1 multiple sprites with different transform matrices?
I have 2 types of objects, one is 2D and will only face directly forward like a flat image, while the other will be 3D such that it scales and skews according to different rotations. So SpriteBatch.Begin
applies the matrix to everything until I call End
. I read somewhere that I should call Begi开发者_开发知识库n
twice, once to draw the 2D sprites and once to draw the 3D objects but I don't know how I would change the matrix to fit each 3D object's needs and I'm very sad for not remembering what the link was.
So I wish to know how to do this without calling Begin
and End
on every object because that would be disastrous.
The correct solution here is to not use SpriteBatch
for 3D drawing. You should start using the actual 3D drawing API.
SpriteBatch
is merely a convenience layer over the top of the 3D API for 2D sprite drawing. You could, for example, write your own 3D version of SpriteBatch
.
Within SpriteBatch
there is no way to specify more than one transformation matrix to each batch. So if you have to have multiple matrices, you have to have multiple batches (multiple begin/end blocks).
If you're really keen on the SpriteBatch
-based solution, then it is possible to do it that way - so you could try it and see how the performance is.
(You could also do a very ugly hack where you replace the vertex shader, somehow packing the 3D transformation data into each sprite, and then unpacking it in the shader. Ugly. Don't do it. [Edit: also overriding the SpriteBatch
vertex shader is very difficult XNA before 4.0])
精彩评论