1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
pub trait Unit { fn name() -> &'static str; } #[derive(Copy, Clone, PartialEq, Debug)] pub struct Untyped; impl Unit for Untyped { fn name() -> &'static str { "Untyped" } } // In texture space (0 .. 1) origin: top-left pub struct Texels; impl Unit for Texels { fn name() -> &'static str { "Texels" } } // In screen pixels (0 .. X) origin: top-left pub struct Screen; impl Unit for Screen { fn name() -> &'static str { "Screen" } } // In world space (-X .. Y) pub struct World; impl Unit for World { fn name() -> &'static str { "World" } } // Local coordinates, for instance mesh vertices... pub struct Local; impl Unit for Local { fn name() -> &'static str { "Local" } } /* macro_rules! declare_unit ( ($module:ident) => ( pub mod $module { use vec2; use vec3; use vec4; use matrix; #[derive(Copy, Clone, Debug)] pub struct Unit; pub type Rectangle = vec2::Rectangle<Unit>; pub type Vec2 = vec2::Vector2D<Unit>; pub type Vec3 = vec3::Vector3D<Unit>; pub type Vec4 = vec4::Vector4D<Unit>; pub type Mat4 = matrix::Matrix4x4<Unit, Unit>; pub type Mat3 = matrix::Matrix3x3<Unit, Unit>; pub type Mat2 = matrix::Matrix2x2<Unit, Unit>; pub fn rect(x: f32, y: f32, w: f32, h: f32) -> Rectangle { vec2::Rectangle::new(x, y, w, h) } pub fn vec2(x: f32, y: f32) -> Vec2 { vec2::Vector2D::new(x, y) } pub fn vec3(x: f32, y: f32, z: f32) -> Vec3 { vec3::Vector3D::new(x, y, z) } pub fn vec4(x: f32, y: f32, z: f32, w: f32) -> Vec4 { vec4::Vector4D::new(x, y, z, w) } pub fn mat2(a11: f32, a21: f32, a12: f32, a22:f32) -> Mat2 { matrix::Matrix2x2::new( a11, a21, a12, a22 ) } pub fn mat3( a11: f32, a21: f32, a31: f32, a12: f32, a22: f32, a32: f32, a13: f32, a23: f32, a33: f32 ) -> Mat3 { matrix::Matrix3x3::new( a11, a21, a31, a12, a22, a32, a13, a23, a33 ) } pub fn mat4( a11: f32, a21: f32, a31: f32, a41: f32, a12: f32, a22: f32, a32: f32, a42: f32, a13: f32, a23: f32, a33: f32, a43: f32, a14: f32, a24: f32, a34: f32, a44: f32 ) -> Mat4 { matrix::Matrix4x4::new( a11, a21, a31, a41, a12, a22, a32, a42, a13, a23, a33, a43, a14, a24, a34, a44 ) } } ) ); // In texture space (0 .. 1) origin: top-left declare_unit!(texels); // In ui units (0 .. X) origin: top-left declare_unit!(pixels); // In world space (-X .. Y) declare_unit!(world); */