Grid values
This commit is contained in:
parent
bd47c52111
commit
1c2a324f55
3 changed files with 66 additions and 44 deletions
39
program.odin
39
program.odin
|
|
@ -218,12 +218,6 @@ AnimationState :: enum {
|
|||
Finished,
|
||||
}
|
||||
|
||||
Grid :: struct {
|
||||
cell_size: v2,
|
||||
zoom_previous, zoom: v2,
|
||||
world_position, world_size, offset: v2,
|
||||
}
|
||||
|
||||
float_slice_get_mat3 :: proc(floats: []f32, index: int) -> ^mat3 {
|
||||
return cast(^mat3)(&floats[index * 9])
|
||||
}
|
||||
|
|
@ -278,7 +272,7 @@ program_init :: proc(allocator := context.allocator) {
|
|||
program.font_style = {
|
||||
font = rl.GetFontDefault(),
|
||||
size = 16.0,
|
||||
spacing = 1.0
|
||||
spacing = 2.0
|
||||
}
|
||||
program.grid = {
|
||||
cell_size = 32.0,
|
||||
|
|
@ -415,33 +409,10 @@ program_update :: proc() {
|
|||
}
|
||||
}
|
||||
|
||||
grid := program.grid
|
||||
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_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 := (v3{x, 0.0, 1.0} * grid_to_world_matrix).x
|
||||
p1 := v2{world_position, grid.world_position.y}
|
||||
p2 := v2{world_position, grid_world_br.y}
|
||||
rl.DrawLineV(p1, p2, {255, 255, 255, 128})
|
||||
}
|
||||
for y: f32 = grid_tl.y; y < grid_br.y; y += grid.cell_size.y {
|
||||
world_position := (v3{0.0, y, 1.0} * grid_to_world_matrix).y
|
||||
p1 := v2{grid.world_position.x, world_position}
|
||||
p2 := v2{grid_world_br.x, world_position}
|
||||
rl.DrawLineV(p1, p2, {255, 255, 255, 128})
|
||||
}
|
||||
top_bar_container_br := rect_get_br(rect2(top_bar_container.area))
|
||||
matrix_container_br := rect_get_br(rect2(matrix_container.area))
|
||||
grid_text_clip := rect_from_area(v2{matrix_container_br.x, top_bar_container_br.y}, v2{WINDOW_WIDTH, WINDOW_HEIGHT})
|
||||
draw_grid(program.grid, rect_grow(grid_text_clip, -4.0), rect_grow(grid_text_clip, -32.0))
|
||||
|
||||
if program.animation_state == .Playing {
|
||||
program.animation_matrix_progress += program.animation_speed * delta_time_fraction()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue