use notan::draw::*;
use notan::math::{vec2, vec3, Mat4, Vec2};
use notan::prelude::*;
const WORK_SIZE: Vec2 = vec2(800.0, 600.0);
#[notan_main]
fn main() -> Result<(), String> {
let win_config = WindowConfig::default().set_resizable(true);
notan::init()
.add_config(win_config)
.add_config(DrawConfig) .draw(draw)
.build()
}
fn draw(gfx: &mut Graphics) {
let (width, height) = gfx.size();
let win_size = vec2(width as f32, height as f32);
let (projection, _) = calc_projection(win_size, WORK_SIZE);
let mut draw = gfx.create_draw();
draw.clear(Color::BLACK);
draw.set_projection(Some(projection));
draw.rect((0.0, 0.0), WORK_SIZE.into())
.color(Color::ORANGE)
.stroke(10.0);
draw.triangle((400.0, 100.0), (100.0, 500.0), (700.0, 500.0));
gfx.render(&draw);
}
fn calc_projection(win_size: Vec2, work_size: Vec2) -> (Mat4, f32) {
let ratio = (win_size.x / work_size.x).min(win_size.y / work_size.y);
let projection = Mat4::orthographic_rh_gl(0.0, win_size.x, win_size.y, 0.0, -1.0, 1.0);
let scale = Mat4::from_scale(vec3(ratio, ratio, 1.0));
let position = vec3(
(win_size.x - work_size.x * ratio) * 0.5,
(win_size.y - work_size.y * ratio) * 0.5,
1.0,
);
let translation = Mat4::from_translation(position);
(projection * translation * scale, ratio)
}