Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add geometry package and a rasterizer #520

Merged
merged 16 commits into from
Sep 7, 2024
Merged

Add geometry package and a rasterizer #520

merged 16 commits into from
Sep 7, 2024

Conversation

JD557
Copy link
Owner

@JD557 JD557 commented Sep 7, 2024

Inspired by #514

Adds a new Rasterizer that is able to render Shapes.

A Shape is just an abstraction that:

  • Can return a bounding box that contains the shape
  • Can tell if a point is inside a shape, and what side is facing the viewer

There are a few more methods and optimizations, but this are the basic ones. Right now there are two public shapes (ConvexPolygon and Circle), but it's not that hard to implement custom ones.

A large part of the ConvexPolygon implementation was based on https://jtsorlinis.github.io/rendering-tutorial/

Due to the way shapes are implemented, matrix operations is a bit weird:

  • "Can return a bounding box that contains the shape" benefits from being able to map points
  • "Can tell if a point is inside a shape, and what side is facing the viewer" benefits from being able to contramap points

So, for the general case, the transformation matrix needs to be inverted, as both versions of the matrix are needed.
However, concrete implementations can sometimes get away with just mapping points so, in this case, Shape#contramapMatrix is implemented using Shape#mapMatrix.

This is in contrast with Planes, which benefit from contramappings. So, I ended up refactoring a lot of the Matrix code in this PR as well. Which has the benefit that now it's also easier to construct transformation matrices by hand, which can help performance in some situations (e.g. if you can precompute a transformation matrix).

While this breaks the API a bit (I moved Matrix to eu.joaocosta.minart.geometry), I'm going to use the "It's version 0.x excuse" to not bump the major... The ergonomics of the old Matrix and related operations were quite bad, to the point where I doubt anyone would use that directly.

Right now, the API is still experimental. I still want to:

  • Add a higher level API (maybe just something like Shape.circle, Shape.triangle, Shape.square... not sure)
  • Add line drawing algorithms
  • Add some examples.

@JD557 JD557 added this to the 0.6.2 milestone Sep 7, 2024
@JD557 JD557 self-assigned this Sep 7, 2024
@JD557 JD557 merged commit 968a07e into master Sep 7, 2024
15 checks passed
@JD557 JD557 deleted the geometry branch September 7, 2024 13:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant