Advertisement

position on grid

Started by February 24, 2016 07:11 PM
1 comment, last by _WeirdCat_ 8 years, 6 months ago

the image shows everything i have black square which is a section, and i have a red square which is a cell now if i have a cell in x,y how do i find in which section it is?

square.png

as you can see each section has 4 cells (2 in x direction 2 in y direction) also sections have the same coordinate system which is x,y (so section where blue cell is is 1,1)

ther eare 8 cells in one direction like 4 sections in the same direction, they are always the same (for x and y directions) additionally they are always power of 2 that means ther ecan be lets say 64 cells but only 2 section or 128 cells and 64 sections etc.

section_x = cell_x / cells_per_section_x;

section_y = cell_y / cells_per_section_y;

Advertisement

i made exactly the same equations before i posted here, then i saw that when casting cell_x and cels_per_section_x i will end up with 2.0 / 2.0 which can be not 1 due to floatpoint inaccuracy, but after i saw your code (and checked that int(7) / int(8) = 0 in http://www.gamedev.net/topic/676402-how-do-i-use-printf-to-display-an-int/ ) then your code makes perfect sense, thanks

This topic is closed to new replies.

Advertisement