mouse position to isometric tile including height

前端 未结 7 926
太阳男子
太阳男子 2021-01-30 22:11

Struggeling translating the position of the mouse to the location of the tiles in my grid. When it\'s all flat, the math looks like this:

this.position.x = Math.         


        
7条回答
  •  隐瞒了意图╮
    2021-01-30 22:30

    Computer graphics is fun, right?

    This is a special case of the more standard computational geometry "point location problem". You could also express it as a nearest neighbour search.

    To make this look like a point location problem you just need to express your tiles as non-overlapping polygons in a 2D plane. If you want to keep your shapes in a 3D space (e.g. with a z buffer) this becomes the related "ray casting problem".

    One source of good geometry algorithms is W. Randolf Franklin's website and turf.js contains an implementation of his PNPOLY algorithm.

    For this special case we can be even faster than the general algorithms by treating our prior knowledge about the shape of the tiles as a coarse R-tree (a type of spatial index).

提交回复
热议问题