Viewport aligned billboarding
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]
glBegin(GL_QUADS);
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]
Anyways, I should really make a tutorial about this. Got all this fireworks code lying about....
Hope this helps somebody! :-)
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]
glBegin(GL_QUADS);
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]
Anyways, I should really make a tutorial about this. Got all this fireworks code lying about....
Hope this helps somebody! :-)
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| Vertex shader particle billboarding question | TomorrowPlusX | 3 | 4,823 |
Sep 15, 2008 06:46 AM Last Post: TomorrowPlusX |
|
| How to set Two viewport in OpenGL? | creater16 | 18 | 7,962 |
Aug 4, 2005 12:19 PM Last Post: unknown |
|
| billboarding question | rhiannon | 5 | 3,168 |
Mar 11, 2005 02:13 PM Last Post: OneSadCookie |
|
| billboarding techniques | ghettotek | 2 | 3,096 |
Feb 16, 2003 10:28 PM Last Post: OneSadCookie |
|

