Help with rope physics and new demo

Started by
9 comments, last by digital_phantom 17 years, 10 months ago
For anyone who has looked at my previous topic involving my rope physics demo: http://www.gamedev.net/community/forums/topic.asp?topic_id=399006 I have updated with a new, except for it's got more bugs in it. All included readme files tell of the bugs. Here is the new demo: http://ingame.netfirms.com/downloads/rope_demo_2006-06-25.zip To recap, the demo has been coded in VB for I didn't had to waste a lot of time making a GUI and such. This program demonstrates using simple rope physics. My new version includes what I like to call atoms, but their really just seperate physic objects for the rope can attach points together. All bugs come together to one little problem I have with the demo, the actual physics part. Here is the part of the source code which I'm having problems, this is for the actual rope: Public Sub Continue() ' If no points was added then ... exit this procedure. If i_Points.Count = 0 Then Exit Sub ' Calculate the maximum length of a connection line. Dim fPartLength As Single fPartLength = (i_MaxLength / i_Points.Count) Dim vecDistance(0 To 1) As POINTF Dim fDistance(0 To 1) As Single Dim fIntensity(0 To 1) As Single Dim computed_force As POINTF Dim oldX As Single, oldY As Single ' For statistics purposes. i_CurLength = 0# ' Go through each point ... Dim dwIndex As Long For dwIndex = 0 To (i_Points.Count - 1) ' ... Get the distance between this point and the previous ... vecDistance(0) = GetPointsDistance2D(dwIndex - 1, dwIndex) fDistance(0) = PointFMagnitude(vecDistance(0)) If fDistance(0) = 0 Then fIntensity(0) = 0# Else fIntensity(0) = (fDistance(0) - fPartLength) / fDistance(0) End If ' ... Get the distance between this point and the next ... vecDistance(1) = GetPointsDistance2D(dwIndex + 1, dwIndex) fDistance(1) = PointFMagnitude(vecDistance(1)) If fDistance(1) = 0 Then fIntensity(1) = 0# Else fIntensity(1) = (fDistance(1) - fPartLength) / fDistance(1) End If computed_force = PointFMultiplyValue(vecDistance(0), fIntensity(0)) computed_force = PointFAdd(computed_force, PointFMultiplyValue(vecDistance(1), fIntensity(1))) ' ... Store the last position to the current poisition ... Call i_Points.Item(dwIndex).Object.GetPosition(oldX, oldY) i_Points.Item(dwIndex).LastPosition = PointFSet(oldX, oldY) ' ... Calculate the new position with the calculated forces ... Call i_Points.Item(dwIndex).Object.SetPosition(oldX + computed_force.X, oldY + computed_force.Y) ' ... STATISTICS ONLY: Store the length into the curent length. i_CurLength = (i_CurLength + fDistance(0)) Next dwIndex End Sub Like I said the problem is the physics part, if you notice I'm adding the forces to the actual object position instead of the object's velocity. When I try to apply the forces unto the velocity everything becomes jumpy, and I've spent more then a days worth of time to fix this and it is bugging me If anyone knows how to fix this problem and/or has a solution then please let me know, It be very appreciated. p.s. Sorry I didn't include all the code in here, there is actually too much to post. lol
Advertisement
no one can help any ?
Not really - except how can you expect it to work when adding force to position? Or even to velocity for that matter? You should be using F = m*a so the relationship between force and position changes will involve force, velocity, mass and your timestep.

You should really test the low-level physics first - disable all the rope/spring stuff and just check that a particle of mass M accelerates at a rate A when you apply a force F to it (such that F = M * A) - dump the output over several updates to a text file and check it by hand with pen/paper. If you spend a little time to get the basics working absolutely reliably you'll waste a lot less of your time later on...

Btw it helps if you use html tags to mark links in your post, and put code inside a code block too.
I didn't know that I could include html tags on here because I'm use to most websites having an option to enable/disable html tags and when they don't, it usually means they don't have the ability.

So you say F = m * a, well I thought every object that acted against an object is a force, like wind, etc... so if F = m * a, then this is false, then does that mean every force is calculated unto acceleration instead of force?

And i do have most of those simple physics included, but it's on the atom object, which the code I'm using for it's physics is this:

g = gravity
F = -g * m
a = F * m
v = v + (a * timestep)
p = p + (v * timestep)
Quote:Original post by digital_phantom
So you say F = m * a, well I thought every object that acted against an object is a force, like wind, etc... so if F = m * a, then this is false, then does that mean every force is calculated unto acceleration instead of force?

