Source: raytracer/sphere.h


Annotated List
Files
Globals
Hierarchy
Index
/* *************************************************************************
                            sphere.h  -  description
                             -------------------
    begin                : Wed Oct 16 2002    
    copyright            : (C) 2002 by Micha Riser
    email                : mriser@gmx.net
 ************************************************************************* */

/* *************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ************************************************************************* */

#ifndef SPHERE_H
#define SPHERE_H

#include "object3d.h"
#include "intersection.h"

/**Sphere object.
  *@author Micha Riser
  */

class Sphere: public Object3D {

public: // Constructors and destructor
    /**Create sphere at origin.
      *@param r radius
      */
    Sphere(DBL r): radius(r) {
        radiussq = r*r;
        calculateBoundingBox();
    }

    /**Create sphere.
      *@param r radius
      *@param l midpoint
      */

    Sphere(DBL r, Vector3 l): Object3D(l), radius(r) {
        radiussq = r*r;
        calculateBoundingBox();
    }

public: // Pulblic methods

    // Inherited from Object3D
    Object3D* duplicate() const {
        return new Sphere(*this);
    }
    void rotate(const Vector3& v); 
    Intersection* intersectUnBounded(const Ray &r);
    Intersection* intersectUnBounded(const Ray &r, DBL maxtime);
    bool isInsideAt(const Vector3 &locallocation) const;
    void prepareToRender();

private: // Static members
    static HitStatistics stat;
    
private: // Private attributes
    DBL radius;
    DBL radiussq;
    
private: // Private methods
    void calculateBoundingBox();

private: // Inner classes

    /**Describes Ray-Sphere Intersection.
      */
    class SphereIntersection: public Intersection {

    private: // Private attributes
        DBL currenttime;
        DBL secondtime;

    public: // Constructor and destructor
        SphereIntersection(const Object3D* o, const Ray &r, DBL t1, DBL t2):
          Intersection(o,r), currenttime(t1), secondtime(t2) {}

    public: // Pulblic methods

        //Inherited from Intersection
        DBL currentTime() {return currenttime;}
        void next();
        Vector3 normal();
        
    };
            
};



#endif

Generated by: micha@laptop on Thu Oct 24 20:25:24 2002, using kdoc 2.0a53.