Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting sprites to face the camera properly in OpenGLES

Tags:

opengl-es

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)
like image 336
Alex Wayne Avatar asked Feb 04 '09 17:02

Alex Wayne


1 Answers

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

like image 193
shoosh Avatar answered Sep 21 '22 05:09

shoosh