Time for action — creating a spotlight

We will use the code we created before and modify it a bit to see how a spotlight works:

  1. Delete the code where we created the light and insert the following code to create a new scene node. Be careful not to delete the part of the code we used to create LigthEnt and then add the following code:
    Ogre::SceneNode* node2 = node->createChildSceneNode("node2");
    node2->setPosition(0,100,0);
    
  2. Again, create a light, but now set the type to spotlight:
    Ogre::Light* light = mSceneMgr->createLight("Light1");
    light->setType(Ogre::Light::LT_SPOTLIGHT);
    
  3. Now set some parameters; we will discuss their meanings later:
    light->setDirection(Ogre::Vector3(1,-1,0)); light->setSpotlightInnerAngle(Ogre::Degree(5.0f)); light->setSpotlightOuterAngle(Ogre::Degree(45.0f)); ...

Get Ogre 3D 1.7 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.