   My Rope Physics Demo
  Hi Everyone,This isn't really a request, like the rest of the topics on here are, instead I'm posting the code (and exe) for a rope physics demo I wrote up based on other code I found here, but if anyone sees any bugs and can make any improvements then they can post the updated code here.Note that the code is in Visual Basic 6.0 (I still love VB6 for simple code), but also note that the demo you can download via the link below off of my temporary website is incomplete and is meant for demonstration purposes only, for example the rope is a bit jumpy and doesn't work to how I would like it.http://ingame.netfirms.com/downloads/rope_demo_2006-06-18.zipp.s.If anyone knows anywhere I can upload my source code (and compiled exe for non VB6 users) that is free please let me know.   
  You can host stuff at freewebs.com for, uh, free :D.It might be nice if you could post the important parts of the code and some explanation of the maths on here, too.   ;  So you think with a name like freewebs it would be free? lolNot even I understand the math behind various code I use completely, it's something I know that works so I use it.The string physics method I'm using in my demo is this:for x = 0 to (points - 1)    vec_distance1 = point(x - 1) - point(x)    mag_distance1 = magnitude(vec_distance1)    intensity1 = (mag_distance1 - part_length) / mag_distance1vec_distance2 = point(x + 1) - point(x)    mag_distance2 = magnitude(vec_distance2)    intensity2 = (mag_distance2 - part_length) / mag_distance2computed_force = (vec_distance1 * intensity1) + (vec_distance2 * intensity2)    point(x) = point(x) + computed_forcenext xmagnitude is simply: mag = sqrt((x * x) + (y * y))part_length is how long you want each line segment to be.In my actual code I've added more stuff to those lines to prevent divide by zero errors to work with when x = 0.Some bugs with it like I mentioned is the line segments is jumpy, and when moving the first point, the others follow gracefully, but when moving any other point, it is the oppisite reaction, it can be stretched, and then it re-stretches.Also in my demo I added the ability to lock points, this will be useful if a point is for an example, attached to another object or such, like a pulley.I will explain some more things about the code that I seem to understand.The first line, "vec_distance1 = point(x - 1) - point(x)", what is going on here is that it's calculating the distanced between two points.The next line, "mag_distance1 = magnitude(vec_distance1)", is getting the magnitude (or dot product) of the distance vector we just made. This can be used for a lot of different things, like one instance I've found is calculating the speed in which a velocity vector is going, depending on your world measurements this means you can retreive the MPH of a car from this. but what we're doing is using it to determine the distance between the points in a 1-D value from 2-D.The next line, "intensity1 = (mag_distance1 - part_length) / mag_distance1" is calculating the percentage of what the length should be, well what I think that is, I'm not too postive on this.The next three lines repeat for the point after the current point, this keeps each point in check with eachother (compared to using a 'snake' style rope).The next line, "computed_force = (vec_distance1 * intensity1) + (vec_distance2 * intensity2)" to my understanding is calcuting the force based the difference between the two point's calculated new length.And finally the last line is just adding the force unto the original vector.The demo was built for 2D but can easilly be updated to add 3D properties.Also note in the demo I'm using delta time to update each point with gravity, which isn't perfect either but this is just a demo after all. lol   ;  I don't know VB6, but if you have gravity >0 shouldn't a rope that is "locked" eventually straighten out and become totally vertical?  When I lock it and gravity is >0 it usually stays at a curve...Anyways, cool demo!   ;  Locking is meant to keep a point from moving, the reason for this is if you wanted a point in the rope attached to a object, like a pulley or some solid object.For an example if you have one point locked, and you move the end point to the other side, losing the tension, from the gravity it should start to bend downwards, or if you stretch it far enough it should keep horizontal.[Edited by - digital_phantom on June 20, 2006 8:38:25 AM];Quote:Original post by digital_phantomSo you think with a name like freewebs it would be free? lolNot always... www.freecreditreport.com?;  Your 'string physics' (in fact it's more like 'chain physics'; a series of discrete links) is inherently directional, as you're updating points before calculating the force on later ones. This might be why the movement looks a bit weird. It's better to calculate all the forces in one step and then apply all the accelerations in another.   ;  Bob Janova...Step #1, Go through each point, calculate the forces and store them.Step #2, Go through each point again, apply stored forces to each point.Is this what you mean? I'm going to apply this to see how it works, I'll get back with all of you when I check it out.   ;  Well I tested it out the storing forces (via a buffer) and I cannot get it to work correctly, since the forces calculation code is not able to get the accurate point positions, it jumps the points all over the screen, which I cannot figure why. I will continue working on this.   ;  Yes, that's what I meant. It can get tricky if you have other things attached to the ropes (working out the forces can get tricky) but that's the basic idea.   