You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As a newcomer, the use of mint is slightly confusing. If I understand correctly, mint is a maths interoperability library so you can convert, say, nalgebra's Point2 to mint's, and maybe from mint's to cgmath's. But only as data, so you can't add two mintVector2s together, let alone add a mintVector2 to a nalgebraVector2.
The solution seems to be for the library user to pick a mint-compatible library, use those types and operations they want in their code. Whenever you need to pass something to or from ggez, you use explicit .into()/.from conversions.
For example, if I wanted to grab the dest field from a DrawParam and create a new DrawParam with the dest offset by (4,4) pixels:
// dest is a mint::Point2 but I need it to be nalgebra::Point2let d: nalgebra::Point2<f32> = drawparam.dest.into();let delta: nalgebra::Vector2<f32> = nalgebra::Vector2<f32>::new(4.0,4.0);// Do nalgebra's vector+point addition, but convert to mint::Point2let new_dest: mint::Point2<f32> = (d + delta).into();// Now DrawParam is happy.let new_dp = DrawParam::default().dest(new_dest);
Is this correct? I feel this is what I should get out of the discussion in #344. Is it worthwhile adding a paragraph of explanation to the FAQ?
The text was updated successfully, but these errors were encountered:
Lots of functions, including all the setters in DrawParam, take Into<Whatever> where Whatever is the appropriate Mint type. So, you can pass them any type that implements From or Into that type, without needing to do the conversion explicitly.
Under Libraries (or Graphics and GUIs?)
Maybe like this? I am quite bad at explaining stuff
How do I use Into<mint::Point2<f32>> and other Into<mint::T> types?
mint stands for "Math INteroperability Types" which means that it provides types for other math libraries to convert to and from with. What you are supposed to do is to add a math library of your choice to your game such as glam or nalgebra, usually with a "mint" feature.
For example. You can add glam = { version = "0.15.2", features = ["mint"] } in your Cargo.toml, then when you try to pass something to say DrawParam::new().dest(my_point) you will be able to pass a glam type like DrawParam::new().dest(glam::vec2(10.0, 15.0)) to set the destination to x=10 and y=15.
Going the other way around is a bit more verbose, you need to do glam::Vec2::from(my_draw_param.dest)
Another example of moving a draw param's destination diagonally by 1 down and right.
let dest = glam::Vec2::from(my_draw_param.dest);let new_dest = dest + glam::vec2(1.0,1.0);DrawParam::new().dest(new_dest)
As a newcomer, the use of
mint
is slightly confusing. If I understand correctly,mint
is a maths interoperability library so you can convert, say,nalgebra
'sPoint2
tomint
's, and maybe frommint
's tocgmath
's. But only as data, so you can't add twomint
Vector2
s together, let alone add amint
Vector2
to analgebra
Vector2
.The solution seems to be for the library user to pick a
mint
-compatible library, use those types and operations they want in their code. Whenever you need to pass something to or fromggez
, you use explicit.into()
/.from
conversions.For example, if I wanted to grab the
dest
field from aDrawParam
and create a newDrawParam
with thedest
offset by (4,4) pixels:Is this correct? I feel this is what I should get out of the discussion in #344. Is it worthwhile adding a paragraph of explanation to the FAQ?
The text was updated successfully, but these errors were encountered: