rustgd / cgmath

A linear algebra and mathematics library for computer graphics.
https://docs.rs/cgmath
Apache License 2.0
1.13k stars 155 forks source link

Create rotation Matrix4 from Quaternion #441

Closed IsaacWoods closed 6 years ago

IsaacWoods commented 6 years ago

I'm probably just reading the docs wrong here (although I don't think I'm alone in thinking the API can be a tad confusing) but I can't seem to find a way to create a rotation matrix (specifically a Matrix4) from a Quaternion. This seems a pretty fundamental thing to want to do if the library is meant to be used for games, so I'm assuming I'm just missing something obvious?

vitvakatu commented 6 years ago

Matrix4 implements From<Quaternion, so basically you need just

let matrix: Matrix4<f32> = quaternion.into();
brendanzab commented 6 years ago

The other option, which I think reads better is:

let matrix = Matrix4::from(quaternion);
IsaacWoods commented 6 years ago

Ah, should've realised that! Thank you very much

brendanzab commented 6 years ago

No problem! I do think it is a bit of a usability problem on the Rustdoc end - it can be hard to miss trait implementations like that.