Working triangles!

This commit is contained in:
Carlos Sanchez 2024-07-26 19:57:36 -04:00
parent 00aedc5531
commit 7b2e52cedb
2 changed files with 9 additions and 12 deletions

View File

@ -12,7 +12,7 @@ const (
Width = 512
Height = 512
ObjectFile = "head.obj"
Repeat = 1 //00_000
Repeat = 100_000
)
func must(err error) {

View File

@ -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
// 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
} else {
}
for y := v0.Y; y <= v2.Y; y++ {
xleft := int(math.Floor(float64(xshort)))