Basic Shapes

In this section we will define the base class, from which all shapes inherit some basic attributes. This will be the way that the ray tracer can interface the shape classes, create a file called Shape.H:

#ifndef _Shape_H
#define _Shape_H

#include "Ray.H"
#include "Transform.H"

class Shape {
    // Initialize shape
    Shape(const Transform *o2w,
          const Transform *w2o,
          bool ro);

    // Check if ray intersects shape
    virtual bool Intersect(const Ray &r,
                           Float *pT,
                           Float *pEpsilon,
                           OSL::ShaderGlobals *pSg) const;

    // Public data
    const Transform *pObjectToWorld;
    const Transform *pWorldToObject;
    const bool reverseOrientation;
    const bool transformSwapsHandedness;
    const int shapeId;

    // Private data
    static int nextShapeId;

#endif // _Shape_H

As you can se above, we will not make this an entirely abstract class. The default methods are defined in Shape.C:

#include <iostream>
#include "Shape.H"

int Shape::nextShapeId = 1;

// Initialize shape
Shape::Shape(const Transform *o2w,
             const Transform *w2o,
             bool ro)
    : pObjectToWorld(o2w),
      shapeId(nextShapeId++) {

// Check if ray intersects shape
bool Shape::Intersect(const Ray &r,
                      Float *pT,
                      Float *pEpsilon,
                      OSL::ShaderGlobals *pSg) const
    std::cerr << "Unimplemented Shape::Intersect() method called" << std::endl;

    return false;

Some ideas for the shape interface has been "borrowed" from the the Physically Based Rendering Techniques Renderer, a.k.a pbrt, enjoy!

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License