T4 Use the Camera Class

Create camera.h

Create camera.h under your src folder, put the following framework into it

#ifndef CAMERA_H
#define CAMERA_H

#include "hittable.h"

class camera {
private:
    /* Private Camera Variables Here */

    void initialize() {
        //...
    }
    
    color ray_color(const ray& r, const hittable& world) const {
        //...
    }
    
  public:
    /* Public Camera Parameters Here */

    void render(const hittable& world) {
        //...
    }

};

#endif

Filling the methods

ray_color()

move the content in ray_color() in main.cpp to this method

intialise()

Move the variables and initialisation code from main.cpp to the camera class

render()

Also move the render loop from main() to the camera class

Reduce main.cpp

The following is the reduced main after using the camera class

Build and run the Program

You should be able to build your program successfully and run it as follows:

You should see the same rendering as in T2

Last updated