/* * rayshade interface */ #include "config.h" #include #include #include "ray_int.h" ray_int::ray_int (ostream &out) t_no : o(out) { } ray_int::~ray_int () t_no { } void ray_int::begin_fig () t_no { x1 = 1e10; y1 = 1e10; z1 = 1e10; x2 = -1e10; y2 = -1e10; z2 = -1e10; } void ray_int::end_fig () t_no { x1 -= 0.1; y1 -= 0.1; z1 -= 0.1; x2 += 0.1; y2 += 0.1; z2 += 0.2; } void ray_int::clip (const vec &v) t_no { if (x1 > v[0]) x1 = v[0]; if (y1 > v[1]) y1 = v[1]; if (z1 > v[2]) z1 = v[2]; if (x2 < v[0]) x2 = v[0]; if (y2 < v[1]) y2 = v[1]; if (z2 < v[2]) z2 = v[2]; } void ray_int::check_attrs (const attribute_set &attr) t_err { width = attr ("width",1); color = attr ("color", vec( 0.8, 0.8, 0.8)); } #define OV(v) v[0] << " " << v[1] << " " << v[2] void ray_int::segment (const point &a, const point &b) t_err { check_attrs (a.attr); clip (a.v); clip (b.v); o << "cylinder " << width << " " << OV(a.v) << " " << OV(b.v) << endl; } void ray_int::object (const points &v) t_err { points p = v; // cerr << "polygon "; for (points::const_iterator j = v.begin (); j != v.end (); j++) cerr << j->first << " "; cerr << endl; if (v.size () < 3) return; if (winding (p) < 0) reverse (p.begin (), p.end ()); check_attrs (p.front ().attr); points::const_iterator a, b, c; c = p.begin (); a = c++; b = c++; clip (a->v); clip (b->v); while (c != p.end ()) { clip (c->v); o << "triangle " << OV(a->v) << " " << OV(a->n) << endl; o << " " << OV(b->v) << " " << OV(b->n) << endl; o << " " << OV(c->v) << " " << OV(c->n) << endl; ++b; ++c; } o << endl; }