So, basic things like "angleTo(fixture1, fixture2)" or "angleToXYcomponents(angle)" and "XYcomponentsToAngle(vx,vy)"
Things that dont seem to be included anywhere in love that make life easier.
I can do it myself, but I'd rather stand on the shoulders of giants, naw mean?
Good utility libraries for love.physics? I'm sick of trig :p
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.

 Prole
 Posts: 19
 Joined: Sat Sep 06, 2014 8:50 pm
Re: Good utility libraries for love.physics? I'm sick of tri
Could modified my simple module for drawing arrows.
Code: Select all
local Arrow = {}
local gr,pi,sin,cos,atan2,floor,sqrt = love.graphics,math.pi,math.sin,math.cos,math.atan2,math.floor,math.sqrt
function Arrow.angle( pt1, pt2 )
return atan2( pt1.ypt2.y, pt1.xpt2.x )  pi
end
function Arrow.length(pt1,pt2)
return math.sqrt((pt1.xpt2.x)^2+(pt1.ypt2.y)^2)
end
function Arrow.StartEnd( pt1, pt2, cl )  from, to, color
local cl = cl or { 0, 255, 0 }
gr.setColor( unpack( cl ) )
Arrow.Draw( pt1, pt2 )
local an = floor( 180 * (atan2( pt1.ypt2.y , pt1.xpt2.x ) ) / pi + 270 )
an = an <= 360 and an or an  360
gr.print( an, pt1.x  10, pt1.y + 30 )
end
function Arrow.Direction( pt1, an, ln, cl )  location, direction, length, [color]
local cl = cl or { 0, 255, 0 }
gr.setColor( unpack( cl ) )
local pt2 = {x=ln * cos(an) + pt1.x,y=ln * sin(an) + pt1.y }
Arrow.Draw( pt1, pt2, ln )
local aa = floor( 180 * an / pi + 450 )  convert angle to North = 0 degrees
return aa and aa or aa  360
end
function Arrow.Draw( pt1, pt2, ln )  start, end, [length]
local x1 ,y1, x2, y2 = pt1.x, pt1.y, pt2.x, pt2.y
local ln = ln and ln or sqrt( (x2x1)^2 + (y2y1)^2 )
local hd = 0.2 * ln
gr.line( x1, y1, x2, y2 )  arrow shaft (point1 to point2)
local dx = x2  x1  arrow head (at point2)
local dy = y2  y1
local a1 = 0.42 * pi  atan2( dy , dx )
local x3 = hd * sin( a1) + x2
local y3 = hd * cos( a1 ) + y2
gr.line( x2, y2, x3, y3 )
local a2 = 0.58 * pi  atan2( dy , dx )
local x4 = hd * sin( a2 ) + x2
local y4 = hd * cos( a2 ) + y2
gr.line( x2, y2, x4, y4 )
end
return Arrow

 Prole
 Posts: 19
 Joined: Sat Sep 06, 2014 8:50 pm
Re: Good utility libraries for love.physics? I'm sick of tri
thanks for the offer, mate!
I've implemented all the functions I mentioned up there while I was waiting, but I would still be happy to see any libraries for these kinds of common operations. I'm all about collaboration
I've implemented all the functions I mentioned up there while I was waiting, but I would still be happy to see any libraries for these kinds of common operations. I'm all about collaboration
Re: Good utility libraries for love.physics? I'm sick of tri
Don't know if you've seen, but the wiki has a list of libraries. Lume might be what you want.
Who is online
Users browsing this forum: Bing [Bot] and 7 guests