问题描述
我有一个或多或少是 2D 的游戏,但以 3D 呈现.摄像机悬停在 2D 游戏场上方,从完全垂直的角度倾斜约 20 度,以提供一点 3D 视角.
I have a game that is more or less 2D, but rendered in 3D. The camera hovers above the 2D game field tilted about 20 degrees from perfectly perpendicular to give a little 3D perspective to it.
我有一些精灵需要被渲染成完全正方形,因为它们代表球形物体.我的第一种方法将四边形平铺在 2D 场上,从而正确定位它们,但精灵会受到透视失真的影响,而且看起来并不总是圆的.
I have some sprites that need to be rendered perfectly square, because they represent spherical objects. My first approach rendered quads flat on the 2D field which positioned them properly, but the sprite was subject to perspective distortion and it didn't always look round.
我目前的方法是,在渲染精灵时,我将相机移动到垂直于游戏场(和精灵),以保证四边形永远不会因透视而失真.缺点是精灵的位置与相机倾斜时的位置略有不同.
My current approach is that when rendering the sprites I move the camera to be perpendicular to the game field (and the sprites) which guarantees that the quads are never distorted by perspective. The drawback being that the position of the sprites is slightly different from where they would be if the camera was tilted.
那么,我怎样才能渲染精灵:
So, how can I render sprites that are:
- 完全正方形且面向相机,但不需要我移动相机即可实现这一点.
- 具有受与相机距离影响的大小(与点精灵不同)
推荐答案
您可以使用始终面向相机的多边形来实现您想要的效果.这被称为广告牌".这里是一个很好的教程,它似乎解释了所涉及的数学以及如何使用 OpenGL 实现它
You can achieve what you want using a polygon which faces the camera at all times. This is called a "billboard". Here is a nice tutorial which seems to explain the math involved and how to implement it using OpenGL
这篇关于在 OpenGLES 中让精灵正确面对相机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!