bevy icon indicating copy to clipboard operation
bevy copied to clipboard

Basic isometry types

Open mweatherley opened this issue 7 months ago • 1 comments

Objective

Introduce isometry types for describing relative and absolute position in mathematical contexts.

Solution

For the time being, this is a very minimal implementation. This implements the following faculties for two- and three-dimensional isometry types:

  • Identity transformations
  • Creation from translations and/or rotations
  • Inverses
  • Multiplication (composition) of isometries with each other
  • Application of isometries to points (as vectors)
  • Conversion of isometries to affine transformations

There is obviously a lot more that could be added, so I erred on the side of adding things that I knew would be useful, with the idea of expanding this in the near future as needed.

(I also fixed some random doc problems in bevy_math.)


Design

One point of interest here is the matter of if/when to use aligned types. In the implementation of 3d isometries, I used Vec3A rather than Vec3 because it has no impact on size/alignment, but I'm still not sure about that decision (although it is easily changed).

For 2d isometries — which are encoded by four floats — the idea of shoving them into a single 128-bit buffer (__m128 or whatever) sounds kind of enticing, but it's more involved and would involve writing unsafe code, so I didn't do that for now.

Future work

  • Expand the API to include shortcuts like inverse_mul and inverse_transform for efficiency reasons.
  • Include more convenience constructors and methods (e.g. from_xy, from_xyz).
  • Refactor bevy_math::bounding to use the isometry types.
  • Add conversions to/from isometries for Transform/GlobalTransform in bevy_transform.

mweatherley avatar Jul 10 '24 18:07 mweatherley