Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (483)
Games in Android Showcase (110)
games submitted by our members
Games in WIP (550)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Getting started with 2d physics system of shapes connected with "springs"?  (Read 750 times)
0 Members and 1 Guest are viewing this topic.
Offline jam

Senior Newbie





« Posted 2013-05-09 10:45:10 »

Hi!

I need to simulate a 2d system consisting of different shapes that are attached to each others with "springs". The forces at work should position & rotate the shapes to even out the "pressure" on the system while maintaining a right angle between their line segments and the "springs" by bending the springs accordingly... and stuff like that.

Is there something better for this sort of thing than starting out with box2d? I have not delved into the requirements very deeply as of yet, but on a first glance box2d does not really look like the right tool for the job and would leave me to figure out low level math "Newton–Raphson method" stuff and such on my own to implement some of the forces at work (which considering that I don't know what the "Newton–Raphson method" is as of yet sounds like an awful lot of reading ahead).

If someone could just list a few relevant math/physics/programming terms that I should be looking up would be great, too - maybe I'm just not finding what I need to use/do/read/learn because my english lacks the right vocabulary (+search terms Wink) when it comes to things like that.
Offline relminator
« Reply #1 - Posted 2013-05-09 13:52:30 »

I used to do springs via hooke's law.

I'm not sure but I believe it's F = -kx.

x is the 1d distance
k is a constant
F is the force

Be careful though since spring physics tend to explode with minimal changes.

I'll try to find my old c++ spring simulator( doesn't use sqrt too.

Or you could go ahead and google "hugo elias"  he's got a nice article in regard to that.
Offline jam

Senior Newbie





« Reply #2 - Posted 2013-05-09 16:56:27 »

Oh god yes, math is horrible xD

In Addition to that "hugo elias stuff" (thanks!) I found this which looks as if it would be very helpful if I understood half of it (and the wikipedia pages it lead me to):
http://wismuth.com/elas/elasticity.html

So for now, I did some "Prototyping" in jmonkey. My shapes start rotating towards connected shapes and organizing themselves which looks fine at first, but then they just take off and fly away without me in a well organized "flock" of rotating geometries xD

Does anyone know something that's better suited for 2d physics prototyping with java? Couldn't find a single 2d engine that has rendering of physics nodes already implemented... might try one of the c++ prototyping engines if I don't manage to understand that "spring stuff" while playing with jmonkey.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline jam

Senior Newbie





« Reply #3 - Posted 2013-05-10 09:42:20 »

Hmmm... after I fixed some bad Quaternions (I hate those things!), it looks to me like the forces work almost as intended. But the system fails to reach an equilibrium. It looks like the physics are ok, so it's probably a concept problem (and not a code problem).

The forces at work are:
- 50% dampening
- a small, fixed force pushing all object away from those they're not connected (to keep them from cluttering up - but a lot smaller than the forces of the "springs".
- a linear force that pulls the connection points towards the place where the end of the "springs end" should be and is proportional to the difference between the "should-be" position and the current position. This force reaches 0 if the point reaches the location where it should be (relative to the point on the other geometry it's connected to with this "pseydo-spring").

Now - in my mind, this system should reach a state where all the forces are either 0 (because the points are where the springs want them to be) or cancel each others out (because... uhm... well... that's the way it works in my head? xD). But that's not what's happening - instead some objects keep on rotating or even accelerating. Now the questions are:
- What am I missing?
- Does that look "springy" to you?
- Can someone with a better visual / physics thinking than me see what's happening to the rotating bodies? Looks to me like it might simply be related to the way I connected the objects... but if there's some factor that makes the connections / the equilibrium impossible then I fail to wrap my brain around it ATM.



( Btw: Still searching for an "engine / library / tools" that's better suited for things like this / has one dimension less to worry about... and stuff. Should have made 2 seperate topics I guess :/ well, too late now^^)
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

CopyableCougar4 (19 views)
2014-08-22 19:31:30

atombrot (30 views)
2014-08-19 09:29:53

Tekkerue (25 views)
2014-08-16 06:45:27

Tekkerue (23 views)
2014-08-16 06:22:17

Tekkerue (15 views)
2014-08-16 06:20:21

Tekkerue (24 views)
2014-08-16 06:12:11

Rayexar (63 views)
2014-08-11 02:49:23

BurntPizza (39 views)
2014-08-09 21:09:32

BurntPizza (31 views)
2014-08-08 02:01:56

Norakomi (38 views)
2014-08-06 19:49:38
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!