Source: raytracer/object3d.h
|
|
|
|
/* *************************************************************************
object3d.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 OBJECT3D_H
#define OBJECT3D_H
#include "transformatable.h"
#include "boundingbox.h"
#include "ray.h"
#include "insidelist.h"
#include "statistics.h"
class Material3D;
class Texture3D;
class Pigment3D;
class Finish;
class Interior;
class Media3D;
class Intersection;
/**Superclass of all objects.
*@author Micha Riser
*/
class Object3D: public Transformatable {
public: // Public attributes
/**The object's material.
*/
Material3D* material;
/**The object's bounding box.
*/
BoundingBox* boundingbox;
/**Holds the object's invering status. True means inversed.
*/
bool inversed;
public: // Constructors and destructor
/**Constructs an object at origin. Material and bounding box default to 0 and
*object not inversed.
*/
Object3D():material(0), boundingbox(0), inversed(false) {};
/**Constructs an object at given position. Material and bounding box default
*to 0 and object not inversed.
*@param location Position to create the object.
*/
Object3D(Vector3 location): Transformatable(location), material(0), boundingbox(0), inversed(false) {}
virtual ~Object3D();
protected:
/**Copy constructor.
*/
Object3D(const Object3D &o);
private:
Object3D& operator=(const Object3D&);
public: // Public methods
// Pure virtual method
/**Create a duplicate of the object.
*@returns duplicate
*/
virtual Object3D* duplicate() const = 0;
/**Intersect object with ray.
*@param r the Ray
*@returns 0 if no intersection else Intersection object
*/
virtual Intersection* intersectUnBounded(const Ray &r) = 0;
/**Intersect object with ray limited to maximum time
*@param r the Ray
*@param maxtime maximal intersecting time
*@returns 0 if no intersection else Intersection object
*/
virtual Intersection* intersectUnBounded(const Ray &r, DBL maxtime) = 0;
/**Test point for insidness.
*@param locallocation point in object space to test
*@returns true if point is inside the object else false
*/
virtual bool isInsideAt(const Vector3 &locallocation) const = 0;
// methods to set Object3D's material and sub-components
/**Set / override object's material.
*@param m new Material3D
*/
void setMaterial(const Material3D &m);
/**Set / override object's texture.
*@param t new Texture3D
*/
void setTexture(const Texture3D &t);
/**Set / override object's pigment.
*@param p new Pigment3D
*/
void setPigment(const Pigment3D &p);
/**Set / override object's finish.
*@param f new Finish
*/
void setFinish(const Finish &f);
/**Set / override object's interior.
*@param i new Interior
*/
void setInterior(const Interior &i);
/**Set / override object's media.
*@param m new Media3D
*/
void setMedia(const Media3D &m);
// overwrite the transformation in Tranformatable to get the
// boundingbox transformed as well
virtual void translate(const Vector3 &v);
virtual void scale(Vector3 v);
virtual void rotate(const Vector3 &v);
virtual void transform(const Transformatable& t);
virtual void transformInverse(const Transformatable& t);
// other virtual methods
/**Inverse the object.
*/
virtual void inverse() {if (inversed) inversed=false; else inversed=true;}
/**Create insidness list. Adds the object (or all subcomponents in the case
*of a container object) to the given list if the location is inside.
*@param location the test point
*@param l list to add the object
*/
virtual void listInside(const Vector3& location, InsideList& l) const;
/**Prepare object for render process. Some optimisations can be done only
*before the rendering starts. This is the method that is to be called
*just before doing so.
*/
virtual void prepareToRender() {}
// non-virtual methods
/**Test point for insidness.
*@param location test point
*@returns true if point is inside object else false
*/
bool isInsideAtBounded(Vector3 location) const {
if (boundingbox && !boundingbox->isInsideAt(location)) return inversed;
transformPointIn(location);
return isInsideAt(location);
}
/**Test ray against object's bounding.
*@param r test ray
*@returns false if ray misses the bounding else true
*/
bool hitsBounding(const Ray& r) {
return (boundingbox==0||boundingbox->isInsideAt(r.getOrigin())||boundingbox->intersect(r)>=0);
}
/**Test ray against object's bounding with limited maximum time.
*@param r test ray
*@param tmax maximal intersecting time
*@returns false if ray misses the bounding else true
*/
bool hitsBounding(const Ray& r, double tmax) {
return (boundingbox==0||boundingbox->isInsideAt(r.getOrigin())||boundingbox->intersect(r,tmax)>=0);
}
/**
*@returns true if object is inversed else false
*/
bool isInversed() const {return inversed;}
};
#endif
| Generated by: micha@laptop on Thu Oct 24 20:25:24 2002, using kdoc 2.0a53. |