And i do have most of those simple physics included, but it's on the atom object, which the code I'm using for it's physics is this:

g = gravity
F = -g * m
a = F * m
v = v + (a * timestep)
p = p + (v * timestep)


first:

a is not equal to F * m ever. a = F / m. that might be an issue to fix (unless it was a mistake typing here).

force shouldn't be considered an object. it is a push or a pull. an object can exert a force onto another object, but forces don't exist on their own. that is a theoretical/conceptual idea to take into account.

now, when calculating a force exerted on to a point i would follow the above poster's ideas -- start out with just a simple calculation program that takes an object of known mass and applies a force to it. this could be done with a simple console program that is text based only to check calculations. i have done this for the physics i have implemented and frankly, i feel that it works the best because that environment is much easier to debug and understand. so anyways, once you have a program that calculates the acceleration of a mass due to a force, change the program so that then you are calculating the velocity and displacement also.

that above is for 1D forces. next try 2D forces so that you are calculating the x and y (or z depending on how you look at it) components of the acceleration, velocity, and direction. then do the same for the third dimension.

once you have this working flawlessly in a text based program start implementing it into a visual program to make sure you have everything connected correctly (displacement data to where the object is being drawn). and then finally, there is the trick of making the rope work like a rope. good luck on that, since i really haven't put any thought into how to do that. my engineering courses don't often (or ever) cover how a rope moves. :)
Yes it was a mistype, sorry.

I have my rope working properly on the movement, it's just the whole acceleration thing I need to fix, or I should say working.

But the one major question I have is from all the examples I have seen, when a force gets applied to an object, it gets added unto the acceleration, is this correct? And if it is, then am I looking at this at the wrong angle (with calcuating forces per frame)
Original post by digital_phantom
when a force gets applied to an object, it gets added unto the acceleration, is this correct?</quote>

No. F = m*a. So the acceleration of an (point) object is equal to the sum of all the forces acting upon it, divided by the mass.

Quote: And if it is, then am I looking at this at the wrong angle (with calcuating forces per frame)


If the force changes with time then you need to calculate it each update. If it's constant (like gravity), you don't. But still, you need to "apply" it each physics update:

Force affects acceleration through F = m*a - so if you know F you calculate a.

Acceleration affects velocity - each timestep use Euler integration (or something more sophisticated when you're ready): change in velocity = acceleration * dt.

Velocity affects position - each timestep use Euler integration (blah blah): change in position = velocity * dt.



What just doesn't make since to me is the whole calculation of the force and acceleration vectors.

F = m * a
a = F / m

To calculate the force you need the acceleration, to calculate the acceleration you need the force... this seems like it won't work unless something is already pre-calculated because... by looking at the two you can see that mass is being canceled out, and then what's left is F = a and a = F, which is the same.
So I looked more into this and I went to the wikipedia and it had a set of formulas, but the most simple are:

Acceleration is defined as "the rate of change of velocity of an object with respect of time"
a = dv / dt (v = velocity, t = time, d = Leibniz's notation for differentiation.)

and then same as we mentioned, "F = m * a" which goes after acceleration is calculated.

and then velocity is calculated as "v = d / t" (d = distance)
okay so to get force you use F = m * a
thats if you want to get the force from the acceleration right?
how do you calculate the initial force to be used on acceleration then?
i'm not sure i understand what you are asking.

you can either supply a known force to the point/object and then calculate the acceleration because the force and mass are known.

or you can have a predetermined acceleration applied and then calculate the force that is causing it

or you can do some calculus to derive the acceleration equation from a displacement or velocity equation:
a = (dv/dt) = (d2s/dt2)
however, this may be more work than necessary.

or you can use conservation of energy at an initial point (where height and velocity are known) and a final point (where either final height or final velocity are known and the other can be solved for). then with this final velocity you can use conservation of momentum to find the transfered velocity from the moving object to another. then use impulse-momentum to determine the impulse that occurrs from the first object onto the other (impulse = F * t). however, then that doesn't tell you how long the force is acting which, unfortunately, right now i can't seem to figure out. you might consider that it s a perfectly elastic collision and then your timestep could be how long the force acts, but this is risky. however, i guess if you are only after velocity then you don't really need the impulse even, just the final velocity because once the impact is over the force is no longer acting and causing no further acceleration. but, this option may just be overkill in general. :)

if i completely just went off and didn't answer your question and just further confused you, i'm very sorry it wasn't supposed to be that way. feel free to pm me and i'll try my best to explain it better if you are still confused.

This topic is closed to new replies.

Advertisement