+void cell_to_pos(struct level *lvl, int cx, int cy, float *px, float *py)
+{
+ if(px) *px = (cx - lvl->width / 2.0f) * cellsz - view_panx + view_width / 2.0f;
+ if(py) *py = (cy - lvl->height / 2.0f) * cellsz - view_pany + view_height / 2.0f;
+}
+
+struct cell *pos_to_cell(struct level *lvl, float px, float py, int *cx, int *cy)
+{
+ int col, row;
+
+ col = (px + view_panx - view_width / 2.0f) / cellsz + lvl->width / 2.0f;
+ row = (py + view_pany - view_height / 2.0f) / cellsz + lvl->height / 2.0f;
+
+ if(cx) *cx = col;
+ if(cy) *cy = row;
+
+ if(col >= 0 && col < lvl->width && row >= 0 && row < lvl->height) {
+ return lvl->cells + row * lvl->width + col;
+ }
+ return 0;
+}
+