Grid values
This commit is contained in:
parent
bd47c52111
commit
1c2a324f55
3 changed files with 66 additions and 44 deletions
48
grid.odin
Normal file
48
grid.odin
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
package main
|
||||
|
||||
import "core:math/linalg"
|
||||
import rl "libraries/raylib"
|
||||
|
||||
Grid :: struct {
|
||||
cell_size: v2,
|
||||
zoom_previous, zoom: v2,
|
||||
world_position, world_size, offset: v2,
|
||||
}
|
||||
|
||||
draw_grid :: proc(grid: Grid, text_draw, text_clip: rect2) {
|
||||
zoom_amount := grid_get_zoom_amount(grid.zoom)
|
||||
world_to_grid_matrix := (
|
||||
mat3 {
|
||||
1, 0, 0,
|
||||
0, 1, 0,
|
||||
grid.offset.x, grid.offset.y, 1,
|
||||
} *
|
||||
linalg.matrix3_scale(v3{**zoom_amount, 1.0}))
|
||||
grid_to_world_matrix := linalg.inverse(world_to_grid_matrix)
|
||||
grid_world_br := grid.world_position + grid.world_size
|
||||
grid_color := rl.Color{64, 64, 64, 255}
|
||||
|
||||
grid_tl := (v3{**grid.world_position, 1.0} * world_to_grid_matrix).xy
|
||||
grid_tl = linalg.floor(grid_tl / grid.cell_size) * grid.cell_size
|
||||
grid_br := (v3{**grid_world_br, 1.0} * world_to_grid_matrix).xy
|
||||
|
||||
for x: f32 = grid_tl.x; x < grid_br.x; x += grid.cell_size.x {
|
||||
world_position_x := (v3{x, 0.0, 1.0} * grid_to_world_matrix).x
|
||||
p1 := v2{world_position_x, grid.world_position.y}
|
||||
p2 := v2{world_position_x, grid_world_br.y}
|
||||
rl.DrawLineV(p1, p2, grid_color)
|
||||
if p1.x >= text_clip.x && p1.x < text_clip.x + text_clip.width {
|
||||
draw_float_aligned(x, {world_position_x, text_draw.y}, program.font_style, .Middle, .Top, rl.GRAY)
|
||||
}
|
||||
}
|
||||
|
||||
for y: f32 = grid_tl.y; y < grid_br.y; y += grid.cell_size.y {
|
||||
world_position_y := (v3{0.0, y, 1.0} * grid_to_world_matrix).y
|
||||
p1 := v2{grid.world_position.x, world_position_y}
|
||||
p2 := v2{grid_world_br.x, world_position_y}
|
||||
rl.DrawLineV(p1, p2, grid_color)
|
||||
if p1.y >= text_clip.y && p1.y < text_clip.y + text_clip.height {
|
||||
draw_float_aligned(y, {text_draw.x, world_position_y}, program.font_style, .Left, .Center, rl.GRAY)
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue