i've recently found a good and clean way to render billboards. i basically use the inverse of the view matrix and set it as "world transformation" in the driver. i believe this is much cleaner and maybe faster, although i havent tested that.
Code: Select all
/* put this in constructor */
Indices[0] = 0;
Indices[1] = 2;
Indices[2] = 1;
Indices[3] = 0;
Indices[4] = 3;
Indices[5] = 2;
Vertices[0].Pos = Size*vector3df(1,1,0);
Vertices[1].Pos = Size*vector3df(-1,1,0);
Vertices[2].Pos = Size*vector3df(-1,-1,0);
Vertices[3].Pos = Size*vector3df(1,-1,0);
Vertices[0].TCoords.set(1.0f, 1.0f);
Vertices[0].Color = shade_down;
Vertices[1].TCoords.set(1.0f, 0.0f);
Vertices[1].Color = shade_top;
Vertices[2].TCoords.set(0.0f, 0.0f);
Vertices[2].Color = shade_top;
Vertices[3].TCoords.set(0.0f, 1.0f);
Vertices[3].Color = shade_down;
/* new render method */
void CBillboardSceneNode::render() {
// ...
matrix4 mv = SMGR->getActiveCamera()->getViewMatrix();
mv.makeInverse();
mv.setTranslation(getPosition());
// draw
Driver->setTransform(ETS_WORLD, mv);
Driver->setMaterial(Material);
Driver->drawIndexedTriangleList(Vertices, 4, Indices, 2);
}