bevy
bevy copied to clipboard
Global to Local methods for transforms
What problem does this solve or what need does it fill?
I want to take a global position, and convert it to a position local to my input Transform.
What solution would you like?
Each Transform keeps track of the total transformation of all its parent transforms. Alternatively, GlobalTransform keeps track of this.
What alternative(s) have you considered?
Kerbiter on Discord:
if you only need to change the position, then you basically just do vector algebra and add all the local transforms for every entity in the hierarchy to get a global transform, so just subtract all local transforms except one you need from the global one
This seems like it could end up being a lot of operations for something that could be cached.
I'm not sure I understand the issue, it seems it's already what GlobalTransform
is doing.
For each element, its GlobalTransform
is its parent GlobalTransform
multiplied by its own local Transform
(through mul_transform
).
You don't need to traverse hierarchy at all.