cgmath
cgmath copied to clipboard
Add type defs for common types
It's quite verbose having to type the full type signature for common vector and matrix types when type inference cannot be used, e.g. writing structs or non generic functions. For this reason it would be good to have aliases for commonly used types (like VectorN
For example, I have the following struct and function:
pub struct ParticleData {
position: Vec<cgmath::Vector3<f32>>,
velocity: Vec<cgmath::Vector3<f32>>,
}
It would be a lot less verbose as (to use GLM format):
pub struct ParticleData {
position: Vec<cgmath::Vec3>,
velocity: Vec<cgmath::Vec3>,
}
The GLM typedefs for vec are listed here http://glm.g-truc.net/0.9.7/api/a00132.html and for matrices are here http://glm.g-truc.net/0.9.7/api/a00120_source.html#l00344. I'm not necessarily recommending adding all of those, GLM is mimicking all the types available in GLSL.
In my experience, game math uses float 99% of the time, so it would be good to provide type defs for the f32 types at least, VecN and MatN (for square matrices) seem like common choices.
Hmm, yeah. Might be useful. Also, nice article!
Yeah, that article was a good find, glad you liked it.
Perhaps the scalar type parameters could also default to f32
. That is,
struct Vector3<S = f32> { ... }
let foo: Vec<Vector3> = vec![];
Yeah, that could work.