Skip to content

Instantly share code, notes, and snippets.

@satoruhiga
Created July 17, 2011 09:17
Show Gist options
  • Save satoruhiga/1087392 to your computer and use it in GitHub Desktop.
Save satoruhiga/1087392 to your computer and use it in GitHub Desktop.
OpenGL Billboard
// http://marina.sys.wakayama-u.ac.jp/~tokoi/?date=20110221
inline void billboard()
{
GLfloat m[16];
glGetFloatv(GL_MODELVIEW_MATRIX, m);
float inv_len;
m[8] = -m[12];
m[9] = -m[13];
m[10] = -m[14];
inv_len = 1. / sqrt(m[8] * m[8] + m[9] * m[9] + m[10] * m[10]);
m[8] *= inv_len;
m[9] *= inv_len;
m[10] *= inv_len;
m[0] = -m[14];
m[1] = 0.0;
m[2] = m[12];
inv_len = 1. / sqrt(m[0] * m[0] + m[1] * m[1] + m[2] * m[2]);
m[0] *= inv_len;
m[1] *= inv_len;
m[2] *= inv_len;
m[4] = m[9] * m[2] - m[10] * m[1];
m[5] = m[10] * m[0] - m[8] * m[2];
m[6] = m[8] * m[1] - m[9] * m[0];
glLoadMatrixf(m);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment