Viewport aligned billboarding

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:

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

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:


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);

Anyways, I should really make a tutorial about this. Got all this fireworks code lying about....

Hope this helps somebody! :-)
Quote this message in a reply
Post: #2
It is much better to post these informative blurbs straight to the FAQ. I will put it there myself now.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Vertex shader particle billboarding question TomorrowPlusX 3 7,896 Sep 15, 2008 06:46 AM
Last Post: TomorrowPlusX
  How to set Two viewport in OpenGL? creater16 18 16,024 Aug 4, 2005 12:19 PM
Last Post: unknown
  billboarding question rhiannon 5 5,181 Mar 11, 2005 02:13 PM
Last Post: OneSadCookie
  billboarding techniques ghettotek 2 4,913 Feb 16, 2003 10:28 PM
Last Post: OneSadCookie