Sphere - G center = rhs.center; radius = rhs.radius; =...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
// This file contains the definition of the class sphere / #include "Sphere.h" #include "math.h" # const double Sphere::kEpsilon = 0.001; c // ---------------------------------------------------------------- default constructor c Sphere::Sphere(void) S : GeometricObject(), center(0.0), radius(1.0) {} { // ---------------------------------------------------------------- constructor / Sphere::Sphere(Point3D c, double r) : GeometricObject(), center(c), radius(r) {} { // ---------------------------------------------------------------- clone / GeometricObject* Sphere::clone(void) const { return (new Sphere(*this)); } // ---------------------------------------------------------------- copy constructor c : GeometricObject(sphere), center(sphere.center), radius(sphere.radius) {} { // ---------------------------------------------------------------- assignment operator o Sphere& S { return (*this); r GeometricObject::operator= (rhs);
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: G center = rhs.center; radius = rhs.radius; = return (*this); } // ---------------------------------------------------------------- destructor / Sphere::~Sphere(void) {} S //---------------------------------------------------------------- hit / bool Sphere::hit(const Ray& ray, double& tmin, ShadeRec& sr) const { double t; Vector3D temp = ray.o - center; double a = ray.d * ray.d; double b = 2.0 * temp * ray.d; double c = temp * temp - radius * radius; double disc = b * b - 4.0 * a * c; = if (disc < 0.0) return(false); else { e double e = sqrt(disc); double denom = 2.0 * a; t = (-b - e) / denom; // smaller root t if (t > kEpsilon) { tmin = t; sr.normal = (temp + t * ray.d) / radius; sr.local_hit_point = ray.o + t * ray.d; return (true); } } t = (-b + e) / denom; // larger root t if (t > kEpsilon) { tmin = t; sr.normal = (temp + t * ray.d) / radius; sr.local_hit_point = ray.o + t * ray.d; return (true); } } return (false); }...
View Full Document

This note was uploaded on 02/19/2010 for the course CS 390 taught by Professor Hu during the Spring '10 term at Westminster UT.

Page1 / 2

Sphere - G center = rhs.center; radius = rhs.radius; =...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online