#ifndef TRI_MESH_H #define TRI_MESH_H #include #include "lin_alg.h" #include "entity.h" #include "triangle.h" #include "texture_eval.h" struct tri_struct { tri_struct(int x, int y, int z) {a=x; b=y; c=z;} vector3d norm; int a, b, c; }; struct tri_mesh : Entity { tri_mesh(){phong = false; texture = 0;} tri_mesh(const char*file) {load(file); texture = 0;} virtual ~tri_mesh(){} void load(const char*file); std::vector pts; std::vector tris; std::vector norms; bool phong; TextureEval * texture; virtual RayIntersect CalcRayIntersect(Ray ray, int flags, int special=-1); virtual vector3d CalcNormal(Ray ray, RayIntersect& ri) { tri_struct & ts = tris[ri.special]; if(phong) { double aa = ri.special0; double bb = ri.special1; double cc = 1 - aa - bb; return (norms[ts.a] * aa + norms[ts.b] * bb + norms[ts.c] * cc).ret_unit(); } else { return ts.norm; } } virtual void PathCompress(const Transform&, queue >&, vector&); virtual int IntersectionTest(Ray ray, int flags, int special=-1); virtual void GridCollect(vector& vec); virtual Color GetTextureColor(Ray ray, RayIntersect& ri) { if(!texture) return Color(); Color c; c.rgb = texture->Eval(ray.o + ray.d * ri.param_t); return c; } virtual bool HasTexture() {return (bool)texture;} void SetTexture(TextureEval * t) {texture = t;} void CalcNorms(); }; #endif