cgfs:shaded_triangles
差分
このページの2つのバージョン間の差分を表示します。
両方とも前のリビジョン前のリビジョン次のリビジョン | 前のリビジョン | ||
cgfs:shaded_triangles [2024/06/14 00:52] – freemikan | cgfs:shaded_triangles [2024/07/12 03:20] (現在) – freemikan | ||
---|---|---|---|
行 1: | 行 1: | ||
- | <codeprism lang=cpp el=true css=full> | + | {{: |
+ | |||
+ | |||
+ | <file cpp> | ||
#include < | #include < | ||
行 33: | 行 36: | ||
*out++ = d; | *out++ = d; | ||
d += a; | d += a; | ||
- | } | ||
- | } | ||
- | |||
- | void DrawLine(vec2 const &p0, vec2 const &p1, Color const &color) { | ||
- | auto x0 = p0.x; | ||
- | auto y0 = p0.y; | ||
- | auto x1 = p1.x; | ||
- | auto y1 = p1.y; | ||
- | |||
- | if (std:: | ||
- | if (x0 > x1) { | ||
- | std:: | ||
- | std:: | ||
- | } | ||
- | auto i0 = static_cast< | ||
- | auto i1 = static_cast< | ||
- | auto ys = std:: | ||
- | Interpolate(i0, | ||
- | for (int i = i0; i <= i1; ++i) { | ||
- | PutPixel(i, ys[i - i0], color); | ||
- | } | ||
- | } else { | ||
- | if (y0 > y1) { | ||
- | std:: | ||
- | std:: | ||
- | } | ||
- | auto i0 = static_cast< | ||
- | auto i1 = static_cast< | ||
- | auto xs = std:: | ||
- | Interpolate(i0, | ||
- | for (int i = i0; i <= i1; ++i) { | ||
- | PutPixel(xs[i - i0], i, color); | ||
- | } | ||
- | } | ||
- | } | ||
- | |||
- | void DrawWireframeTriangle(vec2 const &p0, | ||
- | vec2 const &p1, | ||
- | vec2 const &p2, | ||
- | Color const &color) { | ||
- | DrawLine(p0, | ||
- | DrawLine(p1, | ||
- | DrawLine(p2, | ||
- | } | ||
- | |||
- | void DrawFilledTriangle(vec2 const &p0, | ||
- | vec2 const &p1, | ||
- | vec2 const &p2, | ||
- | Color const &color) { | ||
- | vec2 P0{p0}, P1{p1}, P2{p2}; | ||
- | if (P1.y < P0.y) { | ||
- | std:: | ||
- | } | ||
- | if (P2.y < P0.y) { | ||
- | std:: | ||
- | } | ||
- | if (P2.y < P1.y) { | ||
- | std:: | ||
- | } | ||
- | |||
- | auto i0 = static_cast< | ||
- | auto i1 = static_cast< | ||
- | auto i2 = static_cast< | ||
- | auto x01 = std:: | ||
- | auto x12 = std:: | ||
- | auto x02 = std:: | ||
- | |||
- | Interpolate(i0, | ||
- | Interpolate(i1, | ||
- | Interpolate(i0, | ||
- | |||
- | x01.pop_back(); | ||
- | |||
- | auto x012 = std:: | ||
- | assert(x012.size() == x02.size()); | ||
- | |||
- | auto corner = std:: | ||
- | std:: | ||
- | |||
- | auto x_left = x012; | ||
- | auto x_right = x02; | ||
- | auto m = x012.size() / 2; | ||
- | if (x02[m] < x012[m]) { | ||
- | x_left = x02; | ||
- | x_right = x012; | ||
- | } | ||
- | |||
- | for (int y = i0; y < i2; ++y) { | ||
- | auto x_begin = static_cast< | ||
- | auto x_end = static_cast< | ||
- | for (int x = x_begin; x < x_end; ++x) { | ||
- | PutPixel(x, y, color); | ||
- | } | ||
} | } | ||
} | } | ||
行 212: | 行 122: | ||
auto x_r = static_cast< | auto x_r = static_cast< | ||
- | //~ h_segment.resize(x_r - x_l + 1); | ||
h_segment.clear(); | h_segment.clear(); | ||
Interpolate(x_l, | Interpolate(x_l, | ||
行 218: | 行 127: | ||
for (int x = x_l; x <= x_r; ++x) { | for (int x = x_l; x <= x_r; ++x) { | ||
- | | + | |
- | PutPixel(x, y, shaded_color); | + | PutPixel(x, y, color_scaled(color, |
} | } | ||
} | } | ||
行 225: | 行 134: | ||
int main() { | int main() { | ||
- | InitWindow(Cw, | + | InitWindow(Cw, |
VertexPositionIntensity p0{-100, 200, 1.0}; | VertexPositionIntensity p0{-100, 200, 1.0}; | ||
行 241: | 行 150: | ||
} | } | ||
} | } | ||
- | </codeprism> | + | </file> |
cgfs/shaded_triangles.1718293926.txt.gz · 最終更新: 2024/06/14 00:52 by freemikan