如何在 XNA4.0 的 3d 世界中渲染我的动画 Texture2D
正如我到目前为止所研究的,在 xna 中绘制有两种方法;使用 spritebatch 或将项目放入 3D 世界,然后使用相机渲染它。
目前,我正在开发 2.5D 游戏。我使用的机制可以使更深的精灵转换得更慢,这样看起来游戏中确实有深度。
然而,考虑到效果,即后处理,如果我想将这些效果渲染到中等深度,即以深度 = 0.5 将其渲染到我的角色上,而在深度 = 0.8 处有一个前景树,则可能会出现一些问题。
因此,我正在考虑在真实的 3D 世界中渲染我的游戏。
然而,由于到目前为止我一直在寻找将我的精灵放置在 3D 世界中并为其设置动画的方法,所以我还没有找到。 (可能是因为我不知道正确的关键字。)我发现的最接近的主题是关于 PointSprite,它现在已从 XNA4.0 中删除,因此我无法以这种方式实现它。
我的问题是,如何在 3D 世界中渲染我的动画精灵(即角色运动)。
谢谢, 圆顶
As I've studied so far, there are 2 ways to draw in xna; using spritebatch or putting items onto the 3d world and then use a camera to render it.
Currently, I'm working on my 2.5D game. I'm using a mechanics that makes the deeper sprite translates slower, so that it looks like there is really depth there in the game.
However, considering effects i.e. postprocessing, it could be some problem if i want to render those effect onto the middle level of depth, i.e. render it onto my character with depth = 0.5, while there is a foreground tree at depth = 0.8.
Thus, I'm considering rendering my game in the real 3D world.
However, since i've searched for the way to put my sprite and animate it in the 3d world so far, I haven't found one. (It might be because I didn't know the correct keywords.) The closest topics I found is about PointSprite, which is now removed from XNA4.0, so I couldn't implement it that way.
My question is, how could I render my animate sprite (i.e. character movement) in 3D world.
Thanks,
Dome
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
诀窍在于你到目前为止所做的事情是excapt,而不是使用spritebatch“直接”绘制到屏幕上,而是将2d图像绘制到3d世界中的平面“纸张”上(每个“纸张”由两个三角形组成一个正方形)。
我建议您查看 create.msdn.com 网站上用于构建四边形、纹理以及可能的渲染目标的示例作为起点。
The trick is to exactly what you've been doing thus far excapt instead of using spritebatch to draw "directly" to the screen, you draw the 2d images onto flat "sheets" in the 3d world instead (with each "sheet" consisting of two triangles to form a square).
I would suggest looking at the samples for building quads, textures and possibly render targets on the create.msdn.com site as a starting point.
XNA 4.0 中的新增功能,SpriteBatch 可与 BasicEffect 结合使用。
这篇博文对此进行了解释。它还提供了一些通过 BasicEffect 模仿默认 SpriteBatch 功能的示例代码 - 但您可以传入自己的 3D 世界矩阵。
具体来说:您的“世界”矩阵将描述 3D 空间中绘制精灵的平面的位置。 “视图”矩阵将描述您的相机的世界视图。 “项目”矩阵将是一个 3D 投影矩阵(可能来自
Matrix.CreatePerspective
)。顺便说一句,您所描述的效果的名称是“视差滚动”。它与真正的 3D 不是一回事(2.5D 也有所不同)。
如果您只想将效果应用于场景中的某些图层:那么您可以通过将带有像素着色器的效果传递给 SpriteBatch.Begin 来直接将效果应用于这些精灵。或者,如果您的效果确实是后处理效果(即:应用于整个屏幕),那么您可以使用渲染目标在屏幕外渲染该特定层,并且然后将其渲染回屏幕并显示您的效果。
New in XNA 4.0, SpriteBatch can be used with BasicEffect.
This blog post explains it. It also provides some sample code that mimics the default SpriteBatch functionality through BasicEffect - but you can pass in your own matrices for a 3D world.
Specifically: your "world" matrix will describe the position of the plane where the sprites are drawn, in 3D space. The "view" matrix will describe your camera's view of the world. And the "project" matrix will be a 3D projection matrix (probably from
Matrix.CreatePerspective
).By the way, the name of the effect you are describing is "parallax scrolling". It is not the same thing as real 3D (and 2.5D is also something different again).
If you want to apply effects to only certain layers in a scene: Well you can either apply the effect to those sprites directly by passing an effect with a pixel shader to SpriteBatch.Begin. Or if your effects really are post-processing effects (ie: apply to the whole screen) then you could use a render target to render that particular layer off-screen, and then render it back to the screen with your effect.