Penetrator (Geometry lib)
Re: Penetrator (Geometry lib)
OHH GOD, why does so many libs have these kind of names.
Re: Penetrator (Geometry lib)
Its kinda a tradition around herejjmafiae wrote:OHH GOD, why does so many libs have these kind of names.
Your screen is very zoomed in...
- Ranguna259
- Party member
- Posts: 911
- Joined: Tue Jun 18, 2013 10:58 pm
- Location: I'm right next to you
Re: Penetrator (Geometry lib)
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
Re: Penetrator (Geometry lib)
The Penetrator in saints row the thirdRanguna259 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
- Ranguna259
- Party member
- Posts: 911
- Joined: Tue Jun 18, 2013 10:58 pm
- Location: I'm right next to you
Re: Penetrator (Geometry lib)
Oh that, hum.. well, I-I'm hmmm, heh you got mejjmafiae wrote:The Penetrator in saints row the third
Re: Penetrator (Geometry lib)
lolRanguna259 wrote:Oh that, hum.. well, I-I'm hmmm, heh you got mejjmafiae wrote:The Penetrator in saints row the third
Re: Penetrator (Geometry lib)
This one should work: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 ?
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
- Ranguna259
- Party member
- Posts: 911
- Joined: Tue Jun 18, 2013 10:58 pm
- Location: I'm right next to you
Re: Penetrator (Geometry lib)
Yep it works nicely, thanks jonyzz.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
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.
- xXxMoNkEyMaNxXx
- Party member
- Posts: 206
- Joined: Thu Jan 10, 2013 6:16 am
- Location: Canada
Re: Penetrator (Geometry lib)
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.
- Ranguna259
- Party member
- Posts: 911
- Joined: Tue Jun 18, 2013 10:58 pm
- Location: I'm right next to you
Re: Penetrator (Geometry lib)
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 ?
Who is online
Users browsing this forum: No registered users and 1 guest