I am writing an application that needs to map real-world coordinates to the screen space coordinate system of a canvas. I’ve been referencing the game of life example for how to scale and translate the canvas in response to user mouse events. That example uses members of the Grid struct to track the current scale multiplier and translation of the canvas, and reapplies these transformations every canvas::Program::draw call.
However, if I want my canvas to reflect a real-world coordinates region say starting at 0.0, 0.0 with a size of 2.0, 1.0, I’m not sure how to modify the scale and translation members to achieve this given the current shape of the canvas.
For reference, the relevant parts of the Grid struct look like:
pub struct Grid {
...
translation: Vector,
scale: f32,
...
}
and the place in canvas::Program::draw where these are applied looks like:
fn draw(&self, ...) -> Vec<Geometry> {
...
frame.with_save(|frame| {
frame.translate(center);
frame.scale(self.scaling);
frame.translate(self.translation);
...
}
...
}
Any help or ideas are welcome! Thanks.