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

Update Tangent W calculation #938

Merged
merged 4 commits into from
Mar 8, 2021
Merged

Conversation

pandaGaume
Copy link
Contributor

W Tangent calculation was impacted by floating point rounding error and generate inverted vector randomly. Fix #936

W Tangent calculation was impacted by floating point rounding error and generate inverted vector randomly
}

return w;
float nx = Math.Abs(normal.X) <= Tools.Epsilon ? 0 : normal.X;
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe add an override for Tools.IsAlmostEqualTo?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well technically this is
float nx = Tools.IsAlmostEqualTo(normal.X,Tools.Epsilon)? 0 : normal.X;
so i do not know how to name this function :-)

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, no worries. I just like using helper functions for math, so they're reusable and documented via code.

A header like:

public static bool IsAlmostEqualTo(this float current, float other, float epsilon)
{
    return Math.Abs(current - other) < epsilon
}

Should let us use it like

float nx = current.isAlmostEqualTo(0, Tools.Epsilon);

Just to minimize the amount of wild math we're using

@Drigax Drigax merged commit ec0176a into BabylonJS:master Mar 8, 2021
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.

Incorrect Tangent/Bitangent export
2 participants