Page 7 of 8

Re: Loveballs, A love2d Softbody lib

Posted: Wed Feb 11, 2015 10:11 pm
by Connorses
Thanks for all the help, by the way, I'm just busy lately with college, but I fully intend to re-write my code from scratch to incorporate everything I need when I've got some spare time. I'm confident I'll now have all the tools I need if I decide to continue with the softbody game.

Re: Loveballs, A love2d Softbody lib

Posted: Thu Feb 12, 2015 4:26 am
by IndieRetro
Connorses wrote:Thanks for all the help, by the way, I'm just busy lately with college, but I fully intend to re-write my code from scratch to incorporate everything I need when I've got some spare time. I'm confident I'll now have all the tools I need if I decide to continue with the softbody game.
Awesome! If you make anything using it let me know, I'd love to see it ^^

Re: Loveballs, A love2d Softbody lib

Posted: Sun Feb 22, 2015 6:25 pm
by Ranguna259
Love you lib, now we can do games like microtrip :P
But I'd like to ask some changes if you don't mind.

1. Instead of having the global "Softbody" maybe you could local that variable in init.lua and in the then return it, like this:
init.lua

Code: Select all

--Softbody lib by Shorefire/Steven
--tesselate function by Amadiro/Jonathan Ringstad
local path = ...;
require(path.."/class");
local Softbody = newclass("Softbody");

...

function tessellate(vertices, new_vertices)

  ...

  for i = 1,#new_vertices,4 do
    if i == 1 then
      -- x coordinate
      new_vertices[1] = MIX_FACTOR*(new_vertices[#new_vertices - 1] + new_vertices[3])/2 + (1 - MIX_FACTOR)*new_vertices[1]
      -- y coordinate
      new_vertices[2] = MIX_FACTOR*(new_vertices[#new_vertices - 0] + new_vertices[4])/2 + (1 - MIX_FACTOR)*new_vertices[2]
    else
      -- x coordinate
      new_vertices[i] = MIX_FACTOR*(new_vertices[i - 2] + new_vertices[i + 2])/2 + (1 - MIX_FACTOR)*new_vertices[i]
      -- y coordinate
      new_vertices[i + 1] = MIX_FACTOR*(new_vertices[i - 1] + new_vertices[i + 3])/2 + (1 - MIX_FACTOR)*new_vertices[i + 1]
    end
  end
end

return Softbody
main.lua

Code: Select all

softbody = require('loveballs')
or

Code: Select all

randomvariablename = require('loveballs')
2. We have to update every softbody we create individually, it'd be great if we could create a softbody world which then we would use to create bodies and then we'd just need to update the world instead of every body:
main.lua

Code: Select all

softbody = require('loveballs')
function love.load()
  physWorld = love.physics.newWorld(0,9.81,true)
  softWorld = softbody:newWorld(physWorld)
  soft1 = softWorld:newBody(world, 400, -200, 100, 2, 4)
  soft2 = softWorld:newBody(world, 400, 0, 35, 2, 4)
end

function love.update()
  softWorld:update()
end

function love.draw()
  soft1:draw()
  soft2:draw("line")
end
What do you think ?

Re: Loveballs, A love2d Softbody lib

Posted: Sun Feb 22, 2015 7:18 pm
by ArchAngel075
Ranguna259 wrote: -snip-

Microtrip looks incredibly cute and fun :awesome: , too bad im not too big a fan of mobile games :nyu:

If you want to have the changes made then perhaps pull request the project on github - I would do so myself seeing as i might want the softbody world aswell for future ideas (ive never need for it yet as my on hold project only had one softbody to deal with at a time)

Re: Loveballs, A love2d Softbody lib

Posted: Tue Feb 24, 2015 1:04 am
by IndieRetro
Ranguna259 wrote:Love you lib, now we can do games like microtrip :P
But I'd like to ask some changes if you don't mind.

1. Instead of having the global "Softbody" maybe you could local that variable in init.lua and in the then return it, like this:
init.lua

Code: Select all

--Softbody lib by Shorefire/Steven
--tesselate function by Amadiro/Jonathan Ringstad
local path = ...;
require(path.."/class");
local Softbody = newclass("Softbody");

...

function tessellate(vertices, new_vertices)

  ...

  for i = 1,#new_vertices,4 do
    if i == 1 then
      -- x coordinate
      new_vertices[1] = MIX_FACTOR*(new_vertices[#new_vertices - 1] + new_vertices[3])/2 + (1 - MIX_FACTOR)*new_vertices[1]
      -- y coordinate
      new_vertices[2] = MIX_FACTOR*(new_vertices[#new_vertices - 0] + new_vertices[4])/2 + (1 - MIX_FACTOR)*new_vertices[2]
    else
      -- x coordinate
      new_vertices[i] = MIX_FACTOR*(new_vertices[i - 2] + new_vertices[i + 2])/2 + (1 - MIX_FACTOR)*new_vertices[i]
      -- y coordinate
      new_vertices[i + 1] = MIX_FACTOR*(new_vertices[i - 1] + new_vertices[i + 3])/2 + (1 - MIX_FACTOR)*new_vertices[i + 1]
    end
  end
end

return Softbody
main.lua

Code: Select all

softbody = require('loveballs')
or

Code: Select all

randomvariablename = require('loveballs')
2. We have to update every softbody we create individually, it'd be great if we could create a softbody world which then we would use to create bodies and then we'd just need to update the world instead of every body:
main.lua

Code: Select all

softbody = require('loveballs')
function love.load()
  physWorld = love.physics.newWorld(0,9.81,true)
  softWorld = softbody:newWorld(physWorld)
  soft1 = softWorld:newBody(world, 400, -200, 100, 2, 4)
  soft2 = softWorld:newBody(world, 400, 0, 35, 2, 4)
end

function love.update()
  softWorld:update()
end

function love.draw()
  soft1:draw()
  soft2:draw("line")
end
What do you think ?
As for the first point, I'll probably do that at somepoint when I get a chance.

But the second point, personally I dislike this as I find it better to keep each softbody individual, as each one is its own object you may want to update them at different times, or store them in your own tables and iterate over those tables to draw/update them as you please. It's just generally better coding imo.

Besides, the updating isnt to actually update the physics object, thats all handled in Box2D's world update, the softbody update is for updaing the tesselation for drawing, which realistically you should only ever call when drawing it, so its good to keep these things seperate and let the programmer call them when they need them :p

But I'll 100% implement that first idea at some point, when I get the chance. I really need to go over all the code at somepoint and clean it all up, add a few useful functions and make it more modular.

Re: Loveballs, A love2d Softbody lib

Posted: Tue Feb 24, 2015 2:24 pm
by IndieRetro
Small update released, fixed a few bugs and things.

See first post for changes.

Re: Loveballs, A love2d Softbody lib

Posted: Fri Feb 27, 2015 7:13 pm
by IndieRetro
Update released, see first post for details.

Re: Loveballs, A love2d Softbody lib

Posted: Mon Jul 27, 2015 5:14 am
by Ulydev
Where has this gone ? :cry:

Re: Loveballs, A love2d Softbody lib

Posted: Mon Jul 27, 2015 2:08 pm
by IndieRetro
Ulydev wrote:Where has this gone ? :cry:
It's back up now.

Re: Loveballs, A love2d Softbody lib

Posted: Mon Jul 27, 2015 6:04 pm
by Ulydev
Neat ! Thank you :awesome:

That'd be very much appreciated if you put the source for the example shown here, with dragging features : https://www.youtube.com/watch?t=13&v=LFBQypY7E3E