Advertisement

Springs!!!

Started by October 25, 2000 05:50 PM
2 comments, last by Pete Bassett 24 years ago
Hi all. I''m knocking together a spring simulation app in my spare time using OpenGL for the graphics. The graphics part is fine, thanks mainly th HeNes tutorials. However, I''m having a little trouble getting the springs to work in a believeable way. The basic problem is that the blob of gelly that the springs make is made up of particles. Each particle has its own velocity, mass ect. Two particles are connected by a spring and this does all the calculations for adjusting the velocities of the two particles that it connects. Ok so far. But spring damping is getting me down. In my app, I have a "Bar" of springs bounces of a ball and lands on the "ground". The problem is that the spring damping acts on the velocity of the particles and this is also the particles velocity through the air when it is falling, bouncing, rebounding etc. It looks as if the bar if falling though tar. Needless to say, this is not what I really want. Does anyone knoe a way of damping the movement of the two particles without affecting the velocity that should be there. Here is the code for the spring void CSpring::Update(float fTime) { vec3_t vPar1 = m_pStart->GetPos(); vec3_t vPar2 = m_pEnd->GetPos(); vec3_t vBond = vPar2 - vPar1; // The magnitude of this extension float fMagnitude = vBond.Length(); // get the eztension beyond the normal length float fExtension = fMagnitude - m_fNaturalLength; float ForceMag = (fExtension/fMagnitude) * STIFFNESS; vec3_t ForceVect = (vBond * (ForceMag/fMagnitude)); m_pStart->GetVel().Add(ForceVect); m_pEnd->GetVel().Subtract(ForceVect); m_pStart->SetVel(m_pStart->GetVel() * DAMPING); m_pEnd->SetVel(m_pEnd->GetVel() * DAMPING); } As you can see. The DAMPING (Defined as 0.99f is applied to the velocity of the particles directly. Dont know what to do!!! Thanks for any help you could give me on this. Pete
I am not quite sure of your problem but I can tell you that you must do this...

(I will try not to use assembly language because no one understands it.)

From what I undersand from your post is that you have a ball bouncing off of a box of springs(kinda like a mattress). Now, in the animation sequence of things you have to do this...

First you must take the velocity of the ball and sine it to make a smooth motion. Now when you detect the collision of the ball to the springs. You want to do annother sine to it to slow down the ball and depress the spring.(This all happens very fast.) I forgot something though... When the ball hits the springs you must save the velocity of the ball.

(this is the bounce algorithm I use for my engine. I havn''t got it working really well yet but your welcome to use it.)

Example:
velocity = 10 (kinda fast)
gravity = 5 (normal gravity)
mass = 20 (This is a bowling ball)
Mass properties = less then 10 is a positve height bounce on the ball, 10 is 100% efficiant ball bounce and 20 is really heavy)

2nd bounce velocity = (velocity/mass)*gravity
(Since it is a spring you might want to multiply the mass times the power of the spring)

After the ball bounces you must get the x/y/z velocities and such but that is annother topic. I couldn''t understand your C++ source because I program in ASM. Sorry if I typed this up for nothing. If I didn''t answer your question I am sorry. If this doesn''t work don''t blame me... I am only in Algebra 1 in school

Good Luck,

Kenny
Advertisement
Hi thanks for posting but its not exactly what I was after.

Ok, Heres the scene. Resting on the floor is an imovable beach ball. Somewhere above it as a block of particles interconnected with springs. The block falls due to gravity and bounces off the block in a realistic manner. However, its all slow and the reason is the code I posted above.

The DAMPING constant with is about 0.999 is always robing the particles of their velocity and so bringing the block of springs to rest. But it is also slowing the movement of the block as a whole through the "air". I.e. Sideways and down as it is falling.

The physics I hav at the moment are not correct because I do not take into account the particles mass or elapsed time when calculateing their final velocities. However it does still produce a nice result so all I want to fix it the "Movement through the air" problem.

Thanks

Pete
I have a well knowledge of springs because I work on cloth simulation, so I can tell you that you that there are two ways to do dumping.
First you have to calculate the total force applying on the particle : m*G - k*dX

If you want some dumping effect add one of this term in the force : -c*V or -c*V^2

That''s how dumping is usually calculated.
But you say that you use a value of 0.99 for dumping !!! It''s extremely hight, you should try 0.1 or 0.2, in realty it''s never highter.

If you still have problems with springs contact me, I''ll tell you more about it. You should look at my cloth simylation on

My Web Page

This topic is closed to new replies.

Advertisement