]>
Dogcows Code - chaz/rasterize/blob - triangle.hh
3 * CS5600 University of Utah
5 * mcgarvey@eng.utah.edu
19 * A class for a triangle object.
21 class triangle
: public element
30 triangle(vec_t a
, vec_t b
, vec_t c
, color_t color
= COLOR_WHITE
) :
31 a(a
), b(b
), c(c
), material(color
)
37 virtual bool intersect(ray_t ray
, contact_t
& hit
) const
39 plane p
= plane(a
, b
, c
);
40 if (!p
.intersect(ray
, hit
)) {
45 if (barycentric(bc
, hit
.p
)) {
52 virtual color_t
color(vec_t point
) const
58 * Calculate barycentric coordinates for the triangle.
60 bool barycentric(scal_t
* bc
, vec_t v
) const
62 scal_t denom
= (b
.y
- c
.y
) * (a
.x
- c
.x
) + (c
.x
- b
.x
) * (a
.y
- c
.y
);
63 bc
[0] = ((b
.y
- c
.y
) * (v
.x
- c
.x
) + (c
.x
- b
.x
) * (v
.y
- c
.y
)) / denom
;
64 bc
[1] = ((c
.y
- a
.y
) * (v
.x
- c
.x
) + (a
.x
- c
.x
) * (v
.y
- c
.y
)) / denom
;
65 bc
[2] = S(1.0) - bc
[0] - bc
[1];
66 if (S(0.0) <= bc
[0] && bc
[0] <= S(1.0) &&
67 S(0.0) <= bc
[1] && bc
[1] <= S(1.0) &&
68 S(0.0) <= bc
[2] && bc
[2] <= S(1.0)) {
77 * Destroy a new'd triangle, releasing its memory.
80 void triangle_destroy(plane
* t
)
This page took 0.036698 seconds and 4 git commands to generate.