Crystal Space 2.0.0: 4.9.12 Decals

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### 4.9.12 Decals

Written by Andrew Robberts and adapted by Jorrit Tyberghein

Note: A decal is a piece of geometry that wraps around the existing world. Examples of this might be a bullet mark in a wall, a halo projected onto the floor around a selected item, or even a simple shadow underneath a player.

To create a decal you first need a reference to the global decal manager and decal template designed for your decal.

#### Decal Manager

The decal manager is used to create decals. Use the `iDecalManager` SCFF interface to access the decal manager.

You can load and get a reference to an iDecalManager through any mechanism that loads a Crystal Space Plugin. For example, the following code will attempt to load the decal plugin and give an iDecalManager reference.

    iObjectRegistry* object_reg = ...;
    csRef<iDecalManager> decal_mgr = csLoadPluginCheck<iDecalManager> (
      object_reg, "crystalspace.decal.manager");

#### Decal Templates

A decal template holds all the generic settings that are needed to create a decal such as lifespan, color, material, and other more complicated settings.

A decal template is created using the decal manager's `‘CreateDecalTemplate’` function:

    iMaterialWrapper* matWrap = ...;	// Material wrapper for your decal.
    csRef<iDecalTemplate> decalTemplate = decal_mgr->CreateDecalTemplate(matWrap);

The returned decalTemplate has sufficient default values to create a decal, but the decal template can be greatly customized by calling the many settings functions of iDecalTemplate.

#### Creating Decals

Once you have an `iDecalManager` reference and your `iDecalTemplate` you can create a decal using the decal manager's CreateDecal function:

    iDecal * iDecalManager::CreateDecal(iDecalTemplate * decalTemplate,
      iSector * sector, const csVector3 & pos, const csVector3 & up,
      const csVector3 & normal, float width, float height, iDecal * oldDecal)

- `‘decalTemplate’` This is the decal template you created earlier that will dictate the settings used for the decal.
- `‘sector’` This is the sector where the decal will be placed.
- `‘pos’` This is the position of the decal in the given sector.
- `‘up’` This is the direction of the top side of the decal. This setting can be used to rotate the decal.
- `‘normal’` This is the direction that will be perpendicular to the decal. This setting can be used to tilt the decal. For something like a bullet mark, you will probably want this direction to be perpendicular to the wall that will receive the bullet mark.
- `‘width’` The width of the decal.
- `‘height’` The height of the decal.
- `‘oldDecal’` This is an optional parameter. If you're recreating a decal (ie, moving/rotating an old decal) you can pass your old decal. The decal manager will recycle this decal as much as possible so that supplying an old decal is more efficient than deleting the old decal manually and creating a new one from scratch.

#### Deleting Decals

If you set a lifespan for your decal through `iDecalTemplate::SetTimeToLive()`, then your decal will die naturally and delete itself.

However, if you want to remove your decal early or it does not have a lifespan set, then you can remove your decal from the world by passing your `iDecal` pointer into `iDecalManager::DeleteDecal()`.

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

This document was generated using texi2html 1.76.