Jump to content
  • Advertisement
Sign in to follow this  
Kram

How to simulate a "wobbly" rectangle

This topic is 3497 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am currently trying to figure out just how someone would implement the physics behind a "wobbly" rectangle. By wobbly, I mean sort of like jelly, where if the base of the rectangle was anchored to the ground and something pushed (or pulled) the top (free) part of the rectangle, then that force stopped, it would act like something with elastic properties, wobbling back and forth until slowly stopping. What is this type of physics called? Is there any reference material that I could read to implement this type of physics? I'm currently using JavaFX and am trying to build some cool effects. I would imagine that you would need to build a rectangle out of many many small lines that know about its neighboring lines, and they each get manipulate based on external forces and the pull of their neighboring forces. Is this sort of correct? Thanks for any help that you can give me here. Mark

Share this post


Link to post
Share on other sites
Advertisement
I did this once (and called it "wobbly", too :D) by iterating over all vertices of an arbitrary mesh, took it's position as the input to some function, and used the newly created vertices for drawing the mesh. I did so by actually having two meshes, one being the original, the other being for rendering.

Share this post


Link to post
Share on other sites
I think spring physics does what you want to do.

Create a rectangle of springs, and connect the diagonals with springs too. This should simulate something like jelly (take a lot of fiddling though to get right)

Share this post


Link to post
Share on other sites
Thanks everyone for the info and links so far. It looks like soft body dynamics is the way to go for me, there is a great .NET library that I found that demonstrates it well, http://www.alecrivers.com/fastlsm/ is the link.

Although, I would really like to read some 'step-by-step' guides as to how to implement this type of physics, but I cannot seem to find any just yet. Obviously I will keep looking, but if anyone knows of any specifically, then that would be awesome!

Thanks again
Mark

Share this post


Link to post
Share on other sites
Hi there,

Assuming you know how to implement a spring simulation, this is how it can be done, super compact version:

-create 4 point masses, each having a force, acceleration, velocity, and position vector.

-apply 4 springs between the corners of the box.

do

-get spring length and apply (damped) spring force.

-get the area of the box (there are plenty of simple 2d polygon area algorithms around).

-calculate the scalar pressure of the box, like this: pressure = constant*(area-rest area). (this is just Hooke's law of elasticity in another form)

-apply pressure force (vector) to each spring, like this: pressure vector = pressure * spring length * normalised normal vector.

-accelerate & integrate

loop

If this doesn't make too much sense I can post a simple BASIC code sample for you. Oh, and applying angular springs is good too.

Cheers,
Mike

Share this post


Link to post
Share on other sites
Hi Mike, thanks a lot for the help, i'll take a look at implementing this over the next few days. If I have any troubles, I will be sure to post more and more questions about it, I don't really have any academic background in physics, but I have been toying with it for a small while now and am getting better.

Thanks again.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!