-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Add Transform Helper methods #15200
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
base: main
Are you sure you want to change the base?
Add Transform Helper methods #15200
Conversation
Welcome, new contributor! Please make sure you've read our contributing guide and we look forward to reviewing your pull request shortly ✨ |
Refactored the two methods to accept a single Vec3 as the result of the direction Vec3 multiplied by the speed of the entity we are trying to move. This should remove the redundant assegnation of the speed.
Overall I think the code is good, I'm not sure on the naming though. Not sure what would be a better name. |
I see what you mean. Maybe to make it more coherent might be better to only have a Vec3 as the signature of the method, calling it translation and let the user create the translation vector by multiplying it by the speed AND the delta time? |
Going to change it later to only receive a Vec3 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think translate_to
for a new absolute position and translate_by
for an offset would be a good naming convention. It might also be worth wrapping the Vec3 in a newtype Offset
and Position
to prevent accidentally providing the wrong kind of value. Mojang actually just had this exact mixup earlier this month when reimplementing ender pearl teleportation!
I see your points, but isn't just easier to read and understand a single Vec3 as a parameter? Then it's the user's job to provide the correct calculation over that Vec3 I feel 🤔 |
It's not wrong either way. I feel like it's the same difference between having a raw boolean parameter vs an enum with 2 values. There is a clippy lint against boolean parameters because it's easy to accidentally mix up which parameter or which value you meant to use. Also, a raw |
RE: Point & Offset newtype. While mathematically I 100% agree that the semantics of vectors (as offsets) vs points are very different (and the reason we use Vec3 for both could be regarded as a "hack" based on arbitrarily fixing the origin) the codebase is generally not made for this and it would be a very controversial change. Relevant discussion @ glam: bitshifter/glam-rs#133 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doc suggestions :)
Objective
Solution
translate(&mut self, direction: Vec3, speed: f32, delta_time_seconds: f32)
. This function simply provides a faster way of adding a translation to the Transform by providing a direction, a speed and a delta_seconds (or delta in general referring to time). This doesn't take in account the rotation of the Transform.translate_with_local_rotation(&mut self, direction: Vec3, speed: f32, delta_time_seconds: f32)
. This function differs from the one above because it also utilizes the rotation of the Transform to provide a way of moving the object following a specific direction and taking in account also it's rotation.Testing
translation.rs
using the newly implemented functiontranslate
to see if the result was the same.translate_with_local_rotation
by modifing the example3d_rotation
and adding a new line just after the rotation. It moved as expected, but the addition of the line felt like out of scope of the example, so I removed it.