Billboarding

Started by
15 comments, last by ATronic 22 years, 5 months ago
Hey, I''ve been using the following function for billboarding.
  
void teBillboard()
{
	float temp[16]={1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, m[16];
	glGetFloatv(GL_MODELVIEW_MATRIX, m);
	temp[0]=m[0];
	temp[1]=m[4];
	temp[2]=m[8];
	temp[4]=m[1];
	temp[5]=m[5];
	temp[6]=m[9];
	temp[8]=m[2];
	temp[9]=m[6];
	temp[10]=m[10];
	glMultMatrixf(temp);
}
  
It works fine asside from one problem. It makes the particles face the camera AND eliminates all effects of rotation. It should make them face the camera, but is there a way to do this with the particles being in the resulting rotated position?
Alex BroadwinA-Tronic Software & Design-----"if you fail in life, you were destined to fail. If you suceed in life, call me.""The answer is out there.""Please help, I'm using Windows!"
Advertisement
I think you are missing the whole point with billboarding here!
You use billboarding to make the particles always face the camera, and that will make it a little hard to rotate them!



- -- ---[XaOs]--- -- -

[ project fy ]
- -- ---[XaOs]--- -- -[ Project fy ||| CyberTux ]
You don''t see what I''m saying. When I rotate the camera, everything moves exept the particles. I WANT them to face the camera, but to have their center position moved. Understand what I''m saying? I just want to know if that is possible.

Alex Broadwin
A-Tronic Software & Design
-----
"if you fail in life, you were destined to fail. If you suceed in life, call me."
"The answer is out there."
"Please help, I''m using Windows!"
Alex BroadwinA-Tronic Software & Design-----"if you fail in life, you were destined to fail. If you suceed in life, call me.""The answer is out there.""Please help, I'm using Windows!"
When you multiply the current matrix by your "temp" matrix, you lose all translation informations.

Try this one instead :

  float temp[16]={ 1.0f, 0.0f, 0.0f, 1.0f,                  0.0f, 1.0f, 0.0f, 1.0f,                  0.0f, 0.0f, 1.0f, 1.0f,                  0.0f, 0.0f, 0.0f, 1.0f}   
I''m afraid that one just kills everything. When I use your temp it makes the particles all stretch from the center of the screen out to the lower left corner of the screen. I think you messed up somewhere.

Alex Broadwin
A-Tronic Software & Design
-----
"if you fail in life, you were destined to fail. If you suceed in life, call me."
"The answer is out there."
"Please help, I''m using Windows!"
Alex BroadwinA-Tronic Software & Design-----"if you fail in life, you were destined to fail. If you suceed in life, call me.""The answer is out there.""Please help, I'm using Windows!"
I have found this works fine for me:

float m[16];

glGetFloatv(GL_MODELVIEW_MATRIX, m);
glPushMatrix();
glLoadIdentity();
glTranslatef(m[12],m[13],m[14]);

... draw particle ...

glPopMatrix();


I suppose you could glLoadMatrix(m) at the end instead of the push/pop but I think the card probably does it faster than sending 16 floats...




you do that for EVERY particle? Yikes! Overhead must be INSANE.

Alex Broadwin
A-Tronic Software & Design
-----
"if you fail in life, you were destined to fail. If you suceed in life, call me."
"The answer is out there."
"Please help, I''m using Windows!"
Alex BroadwinA-Tronic Software & Design-----"if you fail in life, you were destined to fail. If you suceed in life, call me.""The answer is out there.""Please help, I'm using Windows!"
OK what you need to do is NOT invert the 4th column of the matrix. I think how to do that is get the transformation matrix, then set everything to identity except the fourth column. This will reset all rotation and scaling to none (hopefully) giving you a quick billboard.

I read that somewhere on the Internet but I can''t find it now.
Yeah, it kinda seems that way, eh? Is there a better technique? If you''ve got a bunch of seperate items that all need to point back at the camera, I can''t think any method will get around having to do a bunch of work each particle.

It''s not that bad, really. It''s all internal to the card ''cept for the get matrix call and the translate.
My way you just call once, then draw all particles, then pop the matrix. Simple enough. But I think I''m inverting part I should not be.... I''ll figure it out soon enough.

Alex Broadwin
A-Tronic Software & Design
-----
"if you fail in life, you were destined to fail. If you suceed in life, call me."
"The answer is out there."
"Please help, I''m using Windows!"
Alex BroadwinA-Tronic Software & Design-----"if you fail in life, you were destined to fail. If you suceed in life, call me.""The answer is out there.""Please help, I'm using Windows!"

This topic is closed to new replies.

Advertisement