Monday, 10 May 2010

PV3D - Easy billboards

Billboards in 3D are really useful, they're used in all sorts of ways: from particle systems right up to big pseudo-3D elements (remember how in the Doom videogames everything always faced you? Billboards!). Anyway, I was happy to discover that creating a PV3D billboard is easy.

All you need to do is add this to your rendering functionality (assuming "plane" is your billboard):

// Position billboard in 3D space
var up : Number3D = new Number3D(0, 1, 0);
Matrix3D.rotateAxis(camera.transform, up);
            
// Reorient the billboard in relation to the camera
plane.lookAt(camera, up);
plane.roll(180);
plane.pitch(180);

Which will give you:


Of course this functionality could be applied in a much smarter way; if I had a bunch of billboard shapes I'd probably store them in an array and update them all in a loop, but you get the idea.

One of the best things about this (apart from the fact that billboards are much less processor-intensive than full 3D geometry) is that you can set up multiple cameras, and the billboards will shift to point at the new perspective a different camera is used. Handy!

No comments:

Post a comment