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
Implement Godot methods for Quat #720
Conversation
#[inline]
fn from_quaternion(rotation: XYZW<T>) -> Self {
glam_assert!(rotation.is_normalized());
let x2 = rotation.x + rotation.x;
let y2 = rotation.y + rotation.y;
let z2 = rotation.z + rotation.z;
let xx = rotation.x * x2;
let xy = rotation.x * y2;
let xz = rotation.x * z2;
let yy = rotation.y * y2;
let yz = rotation.y * z2;
let zz = rotation.z * z2;
let wx = rotation.w * x2;
let wy = rotation.w * y2;
let wz = rotation.w * z2;
Self::from_cols(
V3::new(T::ONE - (yy + zz), xy + wz, xz - wy),
V3::new(xy - wz, T::ONE - (xx + zz), yz + wx),
V3::new(xz + wy, yz - wx, T::ONE - (xx + yy)),
)
} Godot's Basis constructor uses void Basis::set_quat(const Quat &p_quat) {
real_t d = p_quat.length_squared();
real_t s = 2.0 / d;
real_t xs = p_quat.x * s, ys = p_quat.y * s, zs = p_quat.z * s;
real_t wx = p_quat.w * xs, wy = p_quat.w * ys, wz = p_quat.w * zs;
real_t xx = p_quat.x * xs, xy = p_quat.x * ys, xz = p_quat.x * zs;
real_t yy = p_quat.y * ys, yz = p_quat.y * zs, zz = p_quat.z * zs;
set(1.0 - (yy + zz), xy - wz, xz + wy,
xy + wz, 1.0 - (xx + zz), yz - wx,
xz - wy, yz + wx, 1.0 - (xx + yy));
} The implementations are different, which could be the cause of the inaccuracy. Then again, the |
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 the contribution! 🙂
I left some comments.
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.
Looks mostly good, added a last few cosmetic remarks.
In my opinion this can be merged afterwards 🙂
aa9be58
to
1c0918e
Compare
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.
Missed your comments at first. Hope I got them all now 🙂
bors try |
tryMerge conflict. |
There are still some tests lacking & `get_euler` has a large error for some reason.
* s/core::/std:: * Add documentation to IDENTITY constant * s/get_euler/to_euler * Use Basis::to_euler for to_euler instead. Incidentally, this fixes the precision issue in to_the euler test. * Remove set_axis_angle and set_euler * Make Basis::to_quat private. The implementation could perhaps be moved to Quat::from_basis instead?
The slerp test fails because the result diverges a lot. Using `slerp` instead of `lerp` causes the result to be completely different.
Thanks for the quick adaptation! I'm waiting for @setzer22's feedback (who is a big user of quaternions), after that we can merge 🙂 bors try |
tryBuild failed: |
bors try |
tryBuild succeeded: |
bors r+ |
Build succeeded: |
Thanks a lot for the work @Demindiro and for the (off-site) feedback @setzer22! |
No description provided.