ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/lsys/ray_int.cpp
Revision: 1.1
Committed: Thu Nov 6 14:31:24 2008 UTC (15 years, 6 months ago) by root
Branch: MAIN
CVS Tags: HEAD
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.1 /*
2     * rayshade interface
3     */
4    
5     #include "config.h"
6    
7     #include <iostream>
8     #include <algorithm>
9    
10     #include "ray_int.h"
11    
12     ray_int::ray_int (ostream &out) t_no
13     : o(out)
14     {
15     }
16    
17     ray_int::~ray_int () t_no
18     {
19     }
20    
21     void ray_int::begin_fig () t_no
22     {
23     x1 = 1e10; y1 = 1e10; z1 = 1e10;
24     x2 = -1e10; y2 = -1e10; z2 = -1e10;
25     }
26    
27     void ray_int::end_fig () t_no
28     {
29     x1 -= 0.1; y1 -= 0.1; z1 -= 0.1;
30     x2 += 0.1; y2 += 0.1; z2 += 0.2;
31     }
32    
33     void ray_int::clip (const vec &v) t_no
34     {
35     if (x1 > v[0]) x1 = v[0];
36     if (y1 > v[1]) y1 = v[1];
37     if (z1 > v[2]) z1 = v[2];
38    
39     if (x2 < v[0]) x2 = v[0];
40     if (y2 < v[1]) y2 = v[1];
41     if (z2 < v[2]) z2 = v[2];
42     }
43    
44     void ray_int::check_attrs (const attribute_set &attr) t_err
45     {
46     width = attr ("width",1);
47     color = attr ("color", vec( 0.8, 0.8, 0.8));
48     }
49    
50     #define OV(v) v[0] << " " << v[1] << " " << v[2]
51    
52     void ray_int::segment (const point &a, const point &b) t_err
53     {
54     check_attrs (a.attr);
55    
56     clip (a.v);
57     clip (b.v);
58    
59     o << "cylinder " << width << " " << OV(a.v) << " " << OV(b.v) << endl;
60     }
61    
62     void ray_int::object (const points &v) t_err
63     {
64     points p = v;
65     // cerr << "polygon "; for (points::const_iterator j = v.begin (); j != v.end (); j++) cerr << j->first << " "; cerr << endl;
66     if (v.size () < 3)
67     return;
68    
69     if (winding (p) < 0)
70     reverse (p.begin (), p.end ());
71    
72     check_attrs (p.front ().attr);
73    
74     points::const_iterator a, b, c;
75     c = p.begin ();
76     a = c++;
77     b = c++;
78    
79     clip (a->v);
80     clip (b->v);
81     while (c != p.end ())
82     {
83     clip (c->v);
84     o << "triangle " << OV(a->v) << " " << OV(a->n) << endl;
85     o << " " << OV(b->v) << " " << OV(b->n) << endl;
86     o << " " << OV(c->v) << " " << OV(c->n) << endl;
87     ++b; ++c;
88     }
89    
90     o << endl;
91     }
92    
93