## Viewport aligned billboarding

Zoldar256
Unregistered

Post: #1
NOTE: I got confused on what somebody was asking, wrote all this, and then realized it was unrelated. But why waste? I decided to post it anyways. :-)

Viewport aligned billboards are pretty simple, and really useful for particle systems.

To render something that always appears to face the camera, aka viewport aligned billboarding, the easiest method (I think anyways) is to find the vectors in object space that represent positive x and positive y on the viewport. This can be extracted from the modelview matrix:

So from the modelview matrix the viewport x vector can be thought of as defined by the first 3 elements in the first row, and the y vector as the first 3 elements in the second row. Or in code:

[SOURCECODE]
GLfloat m[16];
glGetFloatv(GL_MODELVIEW_MATRIX, m);
GLVector3 viewX(m[0], m[4], m[8]);
GLVector3 viewY(m[1], m[5], m[9]);
[/SOURCECODE]

Then you can render your billboards using these vectors as the basis vectors for the x and y axis. For instance to render a quad that always faces the camera:

[SOURCECODE]

glVertex3f(position.x, position.y, position.z);

GLVector3 temp = position + viewX;
glVertex3f(temp.x, temp.y, temp.z);

temp = temp + viewY;
glVertex3f(temp.x, temp.y, temp.z);

temp = position + viewY;
glVertex3f(temp.x, temp.y, temp.z);
glEnd();
[/SOURCECODE]