Problem with billboarding

This is a discussion on Problem with billboarding within the Game Programming forums, part of the General Programming Boards category; I've tried getting billboarding to work, it seems easy enough, but no matter what I do it doesn't actually work. ...

  1. #1
    Banned
    Join Date
    Jan 2003
    Posts
    1,708

    Problem with billboarding

    I've tried getting billboarding to work, it seems easy enough, but no matter what I do it doesn't actually work. The bitmaps seem to somewhat turn with the camera but they are never actually completely perpendicular.

    Here is what I have so far, what am I doing wrong? It's probably something incredibly obvious.

    Code:
    void	Meteor::CallDraw(){
    	red = (int)rand()%255;
    	green = (int)rand()%255;
    	blue = (int)rand()%255;
    	float scale = 10;
    	float	MVMAT[16];
    	glGetFloatv(GL_MODELVIEW_MATRIX, &MVMAT[0]);
    	
    	//FIXME: I don't know if I need the transpose or what is going on here
    	Vector	up(MVMAT[0], MVMAT[1], MVMAT[2]);
    	Vector	right(MVMAT[4], MVMAT[5], MVMAT[6]);
    	
    	glPushMatrix();
    	glDisable(GL_LIGHTING);
    	glEnable(GL_BLEND);	
    	glBindTexture(GL_TEXTURE_2D, texture);		//THIS IS ACTUALLY THE PARTICLE TEXTURE, hmmm?
    	glTranslatef(Position.x, Position.y, Position.z);
    	glColor4ub(red, green, blue, transparency);
    	glBegin(GL_QUADS);
    	glTexCoord2f(0.0f, 0.0f);
    glVertex3f(Position.x + (up.x + right.x) * -scale, Position.y + (up.y + right.y) * -scale, Position.z);
    	glTexCoord2f(1.0f, 0.0f);
    glVertex3f(Position.x + (-up.x + right.x) * scale, Position.y + (-up.y + right.y) * scale, Position.z); 
    	glTexCoord2f(1.0f, 1.0f);
    glVertex3f(Position.x + (up.x + right.x) * scale, Position.y + (up.y + right.y) * scale, Position.z);
    	glTexCoord2f(0.0f, 1.0f);
    glVertex3f(Position.x + (up.x + -right.x) * scale, Position.y + (up.y + -right.y) * scale, Position.z);
    	glEnd();
    	glDisable(GL_BLEND);
    	glEnable(GL_LIGHTING);
    	glPopMatrix();
    }
    I have tried using what the original model view matrix would be and what the transpose would be. i.e:
    Vector up(MVMAT[0], MVMAT[1], MVMAT[2]);
    Vector right(MVMAT[4], MVMAT[5], MVMAT[6]);

  2. #2
    Registered User
    Join Date
    Sep 2002
    Posts
    1,640
    Oke, This bill board, It's a quad with a texture on it? And it
    always faces the screen, When is always? Can you walk around
    in space and it always faces you or?

  3. #3
    Banned
    Join Date
    Jan 2003
    Posts
    1,708
    yes, that's what billboarding does. what's really supposed to happen is you're supposed to reverse the effects of the model view matrix by multiplying by its inverse. Instead (from ogl game programming) you can get the current up and right vectors from the modelview matrix, and use those to create the texture mapped quad. If you use components from the up and right vectors from the modelview matrix to set the vertices of the quad then the quad will always be facing the camera. I know I'm prolly doing something really stupid wrong. fuk

  4. #4
    Registered User
    Join Date
    Sep 2002
    Posts
    1,640
    Wooow!!! Cut down on the expensive talk!
    What exactly are you trying at accomplish?

  5. #5
    Banned
    Join Date
    Jan 2003
    Posts
    1,708
    BILLBOARDING
    UGG
    BITMAP ALWAYS FACE VIEWER

  6. #6
    Registered User
    Join Date
    Sep 2002
    Posts
    1,640
    You left your caps-lock on,
    Never knew that was called billboarding well, Why go through
    all the fuss for something simple like that? If i'm not mistaken,
    You can use orthographic graphics for 2D things like billboards,
    Otherwise just use a simple quad and keep track of any rotation
    and apply to reverse of any rotation to the billboard.

  7. #7
    Banned
    Join Date
    Jan 2003
    Posts
    1,708
    you can't have a z component when you go into 2d ortho mode therefore that will not work, and this is actually the simplest method. i was hoping someone who had already done billboarding could check this out and correct me where i am wrong.

  8. #8
    Registered User
    Join Date
    Sep 2002
    Posts
    1,640
    No, I haven't done it before, But it seems easy to me. Can't you
    scale it in any way to accomplish some form of depth?

  9. #9
    Banned
    Join Date
    Jan 2003
    Posts
    1,708
    nein don quijote

  10. #10
    Registered User
    Join Date
    Sep 2002
    Posts
    1,640
    Right, Well at first sight your code seems fine, But i can't tell if
    it would work or not since i have a far different and more brute
    force approach.

  11. #11
    Banned
    Join Date
    Jan 2003
    Posts
    1,708
    do you have something that works that you could show me

  12. #12
    Registered User
    Join Date
    Sep 2002
    Posts
    1,640
    Not really, As i said i haven't done anything yet like that before.

  13. #13
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    try this....
    Code:
    Vector up(MVMAT[0], MVMAT[4], MVMAT[8]);
    Vector right(MVMAT[1], MVMAT[5], MVMAT[9]);
    
    // matrix might look like this
    
    0  1  2   3
    4  5  6   7
    8  9 10 11

  14. #14
    Banned
    Join Date
    Jan 2003
    Posts
    1,708
    I have tried using what the original model view matrix would be and what the transpose would be. i.e:
    Vector up(MVMAT[0], MVMAT[1], MVMAT[2]);
    Vector right(MVMAT[4], MVMAT[5], MVMAT[6]);
    anyway I think the problem was because
    1) I am a dumbass
    2) I left out the Z component of the billbaord. I left my laptop at school though so I can't finish it.


    EDIT: well I got it working, that's what the problem was, no biggie. I'll post it sometime when I've made some more updates, if you want.

    travis you should help me think of ideas for this game, i.e I was thinking of having the weapons be billboarded bitmaps that travel in a sine wave, just like the railgun from quake II. You should help me think of stuff like that.
    Last edited by Silvercord; 02-25-2003 at 12:09 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding a problem
    By dnguyen1022 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2009, 05:21 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 09:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 03:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 07:54 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21