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

Augment raymath.h with useful functions #2428

Merged
merged 3 commits into from
Apr 23, 2022
Merged

Augment raymath.h with useful functions #2428

merged 3 commits into from
Apr 23, 2022

Conversation

saccharineboi
Copy link
Contributor

I use these functions heavily during gamedev so I thought they could be useful for others too:

  • FloatEquals: Check whether two given floats are almost equal
  • Vector{n}Invert: Invert the given vector
  • Vector{n}Clamp: Clamp the components of the vector between min and max values specified by the given vectors
  • Vector{n}ClampMagnitude: Clamp the magnitude of the vector between two given min and max values
  • Vector{n}Equals: Check whether two given vectors are almost equal

Additionally Vector3{Up,Down,Left,Right,Forward,Backward} are added for convenience.

Vector3Refract refracts a vector given a normal and a refractive index.

QuaternionEquals checks whether two given quaternions are almost equal.

Furthermore, a macro named "EPSILON" with a value 1e-6 is added (used in floating-point comparison functions), and stdbool.h is included for functions that return boolean values.

@CrezyDud
Copy link
Contributor

rename Vector2ClampMagnitude and Vector3ClampMagnitude to Vector2ClampValue and Vector3ClampValue
for consistency

@raysan5
Copy link
Owner

raysan5 commented Apr 23, 2022

@saccharineboi I think some of those functions are unneded and just add a level of undirection not required. i.e users cand define required Vector3 up/down/back... directly, no need to provide functions for everything.

@raysan5 raysan5 merged commit 52befa0 into raysan5:master Apr 23, 2022
@raysan5
Copy link
Owner

raysan5 commented Apr 23, 2022

@saccharineboi thanks for the review.

@planetis-m
Copy link
Contributor

I don't know if it's intentional or an oversight but missing from this PR is MatrixEquals.

@raysan5
Copy link
Owner

raysan5 commented Apr 24, 2022

@planetis-m Could you list a use case for that function?

Actually, I'm already considering removing all the *Equals() functions, the bool include broke raylib.

@saccharineboi
Copy link
Contributor Author

I don't know if it's intentional or an oversight but missing from this PR is MatrixEquals.

Intentional. In contrast to Vector{n}Equals which is useful for checking degenerate vectors, MatrixEquals is almost never used. Though it could be added for completeness' sake.

@raysan5 what do you mean it broke raylib? Was it because of stdbool.h? Instead of removing those functions, you could change return types to int

@raysan5
Copy link
Owner

raysan5 commented Apr 24, 2022

@saccharineboi I already changed return types to int, I'm considering the real use case for those functions. As it happens with many raylib functions, they looks like a good idea to have but nobody is actually using them ever.

For that reason I try to be very careful with raylib additions. Let's see if anybody will ever use those functions...

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.

None yet

4 participants