OGRE (Object-Oriented Graphics Rendering Engine)
Avionic Flying Lights
Some new classes to play with
We are now going to give the ship some lights on it's wings and tail so that pilots of other ships can see it againt the blackness of space. By using different colours and patterns on each of the wings and tail, another pilot will also be able to determine which direction the ship is facing.
To do this we will be using three object classes: Light, BillboardSet, and Billboard.
Billboards and Materials
A billboard simply displays a 2D image in the 3D world that we create. Whenever a billboard is rendered it faces the viewer. This is perfect for the lights we are about to make, they can appear as small balls of light. The image displayed on the billboard is a material just like any other so it needs to be defined in our material script file.
Open ogrenew\Samples\Media\example.material and add the following to the script:
// Light effectsIt may look familiar to some of you. It is in fact the material used for the flare effects earlier in the script, but its name has been changed to suit our purposes.
material Examples/FlyingLightMaterial
{
technique
{
pass
{
lighting off
scene_blend add
depth_write off
texture_unit
{
texture flare.png
}
}
}
}
BillboardSets and Billboards
A BillboardSet is a grouping of Billboards in 3D space. The relationship between BillboardSet and Billboard is well documented in the Ogre API so there is really no need to describe it here.
Member Variables
Time to add member variables for the lights and billboards. Add this to the protected section of our SpaceApplication class
// The set of all the billboards used for the avionic lights
BillboardSet* mLights;
// Billboards
Billboard* mRedLightBoard;
Billboard* mBlueLightBoard;
Billboard* mWhiteLightBoard;
// Lights
Light* mRedLight;
Light* mBlueLight;
Light* mWhiteLight;
Lighting Instances
The general flow of this is:
|
1) Create BillboardSet |
|
2) Set its material and attach it to the scene |
|
3) Using the new BillboardSet create as many billboards as you require, position each of them |
|
4) Create the lights and attach them to the scene |
So let's begin by creating the BillboardSet. Type this in at the bottom of the createScene method
// First create the BillboardSet. This will define the materials for the billboardsThere should not be too much there that needs explaining. Like other objects in Ogre, BillboardSets all have unique names. This one is called "FlyingLights" and the material that we want it to be using for its Billboards is "Examples/FlyingLightMaterial", which is of course the material we put into the material script earlier. Each of the three coloured lights has two properties of any interest. Position and colour.
// in its set to use
mLights = mSceneMgr->createBillboardSet("FlyingLights");
mLights->setMaterialName("Examples/FlyingLightMaterial");
mShipNode->attachObject(mLights);
// Red light billboard, in "off" stateYou might notice that the positions chosen here are not symmetrical. I originally used symmetrical values but then discovered that the lights just would not line up on the ship. Instead of modifying the model and distributing that I decided to just change these positions. If you find that the lights still do not line up on your model you may want to adjust these values yourself later on.
Vector3 redLightPosition(78, -8, -70);
mRedLightBoard = mLights->createBillboard(redLightPosition);
mRedLightBoard->setColour(ColourValue::Black);
// Blue light billboard, in "off" state
Vector3 blueLightPosition(-90, -8, -70);
mBlueLightBoard = mLights->createBillboard(blueLightPosition);
mBlueLightBoard->setColour(ColourValue::Black);
// White light billboard, in "off" state
Vector3 whiteLightPosition(-4.5, 30, -80);
mWhiteLightBoard = mLights->createBillboard(whiteLightPosition);
mWhiteLightBoard->setColour(ColourValue::Black);
The light objects are next on the list. Each of them has a distinct name, a type, a colour, and a position.
// Red light, in "off" stateIf you run the program as it stands right now you wont notice anything different. Why is that? well that is because we told the lights and billboards to be black. Just to see where the lights and billboards are try changing the colour of all of the billboards to their "on" colour. For instance, set the colour of mRedLightBoard to ColourValue::Red. When you run it you will then see three coloured balls, one on the left wingtip, one on the right wingtip, and one on the tail wingtip. Change them all back to black and save.
mRedLight = mSceneMgr->createLight("RedFlyingLight");
mRedLight->setType(Light::LT_POINT);
mRedLight->setPosition(redLightPosition);
mRedLight->setDiffuseColour(ColourValue::Black);
mShipNode->attachObject(mRedLight);
// Blue light, in "off" state
mBlueLight = mSceneMgr->createLight("BlueFlyingLight");
mBlueLight->setType(Light::LT_POINT);
mBlueLight->setPosition(blueLightPosition);
mBlueLight->setDiffuseColour(ColourValue::Black);
mShipNode->attachObject(mBlueLight);
// White light in "off" state
mWhiteLight = mSceneMgr->createLight("WhiteFlyingLight");
mWhiteLight->setType(Light::LT_POINT);
mWhiteLight->setPosition(whiteLightPosition);
mWhiteLight->setDiffuseColour(ColourValue::Black);
mShipNode->attachObject(mWhiteLight);
Back to Index | << Previous section | Next section >> |