-void vg_update(void)
-{
- // Update camera
- float ratio = (float)vg_window_y / (float)vg_window_x;
- float const size = 7.5f;
- glm_ortho( -size, size, -size*ratio, size*ratio, 0.1f, 100.f, m_projection );
-
- glm_mat4_identity( m_view );
- glm_translate_z( m_view, -10.f );
- glm_rotate_x( m_view, 1.0f, m_view );
-
- glm_mat4_mul( m_projection, m_view, vg_pv );
-
- // Compute map update
- map.frame ^= 0x1;
- for( int y = 0; y < map.y; y ++ )
- {
- for( int x = 0; x < map.x; x ++ )
- {
- // Cell is a connector if it has at least 3 connections
- int output_dirs[][2] = { {0,-1}, {-1,0}, {1,0}, {0,1} };
- u32 output_count = 0;
- struct cell *tile, *thistile;
- thistile = map_tile_at( (int [2]){x,y} );
-
- if( thistile->flags & CELL_FLAG_CANAL )
- {
- for( int i = 0; i < vg_list_size( output_dirs ); i ++ )
- {
- tile = map_tile_at( (int [2]){ x+output_dirs[i][0], y+output_dirs[i][1] } );
-
- if( tile && tile->flags & CELL_FLAG_CANAL )
- output_count ++;
- }
-
- if( output_count >= 3 )
- thistile->flags |= CELL_FLAG_CONNECTOR;
- else
- thistile->flags &= ~CELL_FLAG_CONNECTOR;
- }
- }
- }
-
- // Get mouse ray
- vec3 ray_origin;
- vec3 ray_dir;
-
- mat4 pv_inverse;
- vec4 vp = { 0.f, 0.f, vg_window_x, vg_window_y };
- glm_mat4_inv( vg_pv, pv_inverse );
- glm_unprojecti( (vec3){ vg_mouse_x, vg_window_y-vg_mouse_y, -1.f }, pv_inverse, vp, ray_dir );
- glm_unprojecti( (vec3){ vg_mouse_x, vg_window_y-vg_mouse_y, 0.f }, pv_inverse, vp, ray_origin );
- glm_vec3_sub( ray_dir, ray_origin, ray_dir );