Ragdoll Physics

Sage
Posts: 1,066
Joined: 2004.07
Post: #31
p.s.
Jake, is there any chance that you can (or have) made an ObjC or C++ version of your demo? It looks very cool but I can't read METAL.
Quote this message in a reply
Member
Posts: 509
Joined: 2002.05
Post: #32
Nick Wrote:p.s.
Jake, is there any chance that you can (or have) made an ObjC or C++ version of your demo? It looks very cool but I can't read METAL.

I don't think there is a need for me to make a new version of it because it was only to teach myself verlet. What don't you understand, all of the math is the same, and most of the graphics should be ill-relevant and self explanatory

I might eventually make a new 3D demo to learn C++, but I am very busy now with my moto game
Quote this message in a reply
Member
Posts: 749
Joined: 2003.01
Post: #33
are you sure you can write

oldPos[i] = circlePos[i]; ?

(I dont know in objective-c or whatever you're using, in blitzmax you can't do this stuff, o/w it just passes a pointer to the object)

maybe you better do

oldPos.x[i] = circlePos.x[i];
oldPos.y[i] = circlePos.y[i];
oldPos.z[i] = circlePos.z[i];

©h€ck øut µy stuƒƒ åt ragdollsoft.com
New game in development Rubber Ninjas - Mac Games Downloads
Quote this message in a reply
Sage
Posts: 1,066
Joined: 2004.07
Post: #34
That might be causing a problem. I'll check it out.

