Editgrid - gamera compatible scaling grid

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
bakpakin
Party member
Posts: 114
Joined: Sun Mar 15, 2015 9:29 am
Location: Boston

Editgrid - gamera compatible scaling grid

Post by bakpakin »

Image
Now on github at https://github.com/bakpakin/Editgrid

EDIT: Please look at the github repo for most up-to-date code and documentation.

Editgrid is a module that implements a grid that automatically scales its resolution, like the background grids in 3d modeling software like blender.
Its great for level editors and the like because you can zoom in and out without loosing sight of the gridlines.
It also converts screen coordinates to grid coordinates and vice versa.

Editgrid is also useful for adding a debugging background to games - just call editgrid.draw(camera) with
a gamera or HUMP camera, or just any table.

How to use
Place editgrid.lua in your project and require it like so:

Code: Select all

local editgrid = require "editgrid"
API
Drawing a grid

Code: Select all

editgrid.draw(camera, visuals)
Draws a grid to the screen from the perspective of an optional camera with optional visual effects.

'camera' can be a HUMP or gamera camera, as well as a table containing the following:

Code: Select all

local camera = {
    x = 20,
    y = 20,
    zoom = 2,
    angle = math.pi/2,
    sx = 5,
    sy = 5,
    sw = love.graphics.getWidth() - 10,
    sh = love.graphics.getHeight() - 10
}
* '(x, y)' -- the point the camera is looking at. Default is (0, 0).
* 'zoom' -- the zoom factor of the camera. Default is 1.
* 'angle' -- the angle of the camera. Default is 0.
* '(sx, sy, sw, sh)' -- the clipping rectangle (scissor rectangle) for the camera. By default,
the camera draws to the whole screen (0, 0, love.graphics.getWidth(), love.graphics.getHeight()).

'visuals' should be a table containing the following:

Code: Select all

local visuals = {
    size = 100,
    subdivisions = 5,
    color = {128, 140, 250},
    drawScale = false,
    xColor = {255, 255, 0},
    yColor = {0, 255, 255},
    fadeFactor = 0.3,
    interval = 200
}
* 'size' -- the distance between each major subdivision at 1x zoom. Default is 256.
* 'subdivisions' -- the number of minor subdivisions between each major subdivision. Default is 4.
* 'color' -- a list of three numbers representing the rgb values of the grid lines. Default is {220, 220, 220}.
* 'drawScale' -- boolean indicating if the coordinate value is drawn for each gridline. Default is true.
* 'xColor' -- color of the x axis. Default is {255, 0, 0} (red).
* 'yColor' -- color of the y axis. Default is {0, 255, 0} (green).
* 'fadeFactor' -- color multiplier on subdivision grid lines. For example, if 'color' is {100, 100, 100} and 'fadeFactor' is
0.8, then the color of the minor gridlines will be {80, 80, 80}. Default is 0.5.
* 'interval' -- optional argument that makes the grid use a fixed interval instead of scaling with camera zoom.

Coordinate conversion

Code: Select all

local worldx, worldy = editgrid.toWorld(camera, screenx, screeny)
Converts screen coordinates to world coordinates. 'camera' can be any camera recognized by Editgrid (gamera, HUMP, table).

Code: Select all

local screenx, screeny = editgrid.toScreen(camera, worldx, worldy)
Converts world coordinates to screen coordinates. 'camera' can be any camera recognized by Editgrid (gamera, HUMP, table).

Bugs
If there are bugs or you want to request features, feel free to submit issues.

