Editgrid - gamera compatible scaling grid
Re: Editgrid - gamera compatible scaling grid
I like it! You also properly did scaling: up then down then up returns exactly the same previous value (this is not true for all projects where zooming is used).
Re: Editgrid - gamera compatible scaling grid
This is very cool!
I plan on integrating this with a voxel type game prototype.
Question: I see you have the helper functions to take a x/y value to/from screen/world coordinates, however the principle benefit of a grid is to take a x/y screen/world coordinate and and provide grid cell position without having to do the math by hand. Perhaps something as:
Anyway, awesome lib keep it up
I plan on integrating this with a voxel type game prototype.
Question: I see you have the helper functions to take a x/y value to/from screen/world coordinates, however the principle benefit of a grid is to take a x/y screen/world coordinate and and provide grid cell position without having to do the math by hand. Perhaps something as:
Code: Select all
grid:toCellPosition('screen', x, y) -- Returns cell position from screen coords, relative to origin ex: 0, -2
grid:toCellPosition('world', x, y) -- Returns cell position from world coords, relative to origin ex: 0, 50
grid:fromCellPosition('screen', x, y) -- Returns screen coordinates from cell position.
grid:fromCellPosition('world', x, y) -- Returns world coordinates from cell position.
Re: Editgrid - gamera compatible scaling grid
Hmm, I definitely could add that. However, the cells in the grid are dynamically based on the camera zoom. Should I just return a cell coordinate or a bounding box? I think I could return the cell coordinates if the user can also get the size of the grid, which is already in the code. There is also some other math I would like to add.rlaitila wrote:This is very cool!
I plan on integrating this with a voxel type game prototype.
Question: I see you have the helper functions to take a x/y value to/from screen/world coordinates, however the principle benefit of a grid is to take a x/y screen/world coordinate and and provide grid cell position without having to do the math by hand. Perhaps something as:
Anyway, awesome lib keep it upCode: Select all
grid:toCellPosition('screen', x, y) -- Returns cell position from screen coords, relative to origin ex: 0, -2 grid:toCellPosition('world', x, y) -- Returns cell position from world coords, relative to origin ex: 0, 50 grid:fromCellPosition('screen', x, y) -- Returns screen coordinates from cell position. grid:fromCellPosition('world', x, y) -- Returns world coordinates from cell position.
Thanks for the feedback, btw
((_((_CRAYOLA_((_((_> GitHub <_((_((_CRAYOLA_((_(()
Re: Editgrid - gamera compatible scaling grid
You are right, arbitrary zoom could impose a problem. Perhaps the user can supply a zoom factor to the grid position methods, which will return the cell position within that zoom factor. So, if you wish to lock your cell position points you simply supply a consistent zoom factor (ex: 1)
I don't wish to dictate your api, but for the sake of examples:
I don't wish to dictate your api, but for the sake of examples:
Code: Select all
--
-- Returns grid position from screen or world coordinates and camera zoom factor
-- @param [number]X : The X Screen or World coordinate
-- @param [number]Y : The Y Screen or World coordinate
-- @param [number]ZF : The Zoom Factor to apply
-- @param [string]CS : The Coordinate System to apply calculations ('world'|'screen')
-- @returns [number]CELLX, [number]CELLY
-- @example grid:toGridPosition(love.graphics.getWidth()/2, love.graphics.getHeight()/2, 1, 'screen') -> 2,4
--
function grid:toGridPosition(X, Y, ZF, CS)
-- super awesome code
end
--
-- Returns Screen or World coordinates based on cell grid position
-- @param [number]X : The X Cell Grid Position
-- @param [number]Y : The Y Cell Grid Position
-- @param [number]ZF : The Zoom Factor to source from
-- @param [string]CS : The Coordinate System to apply calculations ('world'|'screen')
-- @returns [number]COORDX, [number]COORDY
-- @example grid:fromGridPosition(2, 4, 1, 'screen') -> 400,300
--
function grid:fromGridPosition(X, Y, ZF, CS)
-- super awesome code
end
Re: Editgrid - gamera compatible scaling grid
Check out the current version on github, I added 3 functions. editgrid.minorInterval and editgrid.majorInterval get the distance in world space between gridlines. Also, I added editgrid.convertCoords, which can convert coordinates between world space, screen space, and cell space in one function.
As for the zoom problem, It's not really a zoom problem, it's that the grid spacing depends on the visuals table (which is why editgrid.convertCoords requires the visuals table). With the colon syntax versions of that function however, it doesn't matter. Anyway, please try the new demo .love file.
As for the zoom problem, It's not really a zoom problem, it's that the grid spacing depends on the visuals table (which is why editgrid.convertCoords requires the visuals table). With the colon syntax versions of that function however, it doesn't matter. Anyway, please try the new demo .love file.
- Attachments
-
- editgrid-v0.0.2.love
- (3.85 KiB) Downloaded 92 times
((_((_CRAYOLA_((_((_> GitHub <_((_((_CRAYOLA_((_(()
- Positive07
- Party member
- Posts: 1014
- Joined: Sun Aug 12, 2012 4:34 pm
- Location: Argentina
Re: Editgrid - gamera compatible scaling grid
This is awesome! I have been hacking around it for a while, I changed some things thought, mostly the use of setScale when drawing the grid since setLineWidth clamps the value to an specific minimum value the lines start to look huge, so I deleted it entirely and used manual multiplication instead. This also allowed me to floor the values and add .5 in order to get pixel perfect lines, and that looks really good!
The other change I made was the ability to pass a function for the subdivisions value so that you can make it depend on the size and zoom (That looks pretty cool because you can show littler squares when the users zooms in)
But you have surely made my work A LOT easier! so thanks!
PS: If you are interested in any of this features I may be able to make a PR in Github!
The other change I made was the ability to pass a function for the subdivisions value so that you can make it depend on the size and zoom (That looks pretty cool because you can show littler squares when the users zooms in)
But you have surely made my work A LOT easier! so thanks!
PS: If you are interested in any of this features I may be able to make a PR in Github!
for i, person in ipairs(everybody) do
[tab]if not person.obey then person:setObey(true) end
end
love.system.openURL(github.com/pablomayobre)
[tab]if not person.obey then person:setObey(true) end
end
love.system.openURL(github.com/pablomayobre)
Re: Editgrid - gamera compatible scaling grid
Yeah, feel free to send a pull request. I haven't seen the issue with the lines when i'm testing, though, but I'll look into that. The function for the subdivision values is a good idea, an could just be added as an extra option to the visuals table.Positive07 wrote:This is awesome! I have been hacking around it for a while, I changed some things thought, mostly the use of setScale when drawing the grid since setLineWidth clamps the value to an specific minimum value the lines start to look huge, so I deleted it entirely and used manual multiplication instead. This also allowed me to floor the values and add .5 in order to get pixel perfect lines, and that looks really good!
The other change I made was the ability to pass a function for the subdivisions value so that you can make it depend on the size and zoom (That looks pretty cool because you can show littler squares when the users zooms in)
But you have surely made my work A LOT easier! so thanks!
PS: If you are interested in any of this features I may be able to make a PR in Github!
I'm glad some people besides me find this useful
((_((_CRAYOLA_((_((_> GitHub <_((_((_CRAYOLA_((_(()
- Positive07
- Party member
- Posts: 1014
- Joined: Sun Aug 12, 2012 4:34 pm
- Location: Argentina
Re: Editgrid - gamera compatible scaling grid
Sure, I will try to make the changes in a tidy way and PR when I have time again.
Here is what I have been working on, UI is missing so right now it is limited to what you see
Here is what I have been working on, UI is missing so right now it is limited to what you see
- right click and drag to move around
- left click to paint pixels green (only color because no UI)
- wheel up to zoom in and down to zoom out (check the correct zooming, it is pretty nice, also the change on the grid)
- q and e rotate (not sure that would be needed when I release this but looks cool)
- resize window if you want, should stay centered where you left it
- Canvas free, because my computer sucks!
- 160x144 image, but could be resized... but no UI to do so!
- Attachments
-
- editor.love
- Not ready for distribution but you can look at it!
- (8.55 KiB) Downloaded 105 times
for i, person in ipairs(everybody) do
[tab]if not person.obey then person:setObey(true) end
end
love.system.openURL(github.com/pablomayobre)
[tab]if not person.obey then person:setObey(true) end
end
love.system.openURL(github.com/pablomayobre)
Re: Editgrid - gamera compatible scaling grid
Nice looking editor so far, it's cool to see how people are customizing how it looks. Just merged your PR along with another, so check out the most recent code on github! (shakesoda also fixed a few things and added some features.)Positive07 wrote:Sure, I will try to make the changes in a tidy way and PR when I have time again.
Here is what I have been working on, UI is missing so right now it is limited to what you see
- right click and drag to move around
- left click to paint pixels green (only color because no UI)
- wheel up to zoom in and down to zoom out (check the correct zooming, it is pretty nice, also the change on the grid)
- q and e rotate (not sure that would be needed when I release this but looks cool)
- resize window if you want, should stay centered where you left it
- Canvas free, because my computer sucks!
- 160x144 image, but could be resized... but no UI to do so!
((_((_CRAYOLA_((_((_> GitHub <_((_((_CRAYOLA_((_(()
- Positive07
- Party member
- Posts: 1014
- Joined: Sun Aug 12, 2012 4:34 pm
- Location: Argentina
Re: Editgrid - gamera compatible scaling grid
Thank! With a little bit of UI it already looks better!bakpakin wrote:Nice looking editor so far, it's cool to see how people are customizing how it looks. Just merged your PR along with another, so check out the most recent code on github! (shakesoda also fixed a few things and added some features.)
Sure I'll update! I still have that sharp lines thing but as I said I have to fix some things first before committing
for i, person in ipairs(everybody) do
[tab]if not person.obey then person:setObey(true) end
end
love.system.openURL(github.com/pablomayobre)
[tab]if not person.obey then person:setObey(true) end
end
love.system.openURL(github.com/pablomayobre)
Who is online
Users browsing this forum: Ahrefs [Bot] and 1 guest