Computer graphics in Game development
Ivan Belyavtsev
24.01.2020
Let’s take two points \((X, Y)\) and \((X+dx, Y=dy)\)
Define an edge function:
\[E(x, y) = (x - X)dy - (y - Y)dx\]
[1]
If \(E(x, y)>0\) then \((x, y)\) on the “right” side
If \(E(x, y)<0\) then \((x, y)\) on the “left” side
If \(E(x, y)=0\) then \((x, y)\) on the edge
[1]
[1]
[2]
Let’s implement it together
Let exists \[P=uA+vB+wC\], where \(u+v+w=1\)
[3]
\[(u_1, u_2, 0) \times (v_1, v_2, 0) = (0, 0, u_1v_1-u_2v_1)\]
and compare with
\[E(x, y) = (x - X)dy - (y - Y)dx\]
Let’s implement it together
1. Pineda J. A parallel algorithm for polygon rasterization // Proceedings of the 15th annual conference on computer graphics and interactive techniques. 1988. Pp. 17–20.
2. Rasterization: A practical implementation [Electronic resource]. 2015. URL: https://www.scratchapixel.com/lessons/3d-basic-rendering/rasterization-practical-implementation/rasterization-stage.
3. Ray tracing: Rendering a triangle [Electronic resource]. 2014. URL: https://www.scratchapixel.com/lessons/3d-basic-rendering/ray-tracing-rendering-a-triangle/barycentric-coordinates.