201 { |
201 { |
202 return pla[0]*plb[4] + pla[1]*plb[5] + pla[2]*plb[3] + pla[4]*plb[0] + pla[5]*plb[1] + pla[3]*plb[2]; |
202 return pla[0]*plb[4] + pla[1]*plb[5] + pla[2]*plb[3] + pla[4]*plb[0] + pla[5]*plb[1] + pla[3]*plb[2]; |
203 } |
203 } |
204 #endif |
204 #endif |
205 |
205 |
206 Triangle::Triangle(const Vector3 &aA, const Vector3 &aB, const Vector3 &aC, Material *amaterial) |
206 Triangle::Triangle(Vertex *aA, Vertex *aB, Vertex *aC, Material *amaterial) |
207 : A(aA), B(aB), C(aC) |
207 : smooth(false), A(aA), B(aB), C(aC) |
208 { |
208 { |
209 material = amaterial; |
209 material = amaterial; |
210 material->reflection = 0; |
210 material->reflection = 0; |
211 |
211 |
212 const Vector3 c = B - A; |
212 const Vector3 c = B->P - A->P; |
213 const Vector3 b = C - A; |
213 const Vector3 b = C->P - A->P; |
214 |
214 |
215 N = -cross(c, b); |
215 N = cross(c, b); |
216 N.normalize(); |
216 N.normalize(); |
217 |
217 |
218 #ifdef TRI_PLUCKER |
218 #ifdef TRI_PLUCKER |
219 Plucker(B,C,pla); |
219 Plucker(B->P,C->P,pla); |
220 Plucker(C,A,plb); |
220 Plucker(C->P,A->P,plb); |
221 Plucker(A,B,plc); |
221 Plucker(A->P,B->P,plc); |
222 #endif |
222 #endif |
223 |
223 |
224 #if defined(TRI_BARI) || defined(TRI_BARI_PRE) |
224 #if defined(TRI_BARI) || defined(TRI_BARI_PRE) |
225 if (fabsf(N.x) > fabsf(N.y)) |
225 if (fabsf(N.x) > fabsf(N.y)) |
226 { |
226 { |
287 const Float t = (nd - O[k] - nu * O[u] - nv * O[v]) / (D[k] + nu * D[u] + nv * D[v]); |
287 const Float t = (nd - O[k] - nu * O[u] - nv * O[v]) / (D[k] + nu * D[u] + nv * D[v]); |
288 |
288 |
289 if (t >= dist || t < Eps) |
289 if (t >= dist || t < Eps) |
290 return false; |
290 return false; |
291 |
291 |
292 const Float hu = O[u] + t * D[u] - A[u]; |
292 const Float hu = O[u] + t * D[u] - A->P[u]; |
293 const Float hv = O[v] + t * D[v] - A[v]; |
293 const Float hv = O[v] + t * D[v] - A->P[v]; |
294 const Float beta = hv * bnu + hu * bnv; |
294 const Float beta = hv * bnu + hu * bnv; |
295 |
295 |
296 if (beta < 0.) |
296 if (beta < 0.) |
297 return false; |
297 return false; |
298 |
298 |
299 const Float gamma = hu * cnv + hv * cnu; |
299 const Float gamma = hu * cnv + hv * cnu; |
300 if (gamma < 0. || beta + gamma > 1) |
300 if (gamma < 0. || beta + gamma > 1.) |
301 return false; |
301 return false; |
302 |
302 |
303 dist = t; |
303 dist = t; |
304 return true; |
304 return true; |
305 #endif |
305 #endif |
331 } |
331 } |
332 |
332 |
333 BBox Triangle::get_bbox() const |
333 BBox Triangle::get_bbox() const |
334 { |
334 { |
335 BBox bbox = BBox(); |
335 BBox bbox = BBox(); |
336 bbox.L = A; |
336 bbox.L = A->P; |
337 if (B.x < bbox.L.x) bbox.L.x = B.x; |
337 if (B->P.x < bbox.L.x) bbox.L.x = B->P.x; |
338 if (C.x < bbox.L.x) bbox.L.x = C.x; |
338 if (C->P.x < bbox.L.x) bbox.L.x = C->P.x; |
339 if (B.y < bbox.L.y) bbox.L.y = B.y; |
339 if (B->P.y < bbox.L.y) bbox.L.y = B->P.y; |
340 if (C.y < bbox.L.y) bbox.L.y = C.y; |
340 if (C->P.y < bbox.L.y) bbox.L.y = C->P.y; |
341 if (B.z < bbox.L.z) bbox.L.z = B.z; |
341 if (B->P.z < bbox.L.z) bbox.L.z = B->P.z; |
342 if (C.z < bbox.L.z) bbox.L.z = C.z; |
342 if (C->P.z < bbox.L.z) bbox.L.z = C->P.z; |
343 bbox.H = A; |
343 bbox.H = A->P; |
344 if (B.x > bbox.H.x) bbox.H.x = B.x; |
344 if (B->P.x > bbox.H.x) bbox.H.x = B->P.x; |
345 if (C.x > bbox.H.x) bbox.H.x = C.x; |
345 if (C->P.x > bbox.H.x) bbox.H.x = C->P.x; |
346 if (B.y > bbox.H.y) bbox.H.y = B.y; |
346 if (B->P.y > bbox.H.y) bbox.H.y = B->P.y; |
347 if (C.y > bbox.H.y) bbox.H.y = C.y; |
347 if (C->P.y > bbox.H.y) bbox.H.y = C->P.y; |
348 if (B.z > bbox.H.z) bbox.H.z = B.z; |
348 if (B->P.z > bbox.H.z) bbox.H.z = B->P.z; |
349 if (C.z > bbox.H.z) bbox.H.z = C.z; |
349 if (C->P.z > bbox.H.z) bbox.H.z = C->P.z; |
350 return bbox; |
350 return bbox; |
351 }; |
351 }; |