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

New API for absolute transforms #397

Open
aarthificial opened this issue Feb 21, 2023 · 1 comment
Open

New API for absolute transforms #397

aarthificial opened this issue Feb 21, 2023 · 1 comment
Assignees
Labels
a-2d Relates to the 2d package b-enhancement New feature or request c-discussion The issue is being discussed

Comments

@aarthificial
Copy link
Contributor

Description
The current way of accessing absolute transform is a bit verbose.
Additionally, there's no easy way to get the transform of a node relative to another node.

Proposed solution
The current way of retrieving absolute positions/rotations/scales of nodes could be improved to accommodate this:

// current API:
const absolutePosition = node().absolutePosition();
const absoluteRotation = node().absoluteRotation();

// new API:
const absolutePosition = node().abs.position();
const absoluteRotation = node().abs.rotation();
const absoluteLeft = layout().abs.left();

// relative to another node:
const relativePosition = node().abs(anotherNode()).position();
const relativeRotation = node().abs(anotherNode()).rotation();
const relativeLeft = layout().abs(anotherNode()).left();

Here, abs would be a separate entity (a signal-like function with a context), similar to filters, which would reduce the complexity of the Node and Layout classes.

Considered alternatives
You can multiply the matrices of two nodes manually but it's verbose and tedious.

Additional context
Related to #391

@aarthificial aarthificial self-assigned this Feb 21, 2023
@aarthificial aarthificial added b-enhancement New feature or request c-discussion The issue is being discussed a-2d Relates to the 2d package labels Feb 21, 2023
@aarthificial
Copy link
Contributor Author

After some more thinking, a better idea worth exploring could be dedicated methods on the Vector2 signals themselves:

// current API:
const absolutePosition = node().absolutePosition();

// new API:
const absolutePosition = node().position.abs();
const absoluteLeft = layout().left.abs();

// relative to another node:
const relativePosition = node().position.relativeTo(anotherNode());
const relativeLeft = layout().left.relativeTo(anotherNode());

This could open the door to other helpful transformations, like

// position in view space:
const position = node().position.view();
// left position in local space:
const left = layout().left.local();

SignalContext already has access to the owner node which should make this possible.
Supporting rotation would require a dedicated scalar signal but it should be worth it.

This solution would also make things like #881 less verbose.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a-2d Relates to the 2d package b-enhancement New feature or request c-discussion The issue is being discussed
Projects
None yet
Development

No branches or pull requests

1 participant