Original Post
So I thought I'd have a stab at writing a software rasteriser in preparation for my studies next year but I've gotten stuck with drawing a filled triangle.
Here is the method in its entirety:
This works up to a point. Let me illustrate:

This is how it should look. In my test I am slowly increasing the Y component of the top most point so that it moves down the screen. When it reaches a certain Y value this happens:

I think it's to do with how I'm sorting the points in a clockwise order since when it goes all screwy like that it starts sorting the points in counter-clockwise order and I don't know why =/
Starting to think that embarking on all this game programming was not a wise decision considering how relatively weak my understanding of mathematics is!
Can anyone point me in the right direction?
Here is the method in its entirety:
float minY = 9999999999999999, maxY = 0; // Find the minimum and maximum Y points for(int i = 0; i < 3; i++) { if(vertices.Position.Y < minY) { minY = vertices.Position.Y; } if(vertices.Position.Y > maxY) { maxY = vertices.Position.Y; } } // This should order the vertices in clockwise order bool switchMade = false; float cX = (vertices[0].Position.X + vertices[1].Position.X + vertices[2].Position.X) / 3; float cY = (vertices[0].Position.Y + vertices[1].Position.Y + vertices[2].Position.Y) / 3; float cAng = atan2(cY, cX); do { switchMade = false; for(int i = 0; i < 2; i++) { float ang1 = atan2(vertices.Position.Y, vertices.Position.X); float ang2 = atan2(vertices[i + 1].Position.Y, vertices[i + 1].Position.X); ang1 = cAng - ang1; ang2 = cAng - ang2; if(ang1 < ang2) { Vertex temp = vertices; vertices = vertices[i + 1]; vertices[i + 1] = temp; switchMade = true; } } } while (switchMade); float dxLeft = (vertices[2].Position.X - vertices[0].Position.X) / (maxY - minY); float dxRight = (vertices[1].Position.X - vertices[0].Position.X) / (maxY - minY); float xLineLeft = vertices[0].Position.X; float xLineRight = vertices[0].Position.X; for(int y = minY; y < maxY; y++) { Vertex lineVerts[2]; lineVerts[0].Position.X = xLineLeft; lineVerts[0].Position.Y = y; lineVerts[1].Position.X = xLineRight; lineVerts[1].Position.Y = y; DrawLine(lineVerts); xLineLeft += dxLeft; xLineRight += dxRight; }This works up to a point. Let me illustrate:

This is how it should look. In my test I am slowly increasing the Y component of the top most point so that it moves down the screen. When it reaches a certain Y value this happens:

I think it's to do with how I'm sorting the points in a clockwise order since when it goes all screwy like that it starts sorting the points in counter-clockwise order and I don't know why =/
Starting to think that embarking on all this game programming was not a wise decision considering how relatively weak my understanding of mathematics is!
Can anyone point me in the right direction?