include/scene.h
branchpyrit
changeset 69 303583d2fb97
parent 60 a23b5089b9c3
child 72 7c3f38dff082
equal deleted inserted replaced
68:2c154aad7f33 69:303583d2fb97
   130  */
   130  */
   131 class Material
   131 class Material
   132 {
   132 {
   133 public:
   133 public:
   134 	Colour colour;
   134 	Colour colour;
       
   135 	Texture *texture;
   135 	Float ambient, diffuse, specular, shininess; // Phong constants
   136 	Float ambient, diffuse, specular, shininess; // Phong constants
   136 	Float reflectivity; // how much reflective is the surface
   137 	Float reflectivity; // how much reflective is the surface
   137 	Float transmissivity, refract_index; // part of light which can be refracted; index of refraction
   138 	Float transmissivity, refract_index; // part of light which can be refracted; index of refraction
   138 	Texture *texture;
   139 	bool smooth; // triangle smoothing
   139 
   140 
   140 	Material(const Colour &acolour): colour(acolour), texture(NULL)
   141 	Material(const Colour &acolour): colour(acolour), texture(NULL), smooth(false)
   141 	{
   142 	{
   142 		ambient = 0.2;
   143 		ambient = 0.2;
   143 		diffuse = 0.8;
   144 		diffuse = 0.8;
   144 		specular = 0.2;
   145 		specular = 0.2;
   145 		shininess = 0.5;
   146 		shininess = 0.5;
   151 	void setPhong(const Float amb, const Float dif, const Float spec, const Float shin)
   152 	void setPhong(const Float amb, const Float dif, const Float spec, const Float shin)
   152 		{ ambient = amb; diffuse = dif; specular = spec; shininess = shin; };
   153 		{ ambient = amb; diffuse = dif; specular = spec; shininess = shin; };
   153 	void setReflectivity(const Float refl) { reflectivity = refl; };
   154 	void setReflectivity(const Float refl) { reflectivity = refl; };
   154 	void setTransmissivity(const Float trans, const Float rindex)
   155 	void setTransmissivity(const Float trans, const Float rindex)
   155 		{ transmissivity = trans; refract_index = rindex; };
   156 		{ transmissivity = trans; refract_index = rindex; };
       
   157 	void setSmooth(bool sm) { smooth = sm; };
   156 };
   158 };
   157 
   159 
   158 /**
   160 /**
   159  * shape
   161  * shape
   160  */
   162  */
   245  */
   247  */
   246 class NormalVertex: public Vertex
   248 class NormalVertex: public Vertex
   247 {
   249 {
   248 public:
   250 public:
   249 	Vector3 N;
   251 	Vector3 N;
       
   252 	NormalVertex(const NormalVertex *v): Vertex(v->P), N(v->N) {};
   250 	NormalVertex(const Vector3 &aP): Vertex(aP) {};
   253 	NormalVertex(const Vector3 &aP): Vertex(aP) {};
   251 	NormalVertex(const Vector3 &aP, const Vector3 &aN): Vertex(aP), N(aN) {};
   254 	NormalVertex(const Vector3 &aP, const Vector3 &aN): Vertex(aP), N(aN) {};
   252 	const Vector3 &getNormal() { return N; };
   255 	const Vector3 &getNormal() { return N; };
   253 	void setNormal(const Vector3 &aN) { N = aN; };
   256 	void setNormal(const Vector3 &aN) { N = aN; };
   254 };
   257 };
   269 #endif
   272 #endif
   270 #ifdef TRI_PLUCKER
   273 #ifdef TRI_PLUCKER
   271 	Float pla[6], plb[6], plc[6];
   274 	Float pla[6], plb[6], plc[6];
   272 #endif
   275 #endif
   273 	Vector3 N;
   276 	Vector3 N;
   274 	bool smooth;
       
   275 	const Vector3 smooth_normal(const Vector3 &P) const
   277 	const Vector3 smooth_normal(const Vector3 &P) const
   276 	{
   278 	{
   277 #ifdef TRI_BARI_PRE
   279 #ifdef TRI_BARI_PRE
   278 		const Vector3 &NA = static_cast<NormalVertex*>(A)->N;
   280 		const Vector3 &NA = static_cast<NormalVertex*>(A)->N;
   279 		const Vector3 &NB = static_cast<NormalVertex*>(B)->N;
   281 		const Vector3 &NB = static_cast<NormalVertex*>(B)->N;
   298 	Triangle() {};
   300 	Triangle() {};
   299 	Triangle(Vertex *aA, Vertex *aB, Vertex *aC, Material *amaterial);
   301 	Triangle(Vertex *aA, Vertex *aB, Vertex *aC, Material *amaterial);
   300 	bool intersect(const Ray &ray, Float &dist) const;
   302 	bool intersect(const Ray &ray, Float &dist) const;
   301 	bool intersect_all(const Ray &ray, Float dist, vector<Float> &allts) const {return false;};
   303 	bool intersect_all(const Ray &ray, Float dist, vector<Float> &allts) const {return false;};
   302 	bool intersect_bbox(const BBox &bbox) const;
   304 	bool intersect_bbox(const BBox &bbox) const;
   303 	const Vector3 normal(const Vector3 &P) const { return (smooth ? smooth_normal(P) : N); };
   305 	const Vector3 normal(const Vector3 &P) const { return (material->smooth ? smooth_normal(P) : N); };
   304 	const Vector3 getNormal() const { return N; };
   306 	const Vector3 getNormal() const { return N; };
   305 	void setSmooth() { smooth = true; };//(typeid(*A) == typeid(*B) == typeid(*C) == typeid(NormalVertex)); };
       
   306 	void setFlat() { smooth = false; };
       
   307 	bool getSmooth() const { return smooth; };
       
   308 	BBox get_bbox() const;
   307 	BBox get_bbox() const;
   309 };
   308 };
   310 
   309 
   311 template <class T> class Array
   310 template <class T> class Array
   312 {
   311 {