gl.enable(gl.SCISSOR_TEST);
}
- world_matrix := ir->get_transform()
- |> transform_to_matrix();
+ transform := ir->get_transform();
- new_x0 := world_matrix[0] * x + world_matrix[1] * y + world_matrix[12] * 1;
- new_y0 := world_matrix[4] * x + world_matrix[5] * y + world_matrix[13] * 1;
- new_x1 := world_matrix[0] * (x + w) + world_matrix[1] * (y + h) + world_matrix[12] * 1;
- new_y1 := world_matrix[4] * (x + w) + world_matrix[5] * (y + h) + world_matrix[13] * 1;
+ new_x0 := x * transform.scale.x + transform.translation.x;
+ new_y0 := y * transform.scale.y + transform.translation.y;
+ new_x1 := (x + w) * transform.scale.x + transform.translation.x;
+ new_y1 := (y + h) * transform.scale.y + transform.translation.y;
new_w := new_x1 - new_x0;
new_h := new_y1 - new_y0;
array.push(^scissor_stack, .{ new_x0, new_y0, new_w, new_h });
- gl.scissor(~~new_x0, ~~(-new_y0 + new_h * 2), ~~new_w, ~~new_h);
+ gl.scissor(~~new_x0, window_height - ~~new_y0 - ~~new_h, ~~new_w, ~~new_h);
}
pop_scissor :: (use ir: ^Immediate_Renderer) {
get_transform :: (use ir: ^Immediate_Renderer) -> ^Transform {
return array.get_ptr(^world_transform_stack, -1);
}
+
+ to_screen_coordinates :: (use ir: ^Immediate_Renderer, use v: Vector2) -> Vector2 {
+ transform := ir->get_transform();
+
+ return .{
+ x * transform.scale.x + transform.translation.x,
+ y * transform.scale.y + transform.translation.y,
+ };
+ }
+
+ to_world_coordinates :: (use ir: ^Immediate_Renderer, use v: Vector2) -> Vector2 {
+ transform := ir->get_transform();
+
+ return .{
+ (x - transform.translation.x) / transform.scale.x,
+ (y - transform.translation.y) / transform.scale.y,
+ };
+ }
}
Transform :: struct {
translation: Vector2;
scale: Vector2;
- rotation: f32; // In radians
+
+ // No rotation for right now. Not need for GUI stuff.
+ // rotation: f32; // In radians
}
transform_identity :: (use t: ^Transform) {
translation = .{ 0, 0 };
scale = .{ 1, 1 };
- rotation = 0;
+
+ // rotation = 0;
}
transform_to_matrix :: (use t: ^Transform) -> [16] f32 {
math :: package core.math
- st := math.sin(rotation);
- ct := math.cos(rotation);
+ // st := math.sin(rotation);
+ // ct := math.cos(rotation);
sx := scale.x;
sy := scale.y;
ty := translation.y;
return f32.[
- sx * ct, -sy * st, 0, 0,
- sx * st, sy * ct, 0, 0,
+ sx, 0, 0, 0,
+ 0, sy, 0, 0,
0, 0, 1, 0,
tx, ty, 0, 1
];