[Solved + Screenshot!] Tracking mouse coords in a grid?
Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. This forum is archived - please use this set of forums to ask new questions.
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. This forum is archived - please use this set of forums to ask new questions.
[Solved + Screenshot!] Tracking mouse coords in a grid?
I need some help. I've been trying to figure this out on my own for a few days but I've come to the point where I realize I just don't know how to do this.
In the screenshot above, you can see a grid-based inventory window which is 10 x 10 in size. Each grid is 32 x 32 pixels. What I'm trying to do is, I want to know which grid is the mouse currently hovered over. I want the result to return a number from 0 to 99 (well, to be more specific, there are 100 slots, but since ACS arrays are 0-based, that would mean that the results would be from 0 to 99).
The grid is also ordered from left to right, then top to bottom. That means... as you retrieve items, the grid will first be filled from left to right... once it reaches the last grid on the right, it moves down to the next line and starts from the left again.
I haven't the slightest clue on how to achieve this. I'm horrible at maths. Please help. :(
Last edited by Nash on Thu Mar 05, 2009 9:54 am, edited 1 time in total.
Re: [Help] Tracking mouse coords in a grid?
subtract the pointer coords from the top right of the top right square. IE if its at 32, 32: x-32 y-32. this makes the top right zero.
now, since its a nice grid all you have to do is divide x and y by the cell size, then multiply y times 10 and add x;
so if x = 270 and y = 165,
x = x - 32,
y = y - 32,
x = x/32 = 7, (ACS integer math rounds everthing down)
y = y/32 = 4,
index = (y*10)+x = 47,
now, since its a nice grid all you have to do is divide x and y by the cell size, then multiply y times 10 and add x;
so if x = 270 and y = 165,
x = x - 32,
y = y - 32,
x = x/32 = 7, (ACS integer math rounds everthing down)
y = y/32 = 4,
index = (y*10)+x = 47,
Re: [Help] Tracking mouse coords in a grid?
Had to alter it around a bit, but finally got it to work. Thanks Isle, I knew I could count on you for all of this maths-y stuff in ACS. :D You'll be credited!
Code: Select all
// calculate which grid the mouse is currently in
int index, index_x, index_y;
index_x = mousex - GetHUDLeft(640);
index_y = mousey - 32;
index_x = index_x / 32;
index_y = index_y / 32;
index = (index_y * 10) + index_x;
- Cutmanmike
- Posts: 11336
- Joined: Mon Oct 06, 2003 3:41 pm
- Operating System Version (Optional): Windows 10
- Location: United Kingdom
- Contact:
Re: [Help] Tracking mouse coords in a grid?
Looks great btw Nash. I long for a decent rpg zdoom adventure, even if it's just a mod to use with doom2 maps.
Re: [Help] Tracking mouse coords in a grid?
Thanks Cutty.
Behold! Thanks to Isle, we now have a working mouse-based inventory, and hovering the mouse over an item will correctly display the item's data! The sword in the screenshot was defined in the master items database to have a base damage of 25, and durability of 50. As you can see in the shot, that one sword in particular that has been pointed over, has its stats randomized. If I were to point the mouse over the other swords in that screenshot, they'd all have different values. Diablo-style items anyone?
Behold! Thanks to Isle, we now have a working mouse-based inventory, and hovering the mouse over an item will correctly display the item's data! The sword in the screenshot was defined in the master items database to have a base damage of 25, and durability of 50. As you can see in the shot, that one sword in particular that has been pointed over, has its stats randomized. If I were to point the mouse over the other swords in that screenshot, they'd all have different values. Diablo-style items anyone?
- Cutmanmike
- Posts: 11336
- Joined: Mon Oct 06, 2003 3:41 pm
- Operating System Version (Optional): Windows 10
- Location: United Kingdom
- Contact:
Re: [Solved + Screenshot!] Tracking mouse coords in a grid?
As a Diablo nut, colour me interested.
- Osiris Kalev
- Posts: 290
- Joined: Sun Aug 20, 2006 11:06 pm
- Location: Australia, Elsewhere Within
- Contact:
Re: [Solved + Screenshot!] Tracking mouse coords in a grid?
That's shiny Nash.
Re: [Solved + Screenshot!] Tracking mouse coords in a grid?
Everybody loves the Daggerfall dagger.
- Captain Proof
- Posts: 1028
- Joined: Wed Aug 27, 2008 8:51 am
- Location: Henderson
- Contact:
Re: [Solved + Screenshot!] Tracking mouse coords in a grid?
Wasn't that an Ebony Dagger?I can't remember,I tried to load Daggerfall on Dosbox but it's being a bitch and saying that it can't detect the CD even after I mounted my damn CDrom.
Re: [Solved + Screenshot!] Tracking mouse coords in a grid?
As usual for me, the Daggerfall dagger is a temporary placeholder sprite. This will have 100% original graphics, this effort demonstrated by the new status bar...
Re: [Solved + Screenshot!] Tracking mouse coords in a grid?
Yes and no. Daggerfall used translations for the various exotic metals. Iron, steel, silver, dwarven, ebony, adamantium, mithril, orcish, daedric... They all used the same sprites. Just with different colors (green for orcish, black for ebony, red for daedric, etc.). The default color (the one you get if you rip the sprites) corresponds to steel IIRC.Captain Proof wrote:Wasn't that an Ebony Dagger?
Sorry for the digression.Nash wrote:As usual for me, the Daggerfall dagger is a temporary placeholder sprite. This will have 100% original graphics, this effort demonstrated by the new status bar...