Triangle Filling Algorithm

My Triangle Filling Algorithm ^^


 So yeah, I've been working on a 3D Engine for some days now, and it's being a really interesting project. Lots of Math! XD.

So part of the function I need in the engine would be to fill my primaries(in my engine's case, triangles) with a solid color.

Since I have little knowledge no experience in these stuff, I looked up for "simple triangle filling algorithms" online. 

Almost unanimously, all I could find was an algorithm making use of horizontal lines, interpolation and stuff.

It was easy to understand, but I felt like it could not be the simplest algorithm out there, so I decided to try coming up with my own XD

The Math behind it is very simple; only basic vector(direction vector and basic vector arithmetic) knowledge is required.

For my implementation, in C, I made use of a few structs.





And so my Algorithm is(Explanation after this):






And  yes, the Z component is unused. That is because this function is called after the 3D coordinates are projected onto a 2D plane (After applying Projection and other transformation matrices).
There is no Vec2f, and I think i would add unnecessary complexity anyways.

Oh yeah, I used the SDL2.0 Library to draw the lines. This can be swapped for any other function to draw a line on a screen using two points.

An Explanation coming right up! :D:




Hope it was clear ^^.


I think I should post a result too right?...

Without the function:

With the function:


That's all aye XD

Thanks, Stay alive, peace


Comments

Popular Posts