summaryrefslogtreecommitdiffstats
path: root/wgpu/src/transformation.rs
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón <hector0193@gmail.com>2019-10-23 04:52:51 +0200
committerLibravatar GitHub <noreply@github.com>2019-10-23 04:52:51 +0200
commit4769272122e8cd0a4d666bb06c00cb27f8cad3c4 (patch)
tree68e513170347d804f55b3743f1fd960bbf700950 /wgpu/src/transformation.rs
parente95e656fcd780264f7a3c9a2ba3d0bd471d4894e (diff)
parent99e1a3780a1ea3ccb173d1fb4cbe889bb08b9643 (diff)
downloadiced-4769272122e8cd0a4d666bb06c00cb27f8cad3c4.tar.gz
iced-4769272122e8cd0a4d666bb06c00cb27f8cad3c4.tar.bz2
iced-4769272122e8cd0a4d666bb06c00cb27f8cad3c4.zip
Merge pull request #22 from hecrj/basic-renderer
Basic `wgpu` renderer
Diffstat (limited to '')
-rw-r--r--wgpu/src/transformation.rs30
1 files changed, 30 insertions, 0 deletions
diff --git a/wgpu/src/transformation.rs b/wgpu/src/transformation.rs
new file mode 100644
index 00000000..1101e135
--- /dev/null
+++ b/wgpu/src/transformation.rs
@@ -0,0 +1,30 @@
+#[derive(Debug, Clone, Copy)]
+pub struct Transformation([f32; 16]);
+
+impl Transformation {
+ #[rustfmt::skip]
+ pub fn identity() -> Self {
+ Transformation([
+ 1.0, 0.0, 0.0, 0.0,
+ 0.0, 1.0, 0.0, 0.0,
+ 0.0, 0.0, 1.0, 0.0,
+ 0.0, 0.0, 0.0, 1.0,
+ ])
+ }
+
+ #[rustfmt::skip]
+ pub fn orthographic(width: u16, height: u16) -> Self {
+ Transformation([
+ 2.0 / width as f32, 0.0, 0.0, 0.0,
+ 0.0, 2.0 / height as f32, 0.0, 0.0,
+ 0.0, 0.0, 1.0, 0.0,
+ -1.0, -1.0, 0.0, 1.0,
+ ])
+ }
+}
+
+impl From<Transformation> for [f32; 16] {
+ fn from(transformation: Transformation) -> [f32; 16] {
+ transformation.0
+ }
+}