Archived

This topic is now archived and is closed to further replies.

MindWipe

Need an algorithm for a simple problem!!

Recommended Posts

I need some kinda algorithm for this problem. I have x1 and x2 and between them is a rope. Look at this picture to give you a better idea: I have tried to solve it by subtracting an acceleration in the beginning and end like this: ..... . . . . . . . . . . . ..... and then lowering it in the same way, but I haven't succeeded. I just need a for-loop or something that would first lower the points. Let's say we have 50
  
for(i=0;i<50;i++)
{
point[i].x = ?????
point[i].y = ?????
}

And I can't make it like:
k=20;
point[1].y+=k;
k--;
point[2].y+=point[1].y+k;
k--;
point[3].y+=point[2].y+k;
  
because then there will be less points in the beginning and there will be holes between the "balls" that the rope is made of(fig. 4). How would you do it. Pleease help, it has been bothering me for days /MindWipe "If it doesn't fit, force it; if it breaks, it needed replacement anyway." Edited by - MindWipe on August 10, 2001 10:18:44 AM

Share this post


Link to post
Share on other sites
monkey8751> Thanks for the info. But it would be a bit too hard to use. And I don''t think it has the solution for my problem. it''s more on how do create a ninjarope

diego_rodriguez> How do I use that in reality? Where''s the x1, x2, y?


Anyone know an easy solution?


"If it doesn''t fit, force it; if it breaks, it needed replacement anyway."

Share this post


Link to post
Share on other sites
Hi,

I would rather agree with the cosh. I would try to use
the cosinus (or in your case since the bride is hanging down: -cos), preferably with a lookup-table.

So here is ''my'' formula suggestion:

y = - MAX * cos(L*n);

where

- MAX = the ''height'' of the point right in the middle, meaning the maximum amplitude.

- L = PI / (number of points-1).

- n = the point number whose height to calculate.

Good luck

Scoop

Share this post


Link to post
Share on other sites
Thanks Scoop. Got it working.

I had to add PI/2, otherwice it started on wrong location in the period.

Thanks alot.

Still one problem. The X.
That's a real tricky one. Because when the distance between x1 and x2 gets shorter, the ropes Xs needs to be nearer eachother.

It works if I take the RopeLength-CurrentLength(between x1 & x2)/amount of points

And then do:
  
p= RopeLength-CurrentLength(between x1 & x2) / amount of points;

for(i=0;i<amountofpoints;i++)
{
point[i].x=(2.0f-p)*i; (I have 2 pixels between every point/ball)
}


but when the rope start to look like a U I need more points in the beginning and end.
So the X need to look like:

***** * * * * * * * * * * * * * * * * *****

You can see this in my image.

So my idea would make it accelerating and then deaccelerating
using:
by starting from 0 and going to:
2*RopeLength-CurrentLength(between x1 & x2) / amount of points;

But when the distance was less then half the size of the rope it went funny.

How would you do THIS?

/MindWipe


"If it doesn't fit, force it; if it breaks, it needed replacement anyway."

Edited by - MindWipe on August 10, 2001 1:53:54 PM

Share this post


Link to post
Share on other sites
Just off the top of my head

  
p = CurrentLength/RopeLength - gives the ratio of length shrinkage

for(i=0;i<numOfPoints;i++)
{
points[i].x = 2.0f*i*p;
}


2*i gives the normal length, but multiplying by p will decrease x accordingly since 0 < p < 1.

Instead of using cos + pi/2, why don''t you use sin?

Share this post


Link to post
Share on other sites
A note on using cosine and sin. Those are hefty calculations and while this was true a few years ago when cpu''s sucked, these calculations take some time to calculate. You might want to make a sine/cosine ref table in memory that has a small resolution so to increase speed but you''ll only be able to do aprox calculations. Then again aprox calcs don''t really matter in a game. You might latter on, if you do alot of these calulations, notice a speed hit. So keep this in mind.

Share this post


Link to post
Share on other sites
Thank you all. I think the problem is sloved 100%.

God save GameDev.net

/MindWipe

"If it doesn''t fit, force it; if it breaks, it needed replacement anyway."

Share this post


Link to post
Share on other sites
One method that would look real nice is called Verlet integration (search on Verlet and Hitman) which was used in the Hitman engine. There is a nice paper out there that tells you how to do it, the method is almost trivial to implement and produces quite nice physics results - and is esp good for strings.

Brad

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
quote:
Original post by Scoop

- L = PI / (number of points-1).



Just a quick thing, if the # of points is variable then make sure it''s not zero otherwise you might get a divide by zero error.

Share this post


Link to post
Share on other sites