summaryrefslogtreecommitdiffstats
path: root/wgpu/src/transformation.rs
diff options
context:
space:
mode:
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
+ }
+}