#Calculating 'complex' mouse_pos_to_tile.

33 messages · Page 1 of 1 (latest)

supple sky
#

So I'm making a game where the tile are as follow in the picture (tiles are making a grid, but they are with an offset which forms an out of bound area).

I've tried to calculate the tile that the mouse is hovering onto without success.

thanks for the help :).

I'm here if it needs more clarification...

true ginkgo
#

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)

supple sky
#

They extend

true ginkgo
#

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 IVec2::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? This was a silly answer

supple sky
#

maybe

#

I'll check the solution tomorrow !

#

thanks for your input :)

wicked quartz
#

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

supple sky
#

Nope ^^ only the math...

supple sky
#

so the tiles tiles this way

supple sky
#

wait

#

did I make mistake on the drawing

west pagoda
#

I mean, they all should have bounding boxes and coordinates, cant you use that?

supple sky
#

that's what I did

#

but using this means it can't be use when tiles are not here

wicked quartz
#

why not?

indigo nimbus
#

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 🙂 )

supple sky
#

I'll mark this as solved for now

#

not exactly what I wanted but works for now

wicked quartz
supple sky
#

nothing, this is not necessary so far

#

but I'm afraid it might be eventually

#

actually

#

I don't know :)

wicked quartz
#

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

indigo nimbus
#

well you want drag and drop with shadow of nearest possible solution right ? see you in a week for the implementation 😄