rgx.legacy icon indicating copy to clipboard operation
rgx.legacy copied to clipboard

Sprite rotation

Open skyne98 opened this issue 5 years ago • 8 comments

Are there any plans to introduce an ability to rotate sprites added to the sprite batch?

In theory, it should be pretty easily done by introducing something like RotationRect as an extension of Rect, which will contain additional info about the angle and origin of rotation. Later this RotationRect may be used by calling batch.add_rotated. As an alternative, it might be a good solution to go "XNA" way by adding both angle and origin to the direct batch.add call.

skyne98 avatar Jan 27 '20 21:01 skyne98

We did exactly this (the XNA way) for the shape2d pipeline, so should be pretty easy to port over to sprite2d. It is planned, but I don't know when it'll land. Would you want to take a stab at it?

cloudhead avatar Jan 28 '20 16:01 cloudhead

For reference: https://github.com/cloudhead/rgx/pull/10

cloudhead avatar Jan 28 '20 16:01 cloudhead

@cloudhead You can assign me to this, gonna need it anyway.

xla avatar Jan 28 '20 16:01 xla

@xla, in case something goes wrong, I am ready to try to do it as well. Will be keeping my eye on the progress here 😉

skyne98 avatar Jan 29 '20 08:01 skyne98

I have some changes I can post as an early draft for the pull request. The new code supports full matrix transformations for sprites (rotation and scaling with origin). However, there are a couple of downsides, at the moment:

  • New coded crudely uses ultraviolet as a math library (as it seems to be the fastest and I use it for the personal projects)
  • Some more testing needs to be done in regards to correctness of the results, as well as performance

I think those issues can be resolved pretty quickly with some cooperation, providing RGX with some kind of proper sprite transform support. Looking forward to it!

skyne98 avatar Mar 16 '20 12:03 skyne98

Amazing! Looking forward to seeing these changes.

cloudhead avatar Mar 16 '20 20:03 cloudhead

Ok, in this case I will post a pull request as soon as the single sprite rotation transform example code works out as expected!

skyne98 avatar Mar 17 '20 09:03 skyne98

@cloudhead, posted a draft pull request. This is my first pull request on GitHub, so sorry if something is done incorrectly! Waiting for feedback!

skyne98 avatar Mar 23 '20 22:03 skyne98