on a side note, is blitzmax a good cross platform language that's fairly easy to use (window creation and input and everything)? I'm trying to find a way to make simple games without using SDL that I can easily port to Windows.
Quote this message in a reply
Sage
Posts: 1,066
Joined: 2004.07
Post: #35
That didn't really change anything. I am utterly confused. I think I'm going to just take a few days and work on separate particles without linking them so that I can make sure that all of that works just fine. Maybe I'll do a few explosions. Then I'll revisit this. I cannot, for the life of me, figure out why this is behaving as it is. From all the previous posts, I'm doing everything I need to be. I wanted to think it was when I was setting the velocities by using the current point - the old point but I know that taking that out doesn't help at all. I'm just lost. Hopefully I'll get some cool explosion done so I can feel as though I can figure something out.
Quote this message in a reply
Member
Posts: 749
Joined: 2003.01
Post: #36
I never tried C++ or obj C, I only know some C (and I don't like it at all), I learned what I know about object oriented programming with blitzmax, and I like it a lot, though I dont have many reference points.

I can only tell you that compared to C it's very, very good :-)

It's also fairly extensible, since you can put in c-c++ code and libraries, call external API etc... so if you want you can have direct opengl access.

Also it's compiled and pretty fast

It has a built in 2d module for that wraps opengl and is very easy to work with input and the like.

I'm certainly not encouraging you to leave the mainstream languages, they're more "serious", and if you use basic you will always be considered a noob, but as far as productivity goes, it's cool.

©h€ck øut µy stuƒƒ åt ragdollsoft.com
New game in development Rubber Ninjas - Mac Games Downloads
Quote this message in a reply
Member
Posts: 749
Joined: 2003.01
Post: #37
argh, I'm ********.

I didn't notice that you called the shifting algorithm only once... you have to iterate that...

so try this:

Code:
(void)updateCircles
{
    int i,j;
    SEVector    shift[NUM_CIRCLES];
    SEVector    tempVector;
    SEVector    oldPos[NUM_CIRCLES];
    float        tempFloat,tempFloat2;
    
    //apply gravity to all of the circles except one
    for(i = 0; i < NUM_CIRCLES - 1; i++)
        circleVel[i].y -= GRAVITY;
    
    //add the velocities to the circles
    for(i = 0; i < NUM_CIRCLES - 1; i++)
    {
        oldPos[i] = circlePos[i];
        circlePos[i].x += circleVel[i].x;
        circlePos[i].y += circleVel[i].y;
        circlePos[i].z += circleVel[i].z ;
    }
    
        for (j= 0; j < 40; j++)
        {

    //figure out shifts for circles
    for(i = 0; i < NUM_CIRCLES - 1; i++)
    {
        tempFloat = sqrt(pow(circlePos[i+1].x - circlePos[i].x,2) +
                         pow(circlePos[i+1].y - circlePos[i].y,2) +
                         pow(circlePos[i+1].z - circlePos[i].z,2));
        
        shift[i].x += ((tempFloat - (CIRCLE_RADIUS * 2)) / 4) * ((circlePos[i+1].x - circlePos[i].x) / tempFloat);
        shift[i].y += ((tempFloat - (CIRCLE_RADIUS * 2)) / 4) * ((circlePos[i+1].y - circlePos[i].y) / tempFloat);
        shift[i].z += ((tempFloat - (CIRCLE_RADIUS * 2)) / 4) * ((circlePos[i+1].z - circlePos[i].z) / tempFloat);
        
        shift[i+1].x = -shift[i].x;
        shift[i+1].y = -shift[i].y;
        shift[i+1].z = -shift[i].z;
    }
    
    //apply the shifts
    for(i = 0; i < NUM_CIRCLES - 1; i++)
    {
        circlePos[i].x += shift[i].x;
        circlePos[i].y += shift[i].y;
        circlePos[i].z += shift[i].z;
    }

        }
    
    //reset the velocities based on actual movement
    for(i = 0; i < NUM_CIRCLES - 1; i++)
    {
        circleVel[i].x = circlePos[i].x - oldPos[i].x;
        circleVel[i].y = circlePos[i].y - oldPos[i].y;
        circleVel[i].z = circlePos[i].z - oldPos[i].z;
    }
}

and be sure that the "oldPos[i] = circlePos[i];" works

©h€ck øut µy stuƒƒ åt ragdollsoft.com
New game in development Rubber Ninjas - Mac Games Downloads
Quote this message in a reply
Sage
Posts: 1,066
Joined: 2004.07
Post: #38
First of all, why iterate it 40 times?

Secondly, that worked a bit better meaning I can see the rope behaving like rope, but it just coils up into a ball in the center of the screen.
Quote this message in a reply
Member
Posts: 749
Joined: 2003.01
Post: #39
You can put less iterations depending on the number of balls

how can it stay in the center of the screen if there is gravity? try equating the position of one ball to the mouse position on screen to drag the rope around

©h€ck øut µy stuƒƒ åt ragdollsoft.com
New game in development Rubber Ninjas - Mac Games Downloads
Quote this message in a reply
Sage
Posts: 1,066
Joined: 2004.07
Post: #40
Here are some screens (in order) of what's going on. Edit: I fixed the moving problem. The anchor point stays where it should now but I still get all the circles bunching up like in the pictures.
[Image: Picture 1.jpg]
[Image: Picture 2.jpg]
[Image: Picture 3.jpg]
Quote this message in a reply
Member
Posts: 749
Joined: 2003.01
Post: #41
hmm... when you do the shifts for the circles you do

Code:
//figure out shifts for circles
for(i = 0; i < NUM_CIRCLES - 1; i++)
{
something[i+1]
}

which brings you to something[numcircles], which is out of bounds:

it should be

Code:
//figure out shifts for circles
for(i = 0; i < NUM_CIRCLES - 2; i++)
{
stuff
}

I dont know if this is it, there may be other errors I didn't spot. Sorry, it looks as trying to help you without xcode by the hand is hopeless, I give up Sad

©h€ck øut µy stuƒƒ åt ragdollsoft.com
New game in development Rubber Ninjas - Mac Games Downloads
Quote this message in a reply
Sage
Posts: 1,066
Joined: 2004.07
Post: #42
No it wouldn't be out of bounds. The statement is i < NUM_CIRCLES - 1 so the highest i will be is NUM_CIRCLES - 2 which, if you add one, is something[NUM_CIRCLES - 1].

I've tried a bunch of things but have gotten nowhere. Let me know if you give it a try in Xcode and get it to work right.
Quote this message in a reply
Member
Posts: 749
Joined: 2003.01
Post: #43
ok, but then you are missing one ball when you do the other loops: the fact is that in the shift loops you refer to i+1, so your loop should have one iteration less than the other ones. So try putting in the other loops (all excep the shift one)

for(i = 0; i < NUM_CIRCLES; i++) instead of for(i = 0; i < NUM_CIRCLES - 1; i++)

©h€ck øut µy stuƒƒ åt ragdollsoft.com
New game in development Rubber Ninjas - Mac Games Downloads
Quote this message in a reply
Sage
Posts: 1,066
Joined: 2004.07
Post: #44
Unfortunately, that didn't help at all. I am thankful that you don't seem to give up on me. I'm not sure what the problem could be. You can download the source here plus I'll post relevent code below. I hope somebody can help me spot the error. You may notice that I removed the Z coordinate simply because it was unneccesary (I'm working in 2D) and it did nothing to help or harm the simulation.
Code:
- (void)updateCircles
{    
    int i,j;
    SEVector    shift[NUM_CIRCLES];
    SEVector    tempVector;
    SEVector    oldPos[NUM_CIRCLES];
    float        tempFloat,tempFloat2;
    
    //add the velocities to the circles
    for(i = 0; i < NUM_CIRCLES - 2; i++)
    {
        oldPos[i] = circlePos[i];
        circlePos[i].x += circleVel[i].x;
        circlePos[i].y += circleVel[i].y;
    }
    
    for (j= 0; j < 40; j++)
    {
        
        //figure out shifts for circles
        for(i = 0; i < NUM_CIRCLES - 1; i++)
        {
            tempFloat = sqrt(pow(circlePos[i+1].x - circlePos[i].x,2) +
                             pow(circlePos[i+1].y - circlePos[i].y,2));
            
            shift[i].x += ((tempFloat - (CIRCLE_RADIUS * 2)) / 4) *
                ((circlePos[i+1].x - circlePos[i].x) / tempFloat);
            shift[i].y += ((tempFloat - (CIRCLE_RADIUS * 2)) / 4) *
                ((circlePos[i+1].y - circlePos[i].y) / tempFloat);
            
            shift[i+1].x = -shift[i].x;
            shift[i+1].y = -shift[i].y;
        }
        
        //apply the shifts
        for(i = 0; i < NUM_CIRCLES - 2; i++)
        {
            circlePos[i].x += shift[i].x;
            circlePos[i].y += shift[i].y;
        }
        
    }
    
    //reset the velocities based on actual movement
    for(i = 0; i < NUM_CIRCLES; i++)
    {
        circleVel[i].x = (circlePos[i].x - oldPos[i].x);
        circleVel[i].y = (circlePos[i].y - oldPos[i].y - GRAVITY);
    }
}
Quote this message in a reply
Member
Posts: 749
Joined: 2003.01
Post: #45
argh...

I meant this

Code:
- (void)updateCircles
{    
    int i,j;
    SEVector    shift[NUM_CIRCLES];
    SEVector    tempVector;
    SEVector    oldPos[NUM_CIRCLES];
    float        tempFloat,tempFloat2;
    
    //add the velocities to the circles
    for(i = 0; i < NUM_CIRCLES; i++)
    {
        oldPos[i] = circlePos[i];
        circlePos[i].x += circleVel[i].x;
        circlePos[i].y += circleVel[i].y;
    }
    
    for (j= 0; j < 40; j++)
    {
        
        //figure out shifts for circles
        for(i = 0; i < NUM_CIRCLES - 1; i++)
        {
            tempFloat = sqrt(pow(circlePos[i+1].x - circlePos[i].x,2) +
                             pow(circlePos[i+1].y - circlePos[i].y,2));
            
            shift[i].x += ((tempFloat - (CIRCLE_RADIUS * 2)) / 4) *
                ((circlePos[i+1].x - circlePos[i].x) / tempFloat);
            shift[i].y += ((tempFloat - (CIRCLE_RADIUS * 2)) / 4) *
                ((circlePos[i+1].y - circlePos[i].y) / tempFloat);
            
            shift[i+1].x = -shift[i].x;
            shift[i+1].y = -shift[i].y;
        }
        
        //apply the shifts
        for(i = 0; i < NUM_CIRCLES; i++)
        {
            circlePos[i].x += shift[i].x;
            circlePos[i].y += shift[i].y;
        }
        
    }
    
    //reset the velocities based on actual movement
    for(i = 0; i < NUM_CIRCLES; i++)
    {
        circleVel[i].x = (circlePos[i].x - oldPos[i].x);
        circleVel[i].y = (circlePos[i].y - oldPos[i].y - GRAVITY);
    }
}

©h€ck øut µy stuƒƒ åt ragdollsoft.com
New game in development Rubber Ninjas - Mac Games Downloads
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Ragdoll Physics merrill541 1 2,518 Feb 5, 2009 09:09 AM
Last Post: JustinFic
  Ragdoll Physic's: (For GML).. Master_Computer 0 2,376 Jan 27, 2008 11:55 AM
Last Post: Master_Computer
  Bullet Physics Library / COLLADA physics viewer erwincoumans 14 12,736 Aug 12, 2006 12:59 AM
Last Post: Fenris
  Ragdoll Physics Duane 3 3,969 Jul 7, 2005 09:55 AM
Last Post: Duane
  Ragdoll and cloth physics Skorche 28 13,090 Jun 10, 2003 03:12 PM
Last Post: Fenris