bevy icon indicating copy to clipboard operation
bevy copied to clipboard

API for rotation alignment

Open torsteingrindvik opened this issue 1 year ago • 0 comments

What problem does this solve or what need does it fill?

Aligning an entity's coordinate-system to align towards a direction or towards a point.

What solution would you like?

Bevy already has:

But these look APIs are camera-oriented since the goal is to align the camera forward to look in a direction or towards a point.

My goal is to instead align the coordinate-system itself.

So perhaps instead of

// Existing API
pub fn looking_to(self, direction: Vec3, up: Vec3) -> Transform
pub fn looking_at(self, target: Vec3, up: Vec3) -> Transform

// New extra API, name tbd
pub fn align_towards_direction(self, direction: Vec3, up: Vec3) -> Transform
pub fn align_towards_point(self, target: Vec3, up: Vec3) -> Transform

An example of what it does:

// no-op, identity is already aligned as such
let t = Transform::IDENTITY.align_towards_direction(Vec3::X, Vec::Y);

// 90 degree rotation, old X axis is now aligned with old -Z direction,
// Y is still up in both cases
let t2 = Transform::IDENTITY.align_towards_direction(Vec3::NEG_Z, Vec::Y);

So essentially it does the same as looking_to/at but it favors (aligns) another axis.

Therefore perhaps even a more general API could be considered where a user can specify which axis is the target for alignment, and the other APIs can be expressed in terms of that.

What alternative(s) have you considered?

Using the looking_* APIs then doing another rotation after that.

torsteingrindvik avatar Feb 09 '24 11:02 torsteingrindvik