For a single collision sphere, in fact, and a plurality of balls the same, but I modified the code in the book, so much the definition of class, finally coming to an end. Soon demonstrated when a miracle.
Class definition:
#pragma once #ifndef __SINGLESPHERE_HEADER__ #define __SINGLESPHERE_HEADER__ #include "tracer.h" class SingleSphere : public Tracer { public: SingleSphere(World* wr_ptr); virtual ~SingleSphere(); virtual RGBColor trace_ray(const Ray& ray) const; private: SingleSphere(); }; #endif
Class implementation:
#include "pch.h" #include "singlesphere.h" #include "../utilities/world.h" SingleSphere::SingleSphere(World* wr_ptr) :Tracer(wr_ptr) {} SingleSphere::~SingleSphere() {} RGBColor SingleSphere::trace_ray(const Ray& ray) const { ShadeRec sr(world_ptr->hit_bare_bones_objects(ray)); if (sr.hit_an_object && world_ptr->get_object_size() == 1) //这里限制了一个球体 return sr.color; return RGBColor(); }