42 #if !defined(TRI_PLUCKER) && !defined(TRI_BARI) && !defined(TRI_BARI_PRE) |
42 #if !defined(TRI_PLUCKER) && !defined(TRI_BARI) && !defined(TRI_BARI_PRE) |
43 # define TRI_BARI_PRE |
43 # define TRI_BARI_PRE |
44 #endif |
44 #endif |
45 |
45 |
46 /** |
46 /** |
47 * shape |
47 * abstract shape class |
48 */ |
48 */ |
49 class Shape |
49 class Shape |
50 { |
50 { |
51 public: |
51 public: |
52 Material *material; |
52 Material *material; |
53 |
53 |
54 Shape() {}; |
54 Shape() {}; |
55 virtual ~Shape() {}; |
55 virtual ~Shape() {}; |
56 |
56 |
57 // first intersection point |
57 /** |
|
58 * intersect ray with sphere |
|
59 * @param[in] ray the ray |
|
60 * @param[in] dist maximum allowed distance of intersection |
|
61 * @param[out] dist distance of the intersection if found, unchanged otherwise |
|
62 * @return true if ray intersects the sphere |
|
63 */ |
58 virtual bool intersect(const Ray &ray, Float &dist) const = 0; |
64 virtual bool intersect(const Ray &ray, Float &dist) const = 0; |
59 |
65 |
|
66 /** |
|
67 * same as intersect, but for ray packets |
|
68 */ |
60 #ifndef NO_SIMD |
69 #ifndef NO_SIMD |
61 virtual mfloat4 intersect_packet(const RayPacket &rays, mfloat4 &dists) const |
70 virtual mfloat4 intersect_packet(const RayPacket &rays, mfloat4 &dists) const |
62 { |
71 { |
63 mfloat4 results; |
72 mfloat4 results; |
64 ((int*)&results)[0] = intersect(rays[0], ((float*)&dists)[0]) ? -1 : 0; |
73 ((int*)&results)[0] = intersect(rays[0], ((float*)&dists)[0]) ? -1 : 0; |
67 ((int*)&results)[3] = intersect(rays[3], ((float*)&dists)[3]) ? -1 : 0; |
76 ((int*)&results)[3] = intersect(rays[3], ((float*)&dists)[3]) ? -1 : 0; |
68 return results; |
77 return results; |
69 }; |
78 }; |
70 #endif |
79 #endif |
71 |
80 |
72 // all intersections (only for CSG) |
81 /** get all intersections -- not needed nor used currently */ |
73 virtual bool intersect_all(const Ray &ray, Float dist, vector<Float> &allts) const = 0; |
82 virtual bool intersect_all(const Ray &ray, Float dist, vector<Float> &allts) const = 0; |
74 |
83 |
75 // intersection with AABB |
84 /** test intersection with bounding box */ |
76 virtual bool intersect_bbox(const BBox &bbox) const = 0; |
85 virtual bool intersect_bbox(const BBox &bbox) const = 0; |
77 |
86 |
78 // normal at point P |
87 /** get surface normal at point P */ |
79 virtual const Vector normal(const Vector &P) const = 0; |
88 virtual const Vector normal(const Vector &P) const = 0; |
80 |
89 |
|
90 /** get bounding box of this shape */ |
81 virtual BBox get_bbox() const = 0; |
91 virtual BBox get_bbox() const = 0; |
82 |
92 |
|
93 /** write textual representation of the shape to stream */ |
83 virtual ostream & dump(ostream &st) const = 0; |
94 virtual ostream & dump(ostream &st) const = 0; |
84 }; |
95 }; |
85 |
96 |
86 /** |
97 /** |
87 * list of shapes |
98 * list of shapes |
101 public: |
112 public: |
102 Sphere(const Vector &acenter, const Float aradius, Material *amaterial): |
113 Sphere(const Vector &acenter, const Float aradius, Material *amaterial): |
103 center(acenter), radius(aradius), |
114 center(acenter), radius(aradius), |
104 sqr_radius(aradius*aradius), inv_radius(1.0f/aradius) |
115 sqr_radius(aradius*aradius), inv_radius(1.0f/aradius) |
105 { material = amaterial; } |
116 { material = amaterial; } |
|
117 |
106 bool intersect(const Ray &ray, Float &dist) const; |
118 bool intersect(const Ray &ray, Float &dist) const; |
|
119 #ifndef NO_SIMD |
|
120 mfloat4 intersect_packet(const RayPacket &rays, mfloat4 &dists) const; |
|
121 #endif |
107 bool intersect_all(const Ray &ray, Float dist, vector<Float> &allts) const; |
122 bool intersect_all(const Ray &ray, Float dist, vector<Float> &allts) const; |
108 bool intersect_bbox(const BBox &bbox) const; |
123 bool intersect_bbox(const BBox &bbox) const; |
109 const Vector normal(const Vector &P) const { return (P - center) * inv_radius; }; |
124 const Vector normal(const Vector &P) const { return (P - center) * inv_radius; }; |
110 BBox get_bbox() const; |
125 BBox get_bbox() const; |
|
126 |
111 const Vector getCenter() const { return center; }; |
127 const Vector getCenter() const { return center; }; |
112 Float getRadius() const { return radius; }; |
128 Float getRadius() const { return radius; }; |
113 ostream & dump(ostream &st) const; |
129 |
114 #ifndef NO_SIMD |
130 ostream & dump(ostream &st) const; |
115 mfloat4 intersect_packet(const RayPacket &rays, mfloat4 &dists) const; |
|
116 #endif |
|
117 }; |
131 }; |
118 |
132 |
119 /** |
133 /** |
120 * box shape |
134 * box shape |
121 */ |
135 */ |
130 if (L[i] > H[i]) |
144 if (L[i] > H[i]) |
131 swap(L[i], H[i]); |
145 swap(L[i], H[i]); |
132 material = amaterial; |
146 material = amaterial; |
133 }; |
147 }; |
134 bool intersect(const Ray &ray, Float &dist) const; |
148 bool intersect(const Ray &ray, Float &dist) const; |
|
149 #ifndef NO_SIMD |
|
150 mfloat4 intersect_packet(const RayPacket &rays, mfloat4 &dists) const; |
|
151 #endif |
135 bool intersect_all(const Ray &ray, Float dist, vector<Float> &allts) const { return false; }; |
152 bool intersect_all(const Ray &ray, Float dist, vector<Float> &allts) const { return false; }; |
136 bool intersect_bbox(const BBox &bbox) const; |
153 bool intersect_bbox(const BBox &bbox) const; |
137 const Vector normal(const Vector &P) const; |
154 const Vector normal(const Vector &P) const; |
138 BBox get_bbox() const { return BBox(L, H); }; |
155 BBox get_bbox() const { return BBox(L, H); }; |
|
156 |
139 const Vector getL() const { return L; }; |
157 const Vector getL() const { return L; }; |
140 const Vector getH() const { return H; }; |
158 const Vector getH() const { return H; }; |
141 ostream & dump(ostream &st) const; |
159 |
142 #ifndef NO_SIMD |
160 ostream & dump(ostream &st) const; |
143 mfloat4 intersect_packet(const RayPacket &rays, mfloat4 &dists) const; |
|
144 #endif |
|
145 }; |
161 }; |
146 |
162 |
147 /** |
163 /** |
148 * triangle vertex |
164 * triangle vertex |
149 */ |
165 */ |
217 Vertex *A, *B, *C; |
233 Vertex *A, *B, *C; |
218 |
234 |
219 Triangle() {}; |
235 Triangle() {}; |
220 Triangle(Vertex *aA, Vertex *aB, Vertex *aC, Material *amaterial); |
236 Triangle(Vertex *aA, Vertex *aB, Vertex *aC, Material *amaterial); |
221 bool intersect(const Ray &ray, Float &dist) const; |
237 bool intersect(const Ray &ray, Float &dist) const; |
|
238 #if !defined(NO_SIMD) && defined(TRI_BARI_PRE) |
|
239 mfloat4 intersect_packet(const RayPacket &rays, mfloat4 &dists) const; |
|
240 #endif |
222 bool intersect_all(const Ray &ray, Float dist, vector<Float> &allts) const {return false;}; |
241 bool intersect_all(const Ray &ray, Float dist, vector<Float> &allts) const {return false;}; |
223 bool intersect_bbox(const BBox &bbox) const; |
242 bool intersect_bbox(const BBox &bbox) const; |
224 const Vector normal(const Vector &P) const { return (material->smooth ? smooth_normal(P) : N); }; |
243 const Vector normal(const Vector &P) const { return (material->smooth ? smooth_normal(P) : N); }; |
|
244 BBox get_bbox() const; |
|
245 |
|
246 /** get real normal of the triangle */ |
225 const Vector getNormal() const { return N; }; |
247 const Vector getNormal() const { return N; }; |
226 BBox get_bbox() const; |
248 |
227 ostream & dump(ostream &st) const; |
249 ostream & dump(ostream &st) const; |
228 #if !defined(NO_SIMD) && defined(TRI_BARI_PRE) |
250 }; |
229 mfloat4 intersect_packet(const RayPacket &rays, mfloat4 &dists) const; |
251 |
230 #endif |
252 /** template for triangle arrays, currently not used */ |
231 }; |
|
232 |
|
233 template <class T> class Array |
253 template <class T> class Array |
234 { |
254 { |
235 T *array; |
255 T *array; |
236 public: |
256 public: |
237 Array(int n) { array = new T[n]; }; |
257 Array(int n) { array = new T[n]; }; |