Skip to content

Ball-orientation-Nan-fix#393

Merged
freezy merged 5 commits into
freezy:masterfrom
Cupiii:BallOrientation-NaN-fix
Mar 22, 2022
Merged

Ball-orientation-Nan-fix#393
freezy merged 5 commits into
freezy:masterfrom
Cupiii:BallOrientation-NaN-fix

Conversation

@Cupiii
Copy link
Copy Markdown
Collaborator

@Cupiii Cupiii commented Mar 21, 2022

This fixes the ball orientation lock that occoured after a while playing.

The Skew Matrix produced more and more longer vectors in the orientation matrix.
Fix is to "kind of" normalize the single vectors inside the orientation matrix.
"Kind of": we don't need to normalize fully (dividing by sqrt(x^2+y^2+z^2)), since we don't use the vector lengthes anywhere (and also should not use them anywhere).
So we can divide by the sum of absolute values of x, y and z). Giving "somewhat" normalized vectors.

Also made the BallMovementsystem a little bit more clear, introducing some inbetween-vectors. I think the clearity is worth the small performance cost.

While analysing I added some comments about general ball-physics that may be useful in the future.

Copy link
Copy Markdown
Owner

@freezy freezy left a comment

Choose a reason for hiding this comment

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

Awesome. I'm wondering how you came across the orthonormalization thing. But it looks solid.

The only question I have is why is it that VP doesn't seem to have this NaN issue? Is there code fixing the symptom that I've missed when porting?

Comment thread VisualPinball.Unity/VisualPinball.Unity/VPT/Ball/BallData.cs Outdated
Comment thread VisualPinball.Unity/VisualPinball.Unity/VPT/Ball/BallDisplacementSystem.cs Outdated
Comment thread VisualPinball.Unity/VisualPinball.Unity/VPT/Ball/BallDisplacementSystem.cs Outdated
@Cupiii
Copy link
Copy Markdown
Collaborator Author

Cupiii commented Mar 22, 2022

Actually I debugged the vector and the values grew and grew until the two vectors used in the balltransform.localrotation were almost the same (maybe because of rounding errors with higher values) That gave assertion errors in the localrotation method. I just looked at the self-written VP-Orthonomalization code and it seems that VP does a Orthonomalization (including a normalization) there, but I'm actually not sure. Usually Orthonomalisation does not "normalize" the vectors length wise. So if VP does it within orthonormalize, it's at least unusual.

So I took a look:
VP's code is here: https://github.com/vpinball/vpinball/blob/be08b04d61096272df97bd45e6f0682043228a73/math/matrix.h#L208
VP actually does not do a true Orthonormalisation... and normalizes while orthonomalizing.

Maybe VP is faster - gave hint in the code for optimization.

@freezy freezy merged commit ae6ce5b into freezy:master Mar 22, 2022
@Cupiii Cupiii deleted the BallOrientation-NaN-fix branch March 23, 2022 17:46
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