crow icon indicating copy to clipboard operation
crow copied to clipboard

matrix + vector types

Open lcnr opened this issue 4 years ago • 5 comments

This crate currently uses [[f32; 4]; 4] as a 4x4 Matrix and (f32, f32, f32, f32) as a 4 component vector. This is simple and should be usable with any algebra / mathematics crate.

It does however prevent matrix and vector multiplication and addition, which is kind of annoying.

I am currently considering the following posibilities:

  • keep using these simple types and add some helper methods like fn mat_mul.
  • add matrix and vector types and implement the basic operations.
  • use an existing algebra crate, while this seems like the best option, there are some disadvantages:
    • increases compilation time by ~25 % (nalgebra)
    • forces the user to use this crate, even if they want to use another one.
    • 2d pixel art games rarely need a lot of complex algebra so the additional complexity is not really worth it imo.

lcnr avatar Feb 04 '20 20:02 lcnr

Note: both [[f32; 4]; 4] and (f32, f32, f32, f32) is only used when dealing with colors, as all positions are based on integers.

lcnr avatar Feb 15 '20 10:02 lcnr

Vector types with methods, you mean like basic trigonometry?

Moar-Chan avatar Apr 16 '20 16:04 Moar-Chan

jup. To get a color_modulation matrix for a simple color one has to use something like this:

https://github.com/lcnr/crow/blob/4449983954f0c5af04b2e8e37161c7dbc3dcd905/examples/rectangles.rs#L122-L129

If we added a matrix + vector type this would just be identity_mat * color_vec which is a lot nicer. To get an image which is toned red, one can use RED multiplied with GREYSCALE As this is only relevant when depending on color_modulation I don't want to add too much complexity + compile time for this.

lcnr avatar Apr 16 '20 16:04 lcnr

Could we add nalgebra as a default, but have an opt out feature like: crow = { version = "x", features = ["no_nalgebra"]}

Moar-Chan avatar Apr 16 '20 16:04 Moar-Chan

you can enclose code segements with ``` to prevent the default text formatting.

crow = { version = "x", features = ["no_nalgebra"]}

which makes things a lot clearer.

Afaik this does not work well. features in rust should be additive and not break code. I would like to allow e.g. GRAYSCALE * a_very_nice_color to work without requring explicit conversions. This prob means changing the type of GRAYSCALE to nalgebras matrix type. This means that GRAYSCALE has a different type depending on the active feature. Thereby breaking any used library which also uses these consts but don't have the same active features.

I also kind of dislike nalgebra tbh :laughing: That's just personal preference though

lcnr avatar Apr 16 '20 17:04 lcnr