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

Use System.Numerics instead of custom vector types #31

Closed
sbarisic opened this issue Aug 8, 2019 · 8 comments · Fixed by #50
Closed

Use System.Numerics instead of custom vector types #31

sbarisic opened this issue Aug 8, 2019 · 8 comments · Fixed by #50
Labels
enhancement New feature or request

Comments

@sbarisic
Copy link

sbarisic commented Aug 8, 2019

It would be a wise idea to use System.Numerics for vector and matrix types, as it would be more compatible with other libraries. They're also SIMD accelerated, and marshalling them works fine.

@ChrisDill
Copy link
Owner

@sbarisic That sounds interesting though I don't plan to change the vector and matrix types at the moment. Ideally a feature like this would be optional for those who want it.

@ChrisDill ChrisDill reopened this Apr 8, 2020
@ChrisDill ChrisDill added the enhancement New feature or request label Apr 21, 2020
@ChrisDill
Copy link
Owner

I have looked into this feature but I am currently unsure on the best way to proceed.
I tried to use System.Numerics in a test project to see how what users need to do to switch to it.

  1. Add using System.Numerics in every file that uses these types.

  2. Change fields like .x, .y, .z etc to .X, .Y, .Z etc.

This is a pain to do especially in a larger project so I looked to see if there was a easier way to make this a optional/non breaking change.

The only possible solution I found is to wrap the System.Numerics types in my own types and provide properties for access. This "might" work but I feel that defeats the idea of it as you need to convert/access the type manually when using external code that uses System.Numerics.

Another possible concern is with the Matrix. I need to look into the ordering of the fields to see if conflicts with how the raylib Matrix works. I do not think it makes sense to add System.Numerics only for Vector types but not Matrices as that will just make things more confusing for new users.

@sbarisic
Copy link
Author

sbarisic commented May 1, 2020

The order of the matrix elements should match OpenGL as far as i know, for anything else it would be enough to just transpose them before doing calculations.

Another way to make this less painful is to add an implicit cast to/from System.Numerics vectors.

@sbarisic
Copy link
Author

sbarisic commented May 1, 2020

It would be possible to create a wrapper over System.Numerics types and use implicit casts to automatically return internal type, but that pretty much defeats the purpose and makes it slower.

@9ParsonsB
Copy link
Collaborator

@ChrisDill I Wouldn't too much about adding/chaning usings in every file - I believe VS can do it now for you anyway.

@ChrisDill
Copy link
Owner

ChrisDill commented May 2, 2020

@sbarisic There is now a numerics branch for this feature. I discussed it with @9ParsonsB and we decided that keeping this feature compatible is not possible so it is being tested as a breaking change. So far Vector2, Vector3 and Vector4 have been replaced.

Matrix4x4 has a different layout but transposing the matrix works for going from the numerics layout to the raymath and vice versa.

@matej-zajacik
Copy link

I'm undecided on the switch to the standard System.Numerics types (not sure of the benefits), but as far as breaking changes go, that shouldn't be a problem, should you decide to make the switch. It takes just minutes, maybe tens of minutes to adjust a project.

@i3elj
Copy link

i3elj commented May 18, 2024

What should I do when using DrawTextureRec? it takes a int based Vector2 and there's no alternative that uses the x and y components separately like DrawTexture . Is there a way to cast the entire System.Numerics.Vector2 to int? Would be easy if it accepted generic types (e.g. Vector2<int>)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants