-
-
Notifications
You must be signed in to change notification settings - Fork 218
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
PR #3/5 Astolfo feature/builtin-vector #67
PR #3/5 Astolfo feature/builtin-vector #67
Conversation
Thanks a lot! As mentioned here:
|
Oh wow, I didn't realize how far you'd gotten with this. If #71 goes through instead of #66, you'll have some nice entry points for deduplication. All functions that work directly on
I hope you'll find that these macros actually reduce the cognitive burden, since they don't have a lot of parameters. |
Thanks a lot for this great collection of methods! To progress here, could you maybe:
|
dc81475
to
6560738
Compare
clippy complains about having too many parameters. i think this is a "too bad, so sad" situation. since all of these parameters are required to emulate the C++ godot equivelent |
@RealAstolfo yeah, later we can think about providing some parameters as ranges, e.g. For now, just add a |
didnt know about that. ill add the change then upload it |
Don't worry about Maybe you can squash all the commits to one? I think you can remove the co-author, as ttencate's additions have been merged in a separate PR in the meantime. |
bors try |
6560738
to
b98c870
Compare
added the clippy change. no idea why vector2 wanted to revert itself but i handled it |
tryBuild succeeded: |
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.
Thanks a lot for this huge list of vector functions!
Gave some first feedback 🙂
bors try
godot-core/src/builtin/vector2.rs
Outdated
pub fn sign(self) -> Self { | ||
-self | ||
} |
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.
This is not the sign...
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.
apologies i should have looked closer. was origonally under the guise that it was a sign flip, not extracting 1 or -1
godot-core/src/builtin/vector2.rs
Outdated
Self::from_glam(glam::Affine2::from_angle(angle).transform_vector2(self.to_glam())) | ||
} | ||
|
||
#[cfg(not(any(gdext_test, doctest)))] |
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.
The #[cfg(not(any(gdext_test, doctest)))]
is no longer necessary (as of today, if you rebase on master
) 🙂
godot-core/src/builtin/vector3.rs
Outdated
pub fn distance_squared_to(self, to: Self) -> f32 { | ||
self.to_glam().distance_squared(to.to_glam()) | ||
} | ||
|
||
pub fn distance_to(self, to: Self) -> f32 { | ||
self.to_glam().distance(to.to_glam()) | ||
} |
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.
Would be easier to just use (to - self).length_squared()
and (to - self).length()
.
godot-core/src/builtin/vector3.rs
Outdated
pub fn max_axis_index(self) -> i32 { | ||
let me = self.to_glam().max_element(); | ||
if me == self.x { | ||
0 | ||
} else if me == self.y { | ||
1 | ||
} else { | ||
2 | ||
} | ||
} | ||
|
||
pub fn min_axis_index(self) -> i32 { | ||
let me = self.to_glam().min_element(); | ||
if me == self.x { | ||
0 | ||
} else if me == self.y { | ||
1 | ||
} else { | ||
2 | ||
} | ||
} |
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'm not sure we should implement it like that (first computing the maximum, then comparing it to each axis).
Maybe check the gdnative
implementation.
We should also make use of the Vector3Axis
type, defined further below in this file.
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.
copy, fixing to use the given type
pub fn slerp(self, to: Self, weight: f32) -> Self { | ||
let start_length_sq = self.length_squared(); | ||
let end_length_sq = to.length_squared(); | ||
if start_length_sq == 0.0 || end_length_sq == 0.0 { | ||
return self.lerp(to, weight); | ||
} | ||
let start_length = start_length_sq.sqrt(); | ||
let result_length = lerp(start_length, end_length_sq.sqrt(), weight); | ||
let angle = self.angle_to(to); | ||
self.rotated(angle * weight) * (result_length / start_length) | ||
} |
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.
The gdnative
implementation is significantly easier; I wonder if it's correct, too?
/// Returns the result of spherical linear interpolation between this vector and b, by amount t.
/// t is on the range of 0.0 to 1.0, representing the amount of interpolation.
///
/// **Note**: Both vectors must be normalized.
#[inline]
pub fn slerp(self, b: Self, t: f32) -> Self {
let theta = self.angle_to(b);
self.rotated(self.cross(b).normalized(), theta * t)
}
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.
perhaps the gdnative implementation is valid as well, i simply looked at upstream godot and converted the language. up to you if you prefer the gdnative version as opposed to upstream.
Vector2 Vector2::slerp(const Vector2 &p_to, const real_t p_weight) const {
real_t start_length_sq = length_squared();
real_t end_length_sq = p_to.length_squared();
if (unlikely(start_length_sq == 0.0f || end_length_sq == 0.0f)) {
// Zero length vectors have no angle, so the best we can do is either lerp or throw an error.
return lerp(p_to, p_weight);
}
real_t start_length = Math::sqrt(start_length_sq);
real_t result_length = Math::lerp(start_length, Math::sqrt(end_length_sq), p_weight);
real_t angle = angle_to(p_to);
return rotated(angle * p_weight) * (result_length / start_length);
}
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.
Maybe keep your implementation for now. In the first line, can you add this comment?
// TODO compare with gdnative implementation:
// https://github.com/godot-rust/gdnative/blob/master/gdnative-core/src/core_types/vector3.rs#L335-L343
Then we can check it later. We anyway need to work out a testing strategy at some point 🙂
tryBuild succeeded: |
861506c
to
39d8022
Compare
btw i tried squashing any two commits but the github client refuses too for everything i try. so unless you have a good workaround we might have to just live with it |
39d8022
to
542805c
Compare
You should be able to combine commits with If you can't get it to work, I can also do it before the merge. bors try |
i might just need you to tell me how you did it later, because all i get is |
542805c
to
292cada
Compare
tryBuild succeeded: |
292cada
to
c9996c3
Compare
Thanks for the contribution! 👍 Squashed and rebased onto bors r+ |
Build succeeded:
|
68: PR #4/5 Astolfo feature/builtin-quaternion r=Bromeon a=RealAstolfo Co-Authored-By: Thomas ten Cate <ttencate@gmail.com> Implemented Quaternion to the best of my current ability to resemble godot's, meant to be merged after #67 Co-authored-by: RealAstolfo <astolfo.gman@gmail.com> Co-authored-by: Jan Haller <bromeon@gmail.com>
This PR builds upon ttencates macro and my math functions to create a rust implementation of what godot has in its C++ as close as i think, meant to be merged after #66