Time for action — doing something that illustrates the thing "in action"

We will use the code that we used before and once again create a new empty method:

  1. Remove the setShadowTechnique() function call from the createCamera() function. We don't want our scene in wireframe mode.
  2. Create an empty createViewports() method:
    void createViewports() {
    }
    
  3. Create a viewport:
    Ogre::Viewport* vp = mWindow->addViewport(mCamera);
    
  4. Set the background color and the aspect ratio:
    vp->setBackgroundColour(ColourValue(0.0f,0.0f,1.0f));
    mCamera->setAspectRatio(Real(vp->getActualWidth()) / Real(vp->getActualHeight()));
    
  5. Compile and run the application.
    Time for action — doing something that illustrates the thing "in action"

What just happened?

We created a viewport. To do this, we needed to pass a camera to the function. Each viewport can only render the view of one camera, so Ogre 3D enforces that one camera is given during creation. Of course, the camera can be changed later using the appropriate getter and setter functions. The most noticeable change is that the background color changed from black to blue. The reason should be obvious: the new viewport has the background color blue; we set it in step 3. Also in step 3, we set the aspect ratio the aspect ratio describes the ratio between the width and height of a rendered image; in math terms: aspect ratio = width of window divided by height of window.

Have a go hero — playing with different aspect ratio

Try playing with different aspect ratios and see how this affects the image produced. Also change the background color. Here is an image where the width of the aspect ratio is divided by five.

Have a go hero — playing with different aspect ratio
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.218.239.182