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

Support rotated sprites (and rotated hit boxes) #255

Merged
merged 6 commits into from
Oct 4, 2023

Conversation

hmeine
Copy link
Contributor

@hmeine hmeine commented Sep 19, 2023

This is certainly more expensive than the old code, but also much more correct and future-proof: Inverting the affine transform allows to support rotated sprites as well.

I also adapted the sprite example to demonstrate the feature.

I am sure that glam offers very fast Affine3A inversion, yet I think it would be possible to speed this up in theory. Not sure that caching the inverted transform makes much sense, since many global transforms would be invalidated very often.

On the other hand, we only perform a 2D hit box test, but the affine transform is 3D; one could skip computing the z coordinate AFAICS.

Finally, an option for speedups would be to make the kind of test configurable; if it is known that certain sprites are never rotated (or even scaled), the computation could take a simpler path. Such configurability would also allow for a more expensive path: Testing the sprite pixmap for transparency at the pointer position would now be a low hanging fruit.

We want to take into account not only the translation part of the global
transform, but also the scaling.  At the moment, rotations are still not
dealt with.

I am also not sure how performant the `to_scale_rotation_translation()`
method is.  (I think a different API could be faster, because we do not
really need the decomposition.)
This is certainly more expensive than the old code, but also much more
correct and future-proof: Inverting the affine transform allows to
support rotated sprites as well.

I also adapted the `sprite` example to demonstrate the feature.

I am sure that glam offers very fast Affine3A inversion, yet I think it
would be possible to speed this up in theory.  Not sure that caching
the inverted transform makes much sense, since many global transforms
would be invalidated very often.

On the other hand, we only perform a 2D hit box test, but the affine
transform is 3D; one could skip computing the z coordinate AFAICS.

Finally, an option for speedups would be to make the kind of test
configurable; if it is known that certain sprites are never rotated (or
even scaled), the computation could take a simpler path.  Such
configurability would also allow for a more expensive path: Testing the
sprite pixmap for transparency at the pointer position would now be a
low hanging fruit.
@aevyrie aevyrie merged commit 7a66eb0 into aevyrie:main Oct 4, 2023
1 check passed
@aevyrie
Copy link
Owner

aevyrie commented Oct 4, 2023

Thank you!

Such configurability would also allow for a more expensive path: Testing the sprite pixmap for transparency at the pointer position would now be a low hanging fruit.

Definitely something I would like to support.

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.

2 participants