sebcrozet/kiss3d

Red Rotating Cube example nalgebra confusion

Closed this issue · 3 comments

Hi.

I was not able to run README.md's red rotating cube example code :

  --> src/main.rs:19:37
   |
19 |         c.prepend_to_local_rotation(&rot);
   |                                     ^^^^ expected struct `kiss3d::nalgebra::Unit`, found struct `na::Unit`
   |
   = note: expected reference `&kiss3d::nalgebra::Unit<kiss3d::nalgebra::Quaternion<f32>>`
              found reference `&na::Unit<na::Quaternion<{float}>>`
   = note: perhaps two different versions of crate `nalgebra` are being used?

To fix, I replaced this:

extern crate nalgebra as na;

use na::{Vector3, UnitQuaternion};

with that:

//extern crate nalgebra as na;

use kiss3d::nalgebra::{Vector3, UnitQuaternion};

I will submit a PR later today unless you think my solution is incorrect.

Hi, this happens when you specify a different version of nalgebra in Cargo.toml than what kiss3d is using. In this sense, the example code is not inherently wrong, since it is the same code as in examples/cube.rs and you should be able to run cargo run --example cube without issues.

That said, kiss3d does re-export the nalgebra crate so using it is also not incorrect. I have a feeling that @sebcrozet might prefer the following, but it's mostly a matter of personal preference:

use kiss3d::nalgebra as na;

use na::{Vector3, UnitQuaternion};

As for me, I tend to just match the Cargo.toml dependency versions whenever possible.

@alvinhochun This makes sense. Also, I was having second thoughts as to my "solution" as one may very well want to use nalgebra outside of the kiss3d context, hence having to add it as a dependency in Cargo.toml. Will see if @sebcrozet will suggest your amendment idea (which I like), in which case I will be glad to submit a PR.

Stumbled upon the same issue while playing around with kiss3d release v0.30. Fixed by using the following version in Cargo.toml. seems like kiss3d v0.30 was utilizing algebra v0.25

[dependencies]
kiss3d = "0.30"
nalgebra = "0.25"