Tutorial 5: Decals
- Decal usage
- Introduction to the Mesh
class
Mostly this tutorial is about
DecalMeshs, which are the simplest of the Mesh classes, and a good place
to start. When the meteor strikes the ground, a red crater is created
at the point of impact, which fades over time. This red crater is a texture
painted on the terrain itself, and is called a "Decal".
The Mesh is one of the most
important primitives for a game engine - it is how objects are placed,
moved, and exist in the world.
I'll point out a little hack:
the Meteor class used to be "deleteable" when 'donePleaseDelete'
was true. Rather than rename / clean code, the logic is changed so that
donePleaseDelete must be true AND decal is null.
Tutorial 5: Change the alpha
of the decal
The Decal is created
(in the section below.) This checks the decal each tick and fades
it out. When fully faded, the decal is deleted.
The game owns the
Mesh! Not the Lilith engine. This is true of all Mesh's. The
life of a Mesh:
- new it (which adds
it to a container)
- position it in the
world
- delete it when done
(note you don't have to remove it from the MeshContainer - this
is automatic)
Tutorial 5: Create and position
decal.
Most Mesh's are created
from a MeshResource. Decals are unique
that they take a Texture instead of a MeshResource.
const Texture* decalTexture = TextureManager::Instance()->GetTexture( "impact", 0 ); GLASSERT( decalTexture ); decal = new DecalMesh( decalTexture, 1.5f ); decal->SetPos( location, rand.FRand( 360.0f ) );
This is important code - games
use lots of Meshs.
As noted, first we get the
texture, then construct the DecalMesh. It looks good at about a size of
1.5x1.5 units, which is the 'size' parameter.
The SetPos() sets both
the position and rotation in one call.
Conclusion
Short and adds a nice impact
crater. But a good foundation for working more with Meshes.
|