diff -r dbe8438d5dca -r 9569e9f35374 include/scene.h --- a/include/scene.h Tue Apr 22 13:33:12 2008 +0200 +++ b/include/scene.h Wed Apr 23 10:38:33 2008 +0200 @@ -30,24 +30,15 @@ #include #include +#include "common.h" #include "sampler.h" #include "noise.h" #include "vector.h" #include "quaternion.h" -/* -triangle intersection alghoritm -chooses are: -TRI_PLUCKER -TRI_BARI -TRI_BARI_PRE -*/ -#if !defined(TRI_PLUCKER) && !defined(TRI_BARI) && !defined(TRI_BARI_PRE) -# define TRI_BARI_PRE -#endif - -using namespace std; - +/** + * ray + */ class Ray { public: @@ -164,167 +155,4 @@ void setSmooth(bool sm) { smooth = sm; }; }; -/** - * shape - */ -class Shape -{ -public: - Material *material; - Shape() {}; - virtual ~Shape() {}; - - // first intersection point - virtual bool intersect(const Ray &ray, Float &dist) const = 0; - - // all intersections (only for CSG) - virtual bool intersect_all(const Ray &ray, Float dist, vector &allts) const = 0; - - // intersection with AABB - virtual bool intersect_bbox(const BBox &bbox) const = 0; - - // normal at point P - virtual const Vector3 normal(const Vector3 &P) const = 0; - - virtual BBox get_bbox() const = 0; -}; - -/** - * list of shapes - */ -class ShapeList: public vector -{ -}; - -/** - * sphere shape - */ -class Sphere: public Shape -{ - Float sqr_radius; - Float inv_radius; -public: - Vector3 center; - Float radius; - - Sphere(const Vector3 &acenter, const Float aradius, Material *amaterial): - sqr_radius(aradius*aradius), inv_radius(1.0f/aradius), - center(acenter), radius(aradius) { material = amaterial; } - bool intersect(const Ray &ray, Float &dist) const; - bool intersect_all(const Ray &ray, Float dist, vector &allts) const; - bool intersect_bbox(const BBox &bbox) const; - const Vector3 normal(const Vector3 &P) const { return (P - center) * inv_radius; }; - BBox get_bbox() const; -}; - -/** - * box shape - */ -class Box: public Shape -{ - Vector3 L; - Vector3 H; -public: - Box(const Vector3 &aL, const Vector3 &aH, Material *amaterial): L(aL), H(aH) - { - for (int i = 0; i < 3; i++) - if (L.cell[i] > H.cell[i]) - swap(L.cell[i], H.cell[i]); - material = amaterial; - }; - bool intersect(const Ray &ray, Float &dist) const; - bool intersect_all(const Ray &ray, Float dist, vector &allts) const { return false; }; - bool intersect_bbox(const BBox &bbox) const; - const Vector3 normal(const Vector3 &P) const; - BBox get_bbox() const { return BBox(L, H); }; -}; - -/** - * triangle vertex - */ -class Vertex -{ -public: - Vector3 P; - Vertex(const Vector3 &aP): P(aP) {}; -}; - -/** - * triangle vertex with normal - */ -class NormalVertex: public Vertex -{ -public: - Vector3 N; - NormalVertex(const NormalVertex *v): Vertex(v->P), N(v->N) {}; - NormalVertex(const Vector3 &aP): Vertex(aP) {}; - NormalVertex(const Vector3 &aP, const Vector3 &aN): Vertex(aP), N(aN) {}; - const Vector3 &getNormal() { return N; }; - void setNormal(const Vector3 &aN) { N = aN; }; -}; - -/** - * triangle shape - */ -class Triangle: public Shape -{ -#ifdef TRI_BARI_PRE - Float nu, nv, nd; - int k; // dominant axis - Float bnu, bnv; - Float cnu, cnv; #endif -#ifdef TRI_BARI - int k; // dominant axis -#endif -#ifdef TRI_PLUCKER - Float pla[6], plb[6], plc[6]; -#endif - Vector3 N; - const Vector3 smooth_normal(const Vector3 &P) const - { -#ifdef TRI_BARI_PRE - const Vector3 &NA = static_cast(A)->N; - const Vector3 &NB = static_cast(B)->N; - const Vector3 &NC = static_cast(C)->N; - static const int modulo3[5] = {0,1,2,0,1}; - register const int ku = modulo3[k+1]; - register const int kv = modulo3[k+2]; - const Float pu = P[ku] - A->P[ku]; - const Float pv = P[kv] - A->P[kv]; - const Float u = pv * bnu + pu * bnv; - const Float v = pu * cnv + pv * cnu; - Vector3 n = NA + u * (NB - NA) + v * (NC - NA); - n.normalize(); - return n; -#else - return N; // not implemented for other algorithms -#endif - }; -public: - Vertex *A, *B, *C; - - Triangle() {}; - Triangle(Vertex *aA, Vertex *aB, Vertex *aC, Material *amaterial); - bool intersect(const Ray &ray, Float &dist) const; - bool intersect_all(const Ray &ray, Float dist, vector &allts) const {return false;}; - bool intersect_bbox(const BBox &bbox) const; - const Vector3 normal(const Vector3 &P) const { return (material->smooth ? smooth_normal(P) : N); }; - const Vector3 getNormal() const { return N; }; - BBox get_bbox() const; -}; - -template class Array -{ - T *array; -public: - Array(int n) { array = new T[n]; }; - ~Array() { delete[] array; }; - const T &operator[](int i) const { return array[i]; }; -}; - -typedef Array VertexArray; -typedef Array NormalVertexArray; -typedef Array TriangleArray; - -#endif