GLProgramming.com

home :: about :: development guides :: irc :: forums :: search :: paste :: links :: contribute :: code dump

-> Click here to learn how to get live help <-


New Paste :: Recent Pastes:: No Line Numbers


billboarding by JazzD
1
 
void DrawBillboard(float x , float y , float z,float scale, GLuint texture)
{
    float mat[16];
    float size = scale;

    glGetFloatv(GL_MODELVIEW_MATRIX, mat);

    CVector3 pos(x,y,z);
    CVector3 right(mat[0],mat[4], mat[8]);
    CVector3 up(mat[1],mat[5],mat[9]);

    glBindTexture(GL_TEXTURE_2D, texture);

    CVector3 blc((pos + ( right + up ) * -size));
    CVector3 brc((pos + ( right - up ) * size));
    CVector3 trc((pos + ( right + up ) * size));
    CVector3 tlc((pos + ( right - up ) * -size));

    glBegin(GL_QUADS);
        glTexCoord2f(0.0f,0.0f); glVertex3f(blc.x,blc.y,blc.z);
        glTexCoord2f(1.0f,0.0f); glVertex3f(brc.x,brc.y,brc.z);
        glTexCoord2f(1.0f,1.0f); glVertex3f(trc.x,trc.y,trc.z);
        glTexCoord2f(0.0f,1.0f); glVertex3f(tlc.x,tlc.y,tlc.z);
    glEnd();

}