From ef403a5baa0c5a5d850c19f14e67f1b9f1186705 Mon Sep 17 00:00:00 2001 From: Justin Worthe Date: Thu, 9 Aug 2018 18:07:24 +0200 Subject: Added functions required for working with a camera and a cursor --- gate/src/renderer/geom.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/gate/src/renderer/geom.rs b/gate/src/renderer/geom.rs index 0f0e478..619555f 100644 --- a/gate/src/renderer/geom.rs +++ b/gate/src/renderer/geom.rs @@ -215,13 +215,26 @@ impl Affine { } } - pub(crate) fn apply(&self, input: Vec2) -> Vec2 { self.mat * input + self.offset } + pub fn invert_translate(&self) -> Affine { + Affine { + mat: self.mat, + offset: -1. * self.offset + } + } + + pub fn apply(&self, input: Vec2) -> Vec2 { self.mat * input + self.offset } - pub(crate) fn apply_f32(&self, input: (f32, f32)) -> (f32, f32) { + pub fn apply_f32(&self, input: (f32, f32)) -> (f32, f32) { let input = Vec2::new(input.0 as f64, input.1 as f64); let result = self.apply(input); (result.x as f32, result.y as f32) } + pub fn apply_f64(&self, input: (f64, f64)) -> (f64, f64) { + let input = Vec2::new(input.0 as f64, input.1 as f64); + let result = self.apply(input); + (result.x, result.y) + } + pub(crate) fn mat(&self) -> &Mat2 { &self.mat } } -- cgit v1.2.3