Efficiently getting isometric grid positions within a bounding box

前端 未结 6 1470
夕颜
夕颜 2021-02-05 10:57

\"Isometric

I have an isometric grid system who\'s coordinates start from [0,0] in the left hand corner of t

6条回答
  •  不知归路
    2021-02-05 11:21

    I assume you can get the coordinates of the selection box's corners mapped to the iso grid squares. This gives you a plotting problem with a simple algebraic test for solution. If we start with the corners in iso-squares (x1,y1) and (x2,y2), we know we need to test along the lines with slope 1 and -1 that go through these points,

    so the four lines are y-y1=x-x1, y-y1=x1-x,y-y2=x-x2,y-y2=x2-x. They meet at the iso-squares containing the corners of the selection box you began with.

    If we assume for convenience that x2 and y2 are larger than x1 and y1 respectively, we need only iterate over the iso-grid for values from x1 to x2, and y1 to y2, accepting only iso-squares whose y-coordinates are less than the both of the "larger" lines, and smaller than the two "smaller" lines.

提交回复
热议问题