Ogre 3D 1.7 Beginner's Guide
上QQ阅读APP看书,第一时间看更新

Time for action — creating a directional light

  1. Delete all the old code in createScene(), except for the plane-related code.
  2. Create a light and set the light type to directional light:
    Ogre::Light* light = mSceneMgr->createLight("Light1");
    light->setType(Ogre::Light::LT_DIRECTIONAL);
    
  3. Set the light to a white color and the light direction to shine in a down-right direction:
    light->setDiffuseColour(Ogre::ColourValue(1.0f,1.0f,1.0f));
    light->setDirection(Ogre::Vector3(1,-1,0));
    
  4. Compile and run the application.
    Time for action — creating a directional light

What just happened?

We created a directional light and set it to shine down and rightwards with setDirection(1,-1,0). In the previous examples, we always had a rather black plane and a small part of the plane was illuminated by our pointlight or spotlight. Here, we used a directional light and hence the complete plane is illuminated. As said before, a directional light can be thought of as the sun, and the sun doesn't have a falloff radius or anything else. So when it shines, it illuminates everything there is; the same is true for our directional light.

Pop quiz — different light types

Recall all three light types that Ogre 3D has and state the differences.