Getting sprites to face the camera properly in OpenGLES

ぃ、小莉子 提交于 2019-12-30 06:42:26

问题


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.

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. Perfectly square and camera facing but does not require me to move my camera to achieve this.
  2. Have a size that is affected by distance from the camera (unlike point sprites)

回答1:


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




回答2:


Draw the quads perpendicular to the camera as you suggest, but position them a little above the field. The distance above should probably be the radius of the sphere.




回答3:


you can still use point sprites...using glPointParameter() you can give it depth attenuation. i'm currently using 0.00025 for my depth attenuation for my particle system i have in development. the down-side is that on the 1st gen machines (i assume you're doing this for the iphone or ipod touch) you'll be stuck with a max sprite size of 64x64 pixels



来源:https://stackoverflow.com/questions/512326/getting-sprites-to-face-the-camera-properly-in-opengles

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!