diff --git a/tinyrender2/main.go b/tinyrender2/main.go index 3fa0aa0..b9d147d 100644 --- a/tinyrender2/main.go +++ b/tinyrender2/main.go @@ -12,7 +12,7 @@ const ( Width = 512 Height = 512 ObjectFile = "head.obj" - Repeat = 1 //00_000 + Repeat = 100_000 ) func must(err error) { diff --git a/tinyrender2/render.go b/tinyrender2/render.go index 220020b..f1a8b3d 100644 --- a/tinyrender2/render.go +++ b/tinyrender2/render.go @@ -59,24 +59,21 @@ func Triangle1(fb *Framebuffer, color uint, v0 Vec2i, v1 Vec2i, v2 Vec2i) { if v2.Y < v1.Y { v1, v2 = v2, v1 } + //log.Print(v0, v1, v2) // Don't worry about speed for now... - dy := float32(v2.Y-v0.Y) - 0.5 var v02step, v01step, v12step, xlong, xshort float32 - xlong = float32(v0.X) + 0.5 + xlong = float32(v0.X) xshort = xlong // We can check just for greater than because we sorted the vertices - if dy > 0 { - v02step = (float32(v2.X-v0.X) - 0.5) / dy // long side always - v01step = (float32(v1.X-v0.X) - 0.5) / dy // first short side - v12step = (float32(v2.X-v1.X) - 0.5) / dy // second short side - xshort += v01step / 2 - xlong += v02step / 2 - } else { - - } + // Assume 02 is on the right(?) and 01 on the left + v02step = (float32(v2.X - v0.X)) / (float32(v2.Y-v0.Y) + 0.001) // long side always + v01step = (float32(v1.X - v0.X)) / (float32(v1.Y-v0.Y) + 0.001) // first short side + v12step = (float32(v2.X - v1.X)) / (float32(v2.Y-v1.Y) + 0.001) // second short side + xshort += v01step / 2 + xlong += v02step / 2 for y := v0.Y; y <= v2.Y; y++ { xleft := int(math.Floor(float64(xshort)))