accmltr / scala-games

A game engine for writing games in Scala.
MIT License
4 stars 0 forks source link

Fix polygon render bug #15

Closed accmltr closed 10 months ago

accmltr commented 10 months ago

The following leaves an unfilled triangle:

val p1 = RenderedMesh(
      shader = shader,
      transform = Matrix3
        .transform(
          translation = Vector2(
            cos(1.7f * Time.current + 5f) * .2,
            sin(3f * Time.current + 3f) * .11
          ),
          rotation = cos(.8f * Time.current + 3f) * 2f * pi,
          scale = Vector2(1f, 1f) * (.2f + .1f * (cos(.8f * Time.current) + 1))
        ),
      mesh = Mesh(
        Polygon(
          Vector(
            Vector2(0, 0),
            Vector2(1, 0),
            Vector2(1, 1),
            Vector2(0, 1),
            Vector2(0, .8),
            Vector2(0.35, 0.5),
            Vector2(0, .2)
          ).map(v => Vector2(v.x - .5, v.y - .5))
        )
      ),
      tint = Color.YELLOW * .75
    )

I assume this happens since the first and last line segments found distinct valid points, and their triangles don't share an edge.

Screenshots: image image

accmltr commented 10 months ago

The rest of the code can be found in the 9ee9e32 commit.