Xna SpriteBatch Matrix.Decompose()
我想要做的是能够将变换矩阵推送和弹出到 SpriteBatch 中。我有 2 个精灵,父级和子级,子级应该相对于父级进行缩放、旋转、平移。
我目前有一个使用纹理四边形的实现,但我认为使用内置的 SpriteBatch 类和使用 Matrix.Decompose() 应该可以实现。不过,我不确定如何将分解后的值传递给 SpriteBatch。
我了解如何保留矩阵堆栈,我只是在寻找将来自 Matrix.Decompose() 的值与 SpriteBatch 结合使用的示例。
What I am looking to do is to be able to push and pop transform matrices into SpriteBatch. I have 2 sprites, parent and child, and the child should be scaled, rotated, translated relative to the parent.
I currently have an implementation using textured quads but I think this should be possible using the built in SpriteBatch class and using Matrix.Decompose(). I'm not sure how to pass the decomposed values to SpriteBatch once I've decomposed them though.
I understand how to keep the matrix stack, I'm just looking for an example of using values coming from Matrix.Decompose() in conjunction with SpriteBatch.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我自己终于弄清楚了这一点。大部分功劳都属于这个 博客文章。
您可以使用此方法来分解您的矩阵:
然后您可以为您的叶精灵构建一个变换矩阵,如下所示:
对于您的父精灵,包括原点:
以相反的顺序乘以堆栈中的所有矩阵。
Figured this one out myself finally. Most of the credit belongs to this blog post though.
You can use this method to decompose your matrix:
You can then build a transform matrix your leaf sprites like so:
For your parent sprites, include the origin:
Multiply by all the matrices in the stack in reverse order.