在OpenGLES中让精灵正确面对相机 [英] Getting sprites to face the camera properly in OpenGLES

查看:108
本文介绍了在OpenGLES中让精灵正确面对相机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个或多或少的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:

  1. 完全方形且面向相机,但不需要我移动相机即可实现.
  2. 其大小受距相机的距离影响(不同于点精灵)

推荐答案

您可以使用始终面向镜头的多边形来实现所需的功能.这称为广告牌". 这是一个不错的教程,它似乎在解释所涉及的数学以及如何使用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中让精灵正确面对相机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