include/scene.h
branchpyrit
changeset 25 b8232edee786
parent 24 d0d76e8a5203
child 28 ffe83ca074f3
equal deleted inserted replaced
24:d0d76e8a5203 25:b8232edee786
     9 #define SCENE_H
     9 #define SCENE_H
    10 
    10 
    11 #include <vector>
    11 #include <vector>
    12 
    12 
    13 #include "noise.h"
    13 #include "noise.h"
    14 
       
    15 #include "vector.h"
    14 #include "vector.h"
       
    15 
       
    16 /*
       
    17 triangle intersection alghoritm
       
    18 chooses are:
       
    19 TRI_PLUCKER
       
    20 TRI_BARI
       
    21 TRI_BARI_PRE
       
    22 */
       
    23 #if !defined(TRI_PLUCKER) && !defined(TRI_BARI) && !defined(TRI_BARI_PRE)
       
    24 #	define TRI_BARI_PRE
       
    25 #endif
    16 
    26 
    17 using namespace std;
    27 using namespace std;
    18 
    28 
    19 class Ray
    29 class Ray
    20 {
    30 {
   138 	Material *material;
   148 	Material *material;
   139 	Shape() {};
   149 	Shape() {};
   140 	virtual ~Shape() {};
   150 	virtual ~Shape() {};
   141 
   151 
   142 	// first intersection point
   152 	// first intersection point
   143 	virtual bool intersect(const Ray &ray, Float &dist) = 0;
   153 	virtual bool intersect(const Ray &ray, Float &dist) const = 0;
   144 
   154 
   145 	// all intersections (only for CSG)
   155 	// all intersections (only for CSG)
   146 	virtual bool intersect_all(const Ray &ray, Float dist, vector<Float> &allts) = 0;
   156 	virtual bool intersect_all(const Ray &ray, Float dist, vector<Float> &allts) const = 0;
   147 
   157 
   148 	// normal at point P
   158 	// normal at point P
   149 	virtual Vector3 normal(Vector3 &P) = 0;
   159 	virtual Vector3 normal(Vector3 &P) const = 0;
   150 
   160 
   151 	virtual BBox get_bbox() = 0;
   161 	virtual BBox get_bbox() const = 0;
   152 };
   162 };
   153 
   163 
   154 class ShapeList: public vector<Shape*>
   164 class ShapeList: public vector<Shape*>
   155 {
   165 {
   156 };
   166 };
   164 	Float radius;
   174 	Float radius;
   165 
   175 
   166 	Sphere(const Vector3 &acenter, const Float aradius, Material *amaterial):
   176 	Sphere(const Vector3 &acenter, const Float aradius, Material *amaterial):
   167 		sqr_radius(aradius*aradius), inv_radius(1.0f/aradius),
   177 		sqr_radius(aradius*aradius), inv_radius(1.0f/aradius),
   168 		center(acenter), radius(aradius) { material = amaterial; }
   178 		center(acenter), radius(aradius) { material = amaterial; }
   169 	bool intersect(const Ray &ray, Float &dist);
   179 	bool intersect(const Ray &ray, Float &dist) const;
   170 	bool intersect_all(const Ray &ray, Float dist, vector<Float> &allts);
   180 	bool intersect_all(const Ray &ray, Float dist, vector<Float> &allts) const;
   171 	Vector3 normal(Vector3 &P) { return (P - center) * inv_radius; };
   181 	Vector3 normal(Vector3 &P) const { return (P - center) * inv_radius; };
   172 	BBox get_bbox();
   182 	BBox get_bbox() const;
   173 };
   183 };
   174 
   184 
   175 class Box: public Shape
   185 class Box: public Shape
   176 {
   186 {
   177 	Vector3 L;
   187 	Vector3 L;
   182 		for (int i = 0; i < 3; i++)
   192 		for (int i = 0; i < 3; i++)
   183 			if (L.cell[i] > H.cell[i])
   193 			if (L.cell[i] > H.cell[i])
   184 				swap(L.cell[i], H.cell[i]);
   194 				swap(L.cell[i], H.cell[i]);
   185 		material = amaterial;
   195 		material = amaterial;
   186 	};
   196 	};
   187 	bool intersect(const Ray &ray, Float &dist);
   197 	bool intersect(const Ray &ray, Float &dist) const;
   188 	bool intersect_all(const Ray &ray, Float dist, vector<Float> &allts) {return false;};
   198 	bool intersect_all(const Ray &ray, Float dist, vector<Float> &allts) const { return false; };
   189 	Vector3 normal(Vector3 &P);
   199 	Vector3 normal(Vector3 &P) const;
   190 	BBox get_bbox() { return BBox(L, H); };
   200 	BBox get_bbox() const { return BBox(L, H); };
   191 };
   201 };
   192 
   202 
   193 class Triangle: public Shape
   203 class Triangle: public Shape
   194 {
   204 {
       
   205 #ifdef TRI_BARI_PRE
       
   206 	Float nu, nv, nd;
   195 	int k; // dominant axis
   207 	int k; // dominant axis
   196 	Float nu, nv, nd;
       
   197 	Float bnu, bnv;
   208 	Float bnu, bnv;
   198 	Float cnu, cnv;
   209 	Float cnu, cnv;
       
   210 #endif
       
   211 #ifdef TRI_BARI
       
   212 	int k; // dominant axis
       
   213 #endif
       
   214 #ifdef TRI_PLUCKER
       
   215 	Float pla[6], plb[6], plc[6];
       
   216 #endif
   199 public:
   217 public:
   200 	Vector3 A, B, C, N;
   218 	Vector3 A, B, C, N;
   201 
   219 
   202 	Triangle(const Vector3 &aA, const Vector3 &aB, const Vector3 &aC, Material *amaterial);
   220 	Triangle(const Vector3 &aA, const Vector3 &aB, const Vector3 &aC, Material *amaterial);
   203 	bool intersect(const Ray &ray, Float &dist);
   221 	bool intersect(const Ray &ray, Float &dist) const;
   204 	bool intersect_all(const Ray &ray, Float dist, vector<Float> &allts) {return false;};
   222 	bool intersect_all(const Ray &ray, Float dist, vector<Float> &allts) const {return false;};
   205 	Vector3 normal(Vector3 &) { return N; };
   223 	Vector3 normal(Vector3 &) const { return N; };
   206 	BBox get_bbox();
   224 	BBox get_bbox() const;
   207 };
   225 };
   208 
   226 
   209 #endif
   227 #endif