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

wrong multiplication operator for quat #68

Open
abisxir opened this issue Jul 11, 2023 · 0 comments
Open

wrong multiplication operator for quat #68

abisxir opened this issue Jul 11, 2023 · 0 comments

Comments

@abisxir
Copy link

abisxir commented Jul 11, 2023

Default implementation looks buggy in version 2.0.0:

import vmath

# Correct implementation
func mult(q, p: Quat): Quat =
    result.x =   p.x * q.w  + p.y * q.z - p.z * q.y + p.w * q.x
    result.y = -(p.x * q.z) + p.y * q.w + p.z * q.x + p.w * q.y
    result.z =   p.x * q.y  - p.y * q.x + p.z * q.w + p.w * q.z
    result.w = -(p.x * q.x) - p.y * q.y - p.z * q.z + p.w * q.w

let
  q1 = quat(1, 2, 3, 4) 
  q2 = quat(5, 6, 7, 8)

echo q1 * q2          # vec4(5.0, 12.0, 21.0, 32.0)
echo mult(q1, q2) # vec4(32.0, 32.0, 56.0, -6.0)

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

No branches or pull requests

1 participant