#Calculating 'complex' mouse_pos_to_tile.
33 messages · Page 1 of 1 (latest)
If I were to solve this, I would first of all ask myself why I'm using such a weird grid to begin with. Do these four grids extend indefinitely, or do you only have these four boxes?
(If the grid is larger than this, then it's not clear to me how it tiles)
They extend
If these are four ordinary grids extending as normal grids in their respective "quadrants", you can try rotating the cursor position 90/180/270 degrees about the origin so that it ends up in one quadrant. Then you can use the ordinary This was a silly answerIVec2::new(x as i32, y as i32) / TILE_SIZE trick to quantize the mouse position into tile coordinates. After that, you have to rotate the cursor position back using the inverse rotation matrix. You'll also have to deal with the edge case of what happens when the cursor is right in the middle, maybe there are no coordinates there?
There has to be a direct way to mathematically determine tile from world coords. You can get world coords from screen coords with raycasting or some other way if it's 2d and never moves
It doesn't seem to me like something that should be very hard, cause there will be "lines" of tiles that continue forever diagonally, right?
so you need to apply this same offset the tile gets, based on distance from some centre point where things are still most aligned to a normal grid
I would not try rotating anything
The first step is to get world coords from screen coords, mention it if you're stuck on that
Nope ^^ only the math...
I mean, they all should have bounding boxes and coordinates, cant you use that?
why not?
you could add "invisible" tiles to get an estimation of what tile could be there ?
(from what I understand, there are also non valid spaces so it's difficult to exactly know which tile would be at any position..?) ; I feel like if the tiles can indefinitely shrink/grow, [x,y] position is maybe not the best choice (but I guess size cannot change much so it's fine 🙂 )
what should happen if the player mouseovers or clicks a gap?
nothing, this is not necessary so far
but I'm afraid it might be eventually
actually
I don't know :)
I feel like there has to be some solution where you find out where on the tile plane the user clicked, and then dividing by tile size and truncating to know how many blocks off-centre that is, and then calculating somehow how off-centre the blocks are there, and compensating
well you want drag and drop with shadow of nearest possible solution right ? see you in a week for the implementation 😄