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

mr::Quat implementation #19

Merged
merged 6 commits into from
Dec 16, 2024
Merged

mr::Quat implementation #19

merged 6 commits into from
Dec 16, 2024

Conversation

cone-forest
Copy link
Collaborator

Benchmarks to be added

@cone-forest cone-forest linked an issue Nov 23, 2024 that may be closed by this pull request
include/mr-math/quat.hpp Outdated Show resolved Hide resolved
include/mr-math/quat.hpp Outdated Show resolved Hide resolved
include/mr-math/quat.hpp Outdated Show resolved Hide resolved
}

friend constexpr Vec<T, 3> operator*(const Vec<T, 3> &lhs, const Quat &rhs) noexcept {
auto vq = rhs._vec * std::cos(rhs._angle._data / 2);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd use const VecT for clarity

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we introduce more and more metaprogramming magic, we might cause implicit casts from Proxy classes to Underlying types, which is costly. I'd use auto where possible.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fair enough

@dantibel
Copy link
Contributor

dantibel commented Nov 25, 2024

Consider adding mr::Quat<T> mr::rotate(const mr::Vec<T, N>& axis, mr::Radians<T> angle) to match other transform functions. That likely imply adding product for ScaleMatr and Quat

@@ -55,8 +73,8 @@ namespace mr {

friend constexpr Quat operator*(const Quat &lhs, const Quat &rhs) noexcept {
return {
lhs[0] * rhs[0] - lhs & rhs,
lhs._angle * rhs + rhs._angle * lhs + lhs % rhs
mr::Radiansf(lhs.w() * rhs.w() - lhs.vec().dot(rhs.vec())),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can return Radians from w() (and call it angle() then), so such casts won't be necessary. That is also better, since user will be sure they dealing with radians

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't you have to cast dot product to Radians or lhs.w() to T in this case?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, Radians would support arithmetic operations with primitive types. Since the conversion from Degrees is explicit (I hope) that wouldn't lead to an ambiguity

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, Radians support + or - with Radians and * or / with numbers (which makes sense). Then yep, we need to add the cast to the dot product

@cone-forest cone-forest changed the title mr::Quaternion implementation mr::Quat implementation Nov 25, 2024
@cone-forest cone-forest merged commit e0f1c2e into master Dec 16, 2024
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add mr::Quat
2 participants