Skip to content

Cleanup and improvement for fromVectors()#491

Open
infusion wants to merge 1 commit intoschteppe:masterfrom
infusion:master
Open

Cleanup and improvement for fromVectors()#491
infusion wants to merge 1 commit intoschteppe:masterfrom
infusion:master

Conversation

@infusion
Copy link
Copy Markdown

Hi Stefan,

thanks for Cannon.js! As I am the author of Quaternion.js ( https://github.com/infusion/Quaternion.js ), I was interested in your implementation and figured, your fromVectors() method could be improved quite a bit. Besides this I added a note where the calculation for normalizeFast() comes from and removed the unused vectors used before for multiplication.

Hope this is helpful.
Robert

@infusion
Copy link
Copy Markdown
Author

infusion commented Oct 7, 2024

Is the project still alive?


// Close to PI - antiparallel check
if (dot < -0.999999) {
this.setFromAxisAngle(Math.abs(ux) > Math.abs(uz) ? new Vec3(-uy, ux, 0) : new Vec3(0, -uz, uy), Math.PI);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Why provoke GC? Previous solution is GC free.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I think the code is cleaner this way and it only handles the (hopefully) super rare edge case this way. But I mean, we could also have an initialized Vec3 somewhere floating around for such operations

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Yes, rare or not, I'm following 100% GC free principle. This allows me to set breakpoints in Vec/Quat constructors to see where allocations are happening under stress testing, so I can make sure everything is as optimized as it gets (memory-wise). But yea, everyone has different ideas (as usual).

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Yea good way of seeing it for sure. Should I change the commit to be GC free to be merged or don't you see the necessity?

@kungfooman
Copy link
Copy Markdown

Is the project still alive?

Not exactly this repo, but I'm still using and updating the code for myself. I was actually wondering just some days ago how Quat#normalizeFast works and now this appeared in my issue list again because of your question 🙈 Thank you!

@infusion
Copy link
Copy Markdown
Author

It should maybe not be called normalizeFast, but more like refineNormalization or something, since this also reflects the use case of having a normalized quat already that may need some adjustment

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.

2 participants