Penetrator (Geometry lib)

Showcase your libraries, tools and other projects that help your fellow love users.
jjmafiae
Party member
Posts: 1331
Joined: Tue Jul 24, 2012 8:22 am

Re: Penetrator (Geometry lib)

Post by jjmafiae »

OHH GOD, why does so many libs have these kind of names.
User avatar
mickeyjm
Party member
Posts: 237
Joined: Thu Dec 29, 2011 11:41 am

Re: Penetrator (Geometry lib)

Post by mickeyjm »

jjmafiae wrote:OHH GOD, why does so many libs have these kind of names.
Its kinda a tradition around here
Your screen is very zoomed in...
User avatar
Ranguna259
Party member
Posts: 911
Joined: Tue Jun 18, 2013 10:58 pm
Location: I'm right next to you

Re: Penetrator (Geometry lib)

Post by Ranguna259 »

Well it's called penetrator because the first function that I added to the lib was getInter() which gives you the "penetration" rectangle area of both intersecting rectangles, I don't know what else that name would refer to ;)
LoveDebug- A library that will help you debug your game with an on-screen fully interactive lua console, you can even do code hotswapping :D

Check out my twitter.
jjmafiae
Party member
Posts: 1331
Joined: Tue Jul 24, 2012 8:22 am

Re: Penetrator (Geometry lib)

Post by jjmafiae »

Ranguna259 wrote:Well it's called penetrator because the first function that I added to the lib was getInter() which gives you the "penetration" rectangle area of both intersecting rectangles, I don't know what else that name would refer to ;)
The Penetrator in saints row the third :ultraglee:
User avatar
Ranguna259
Party member
Posts: 911
Joined: Tue Jun 18, 2013 10:58 pm
Location: I'm right next to you

Re: Penetrator (Geometry lib)

Post by Ranguna259 »

jjmafiae wrote:The Penetrator in saints row the third :ultraglee:
Oh that, hum.. well, I-I'm hmmm, heh you got me :roll:
LoveDebug- A library that will help you debug your game with an on-screen fully interactive lua console, you can even do code hotswapping :D

Check out my twitter.
jjmafiae
Party member
Posts: 1331
Joined: Tue Jul 24, 2012 8:22 am

Re: Penetrator (Geometry lib)

Post by jjmafiae »

Ranguna259 wrote:
jjmafiae wrote:The Penetrator in saints row the third :ultraglee:
Oh that, hum.. well, I-I'm hmmm, heh you got me :roll:
lol
jonyzz
Prole
Posts: 48
Joined: Sun Sep 02, 2012 9:35 pm

Re: Penetrator (Geometry lib)

Post by jonyzz »

Ranguna259 wrote:
vrld wrote:Sorry, but your code is not very good and much too long. Here is a shorter version:

Code: Select all

function isInter(a, b)
	local ax2,ay2,bx2,by2 = a.x + a.width, a.y + a.height, b.x + b.width, b.y + b.height
	return a.x < bx2 and ax2 > b.x and a.y < by2 and ay2 > b.y
end

function getInter(a, b)
	if not isInter(a, b) then return end

	if a.x > b.x then a,b = b,a end
	local x = b.x
	local w = a.x + a.width - b.x

	if a.y > b.y then a,b = b,a end
	local y = b.y
	local h = a.y + a.height - b.y

	return newRect(x,y,w,h)
end
...
Your code doesn't work when obj2 has bigger or smaller width or height, that's why the code is big, this is not a collision detection lib, it's just a geometry lib.. Wait don't tell me that the libs you said do what this does do they ? :ultrashocked:
This one should work:

Code: Select all

local function getInter(a, b)
    local left = math.max(a.x, b.x)
    local right = math.min(a.x + a.width, b.x + b.width)
    local top = math.max(a.y, b.y)
    local bottom = math.min(a.y + a.height, b.y + b.height)
    if left < right and top < bottom then
        return newRect(left, top, right - left, bottom - top)
    end
end
User avatar
Ranguna259
Party member
Posts: 911
Joined: Tue Jun 18, 2013 10:58 pm
Location: I'm right next to you

Re: Penetrator (Geometry lib)

Post by Ranguna259 »

jonyzz wrote:
This one should work:

Code: Select all

local function getInter(a, b)
    local left = math.max(a.x, b.x)
    local right = math.min(a.x + a.width, b.x + b.width)
    local top = math.max(a.y, b.y)
    local bottom = math.min(a.y + a.height, b.y + b.height)
    if left < right and top < bottom then
        return newRect(left, top, right - left, bottom - top)
    end
end
Yep it works nicely, thanks jonyzz.
You code has been added to the source and to github.

Found rectangle.java source code, I'm gonna start converting now, anyone who want to help is free to, just pick up the code in the link, convert it to löve and post it here or on GitHub.
LoveDebug- A library that will help you debug your game with an on-screen fully interactive lua console, you can even do code hotswapping :D

Check out my twitter.
User avatar
xXxMoNkEyMaNxXx
Party member
Posts: 206
Joined: Thu Jan 10, 2013 6:16 am
Location: Canada

Re: Penetrator (Geometry lib)

Post by xXxMoNkEyMaNxXx »

Does anyone have code for the area of intersection of two squares with arbitrary size, position, and rotation? I could make a perfect image resize and rotate with it. I might make it eventually if no one else has.
User avatar
Ranguna259
Party member
Posts: 911
Joined: Tue Jun 18, 2013 10:58 pm
Location: I'm right next to you

Re: Penetrator (Geometry lib)

Post by Ranguna259 »

The code for the area part would just be the code in getInter and then it'd just multiply the width for the height and the position is just the x and the y coord of the output rectangle (I'll code both of them tomorrow) but rotation.. Can we rotate rectangles in löve ?
LoveDebug- A library that will help you debug your game with an on-screen fully interactive lua console, you can even do code hotswapping :D

Check out my twitter.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest