XNA 3.1 多个精灵具有不同的变换矩阵?
我有两种类型的对象,一种是 2D 的,只会像平面图像一样直接面向前方,而另一种是 3D 的,它会根据不同的旋转进行缩放和倾斜。因此,SpriteBatch.Begin
将矩阵应用于所有内容,直到我调用 End
。我在某处读到我应该调用 Begin
两次,一次绘制 2D 精灵,一次绘制 3D 对象,但我不知道如何更改矩阵以满足每个 3D 对象的需求,我我很遗憾不记得链接是什么。
所以我想知道如何在不对每个对象调用 Begin
和 End
的情况下做到这一点,因为那将是灾难性的。
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 Begin
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这里正确的解决方案是不使用
SpriteBatch
进行 3D 绘图。 您应该开始使用实际的 3D 绘图 API。SpriteBatch
只是用于 2D sprite 绘图的 3D API 之上的一个便利层。例如,您可以编写自己的 3D 版本的SpriteBatch
。在
SpriteBatch
中,无法为每个批次指定多个变换矩阵。因此,如果您必须有多个矩阵,则必须有多个批次(多个开始/结束块)。如果您真的热衷于基于
SpriteBatch
的解决方案,那么可能可以这样做 - 所以您可以尝试一下并看看表现如何。(你也可以做一个非常丑陋的黑客,你替换顶点着色器,以某种方式将 3D 转换数据打包到每个精灵中,然后在着色器中将其解包。丑陋。不要这样做。[编辑:也覆盖
SpriteBatch
顶点着色器在 4.0 之前的 XNA 非常困难])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 ofSpriteBatch
.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])