This section of the archives stores flipcode's complete Developer Toolbox collection, featuring a variety of mini-articles and source code contributions from our readers.

| Really Fast Billboarding Alignment Without VP Tricks Submitted by

Often billboards are explained as a Quad with its normals looking to the camera position. While this is true for a spherical mapping as you can see it with a real camera objective or how its done by good raytracers. However realtime 3D graphics uses projection methods based on models in which the far and near clip plane are planparallel to the screen plane. This however means, that you've just to compensate all the rotaions applied to the camera. As you might know in a 4x4 matrix the rotations are represented by the 3x3 upper left submatrix. So all you need is to do is changing this submatrix to

    1 0 0
    0 1 0
    0 0 1

However you've to do this for every single billboard positioning matrix. Not very usefull for a particle system. But you can avoid this problem relatively easy: First you've to extract and inverse the camera rotation sub-matrix. Then you build a small vertex array containing the billboard quad, with each vertex roatated by this inversed rotation matrix. This applies the transformation you'd have to do for each particle otherwise.
Now a short pseudo code snippet, assuming OpenGL

    position_camera();
    glGetDoublev(GL_MODELVIEW_MATRIX, &mv_matrix);
    rot_matrix=mv_matrix.get_sub(0, 0, 3, 3).inverse();
    billboard_alligned_quad_array=quad_array.mult_matrix(rot_matix);
    for(i=0; i<billboard_count; i++)
    {
        glPushMatrix();
        glTranslate(billboard[i].position);
        bilboard[i].draw_using(billboard_alligned_quad_array);
        glPopMatrix()
    }

The zip file viewer built into the Developer Toolbox made use of the zlib library, as well as the zlibdll source additions.

Copyright 1999-2008 (C) FLIPCODE.COM and/or the original content author(s). All rights reserved.
Please read our Terms, Conditions, and Privacy information.