In the love file, use Q and E to rotate the camera.
Attachments
editgrid.love
(3.12 KiB) Downloaded 202 times
editgrid.lua
(7.03 KiB) Downloaded 176 times
Last edited by bakpakin on Mon Jul 13, 2015 2:50 pm, edited 4 times in total.
((_((_CRAYOLA_((_((_> GitHub <_((_((_CRAYOLA_((_(()
User avatar
Tesselode
Party member
Posts: 555
Joined: Fri Jul 23, 2010 7:55 pm

Re: Editgrid - gamera compatible scaling grid

Post by Tesselode »

Looks pretty cool! Can you throw this on GitHub or something? It'll make it a lot easier to keep track of updates and stuff like that.
User avatar
Positive07
Party member
Posts: 1014
Joined: Sun Aug 12, 2012 4:34 pm
Location: Argentina

Re: Editgrid - gamera compatible scaling grid

Post by Positive07 »

Tesselode wrote:Looks pretty cool! Can you throw this on GitHub or something? It'll make it a lot easier to keep track of updates and stuff like that.
Please!! Github!! I love this, simple and nice... It's perfect!
for i, person in ipairs(everybody) do
[tab]if not person.obey then person:setObey(true) end
end
love.system.openURL(github.com/pablomayobre)
User avatar
bakpakin
Party member
Posts: 114
Joined: Sun Mar 15, 2015 9:29 am
Location: Boston

Re: Editgrid - gamera compatible scaling grid

Post by bakpakin »

Ok, i'll put it on github :awesome:
Here's the repo: https://github.com/bakpakin/Editgrid
((_((_CRAYOLA_((_((_> GitHub <_((_((_CRAYOLA_((_(()
User avatar
Positive07
Party member
Posts: 1014
Joined: Sun Aug 12, 2012 4:34 pm
Location: Argentina

Re: Editgrid - gamera compatible scaling grid

Post by Positive07 »

bakpakin wrote:Ok, i'll put it on github :awesome:
Here's the repo: https://github.com/bakpakin/Editgrid
And there is my STAR!!
for i, person in ipairs(everybody) do
[tab]if not person.obey then person:setObey(true) end
end
love.system.openURL(github.com/pablomayobre)
User avatar
Tesselode
Party member
Posts: 555
Joined: Fri Jul 23, 2010 7:55 pm

Re: Editgrid - gamera compatible scaling grid

Post by Tesselode »

Positive07 wrote:
bakpakin wrote:Ok, i'll put it on github :awesome:
Here's the repo: https://github.com/bakpakin/Editgrid
And there is my STAR!!
And my axe!
Almia
Prole
Posts: 8
Joined: Mon Aug 05, 2013 7:56 am

Re: Editgrid - gamera compatible scaling grid

Post by Almia »

Tesselode wrote:
Positive07 wrote:
bakpakin wrote:Ok, i'll put it on github :awesome:
Here's the repo: https://github.com/bakpakin/Editgrid
And there is my STAR!!
And my axe!
And my potato!
User avatar
arampl
Party member
Posts: 248
Joined: Mon Oct 20, 2014 3:26 pm

Re: Editgrid - gamera compatible scaling grid

Post by arampl »

Cool!

One tip, though: by unwritten law colors used for axises uses x = red, y = green, z = blue (XYZ, RGB, little easier to remember in some cases, for example if you implement grid rotation someday).
User avatar
bakpakin
Party member
Posts: 114
Joined: Sun Mar 15, 2015 9:29 am
Location: Boston

Re: Editgrid - gamera compatible scaling grid

Post by bakpakin »

arampl wrote:Cool!

One tip, though: by unwritten law colors used for axises uses x = red, y = green, z = blue (XYZ, RGB, little easier to remember in some cases, for example if you implement grid rotation someday).
Just updated to version 0.0.1 :o ! Added grid rotation and support for hump cameras.

All works pretty well, but labeling of the grid only works when the grid isn't rotated.

I also changed the axis colors and the api slightly, but everything is still there. The biggest change in the api is that drawing the grid takes the camera angle, and camx and camy specify the center of the grid. Please see the github repo (https://github.com/bakpakin/Editgrid) for the new code and api.

Lastly, I added examples for hump, gamera, and standalone use of editgrid in the repo.
((_((_CRAYOLA_((_((_> GitHub <_((_((_CRAYOLA_((_(()
User avatar
bakpakin
Party member
Posts: 114
Joined: Sun Mar 15, 2015 9:29 am
Location: Boston

Re: Editgrid - gamera compatible scaling grid

Post by bakpakin »

Just fixed the problem of drawing the scale when the grid is rotated (math skillz :cool: ). Also, cleaned up the API again. The code is way cleaner now, and prettier (in my opinion). Try out the new demo, and use Q and E to rotate the camera.
((_((_CRAYOLA_((_((_> GitHub <_((_((_CRAYOLA_((_(()
Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests