Working triangles!
This commit is contained in:
parent
00aedc5531
commit
7b2e52cedb
@ -12,7 +12,7 @@ const (
|
||||
Width = 512
|
||||
Height = 512
|
||||
ObjectFile = "head.obj"
|
||||
Repeat = 1 //00_000
|
||||
Repeat = 100_000
|
||||
)
|
||||
|
||||
func must(err error) {
|
||||
|
@ -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)))
|
||||
|
Loading…
Reference in New Issue
Block a user