include/scene.h
branchpyrit
changeset 36 b490093b0ac3
parent 34 28f6e8b9d5d1
child 38 5d043eeb09d9
equal deleted inserted replaced
35:fb170fccb19f 36:b490093b0ac3
   128 	virtual bool intersect(const Ray &ray, Float &dist) const = 0;
   128 	virtual bool intersect(const Ray &ray, Float &dist) const = 0;
   129 
   129 
   130 	// all intersections (only for CSG)
   130 	// all intersections (only for CSG)
   131 	virtual bool intersect_all(const Ray &ray, Float dist, vector<Float> &allts) const = 0;
   131 	virtual bool intersect_all(const Ray &ray, Float dist, vector<Float> &allts) const = 0;
   132 
   132 
       
   133 	// intersection with AABB
       
   134 	virtual bool intersect_bbox(const BBox &bbox) const = 0;
       
   135 
   133 	// normal at point P
   136 	// normal at point P
   134 	virtual const Vector3 normal(const Vector3 &P) const = 0;
   137 	virtual const Vector3 normal(const Vector3 &P) const = 0;
   135 
   138 
   136 	virtual BBox get_bbox() const = 0;
   139 	virtual BBox get_bbox() const = 0;
   137 };
   140 };
   151 	Sphere(const Vector3 &acenter, const Float aradius, Material *amaterial):
   154 	Sphere(const Vector3 &acenter, const Float aradius, Material *amaterial):
   152 		sqr_radius(aradius*aradius), inv_radius(1.0f/aradius),
   155 		sqr_radius(aradius*aradius), inv_radius(1.0f/aradius),
   153 		center(acenter), radius(aradius) { material = amaterial; }
   156 		center(acenter), radius(aradius) { material = amaterial; }
   154 	bool intersect(const Ray &ray, Float &dist) const;
   157 	bool intersect(const Ray &ray, Float &dist) const;
   155 	bool intersect_all(const Ray &ray, Float dist, vector<Float> &allts) const;
   158 	bool intersect_all(const Ray &ray, Float dist, vector<Float> &allts) const;
       
   159 	bool intersect_bbox(const BBox &bbox) const { return true; };
   156 	const Vector3 normal(const Vector3 &P) const { return (P - center) * inv_radius; };
   160 	const Vector3 normal(const Vector3 &P) const { return (P - center) * inv_radius; };
   157 	BBox get_bbox() const;
   161 	BBox get_bbox() const;
   158 };
   162 };
   159 
   163 
   160 class Box: public Shape
   164 class Box: public Shape
   169 				swap(L.cell[i], H.cell[i]);
   173 				swap(L.cell[i], H.cell[i]);
   170 		material = amaterial;
   174 		material = amaterial;
   171 	};
   175 	};
   172 	bool intersect(const Ray &ray, Float &dist) const;
   176 	bool intersect(const Ray &ray, Float &dist) const;
   173 	bool intersect_all(const Ray &ray, Float dist, vector<Float> &allts) const { return false; };
   177 	bool intersect_all(const Ray &ray, Float dist, vector<Float> &allts) const { return false; };
       
   178 	bool intersect_bbox(const BBox &bbox) const { return true; };
   174 	const Vector3 normal(const Vector3 &P) const;
   179 	const Vector3 normal(const Vector3 &P) const;
   175 	BBox get_bbox() const { return BBox(L, H); };
   180 	BBox get_bbox() const { return BBox(L, H); };
   176 };
   181 };
   177 
   182 
   178 class Vertex
   183 class Vertex
   233 	Vertex *A, *B, *C;
   238 	Vertex *A, *B, *C;
   234 
   239 
   235 	Triangle(Vertex *aA, Vertex *aB, Vertex *aC, Material *amaterial);
   240 	Triangle(Vertex *aA, Vertex *aB, Vertex *aC, Material *amaterial);
   236 	bool intersect(const Ray &ray, Float &dist) const;
   241 	bool intersect(const Ray &ray, Float &dist) const;
   237 	bool intersect_all(const Ray &ray, Float dist, vector<Float> &allts) const {return false;};
   242 	bool intersect_all(const Ray &ray, Float dist, vector<Float> &allts) const {return false;};
       
   243 	bool intersect_bbox(const BBox &bbox) const;
   238 	const Vector3 normal(const Vector3 &P) const { return (smooth ? smooth_normal(P) : N); };
   244 	const Vector3 normal(const Vector3 &P) const { return (smooth ? smooth_normal(P) : N); };
   239 	const Vector3 getNormal() const { return N; };
   245 	const Vector3 getNormal() const { return N; };
   240 	void setSmooth() { smooth = true; };//(typeid(*A) == typeid(*B) == typeid(*C) == typeid(NormalVertex)); };
   246 	void setSmooth() { smooth = true; };//(typeid(*A) == typeid(*B) == typeid(*C) == typeid(NormalVertex)); };
   241 	void setFlat() { smooth = false; };
   247 	void setFlat() { smooth = false; };
   242 	bool getSmooth() const { return smooth; };
   248 	bool getSmooth() const { return smooth; };