Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Rigid Body and Cloth Physics
Index -> Programming, Turing -> Turing Submissions
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
zero-impact




PostPosted: Fri May 22, 2009 6:46 pm   Post subject: Rigid Body and Cloth Physics

This is a system based off of verlet integration.
Simulates cloth and rigid bodys without collision detection so far.
Based off of http://www.teknikus.dk/tj/gdc2001.htm.

Run clothsystem.t to start.
Tell me what you think Very Happy

P.S. I'm not sure how I should go about collision detection. I've heard separating axis theorem http://en.wikipedia.org/wiki/Separating_hyperplane_theorem, any other ideas?



ClothSystem Output.png
 Description:
 Filesize:  8.27 KB
 Viewed:  5171 Time(s)

ClothSystem Output.png



Verlet.zip
 Description:

Download
 Filename:  Verlet.zip
 Filesize:  5.16 KB
 Downloaded:  227 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
Geniis




PostPosted: Fri May 22, 2009 10:02 pm   Post subject: Re: Rigid Body and Cloth Physics

Thats pretty sweet. The cloth is pretty realistic. Good job.
A.J




PostPosted: Sat May 23, 2009 10:51 am   Post subject: RE:Rigid Body and Cloth Physics

Very Impressive. I like the cloth. You used verlet integration very effectively.
zero-impact




PostPosted: Sat May 23, 2009 4:08 pm   Post subject: RE:Rigid Body and Cloth Physics

Thanks A.J.
corriep




PostPosted: Sat May 23, 2009 9:02 pm   Post subject: RE:Rigid Body and Cloth Physics

Your gonna have to teach me rigid body dynamics some time, I can't find a decent guide on the internet Sad

PS. Can't wait to see how it works w/ mouse and collisions!
zero-impact




PostPosted: Sat May 23, 2009 9:05 pm   Post subject: RE:Rigid Body and Cloth Physics

Corriep, my reference is included in my first post.
zero-impact




PostPosted: Sat May 23, 2009 10:58 pm   Post subject: Re: Rigid Body and Cloth Physics

[Update]

I have added constraints that allow you to connect vertices to arbitrary points. This of course allows you to interact with the shapes via the mouse.

Here is a demo with the solids on hinges and the cloth connected to your mouse position.
If you look at the comments on the main loop you can see how to try it out on different objects.

Tell me what you think Very Happy



Verlet.zip
 Description:

Download
 Filename:  Verlet.zip
 Filesize:  5.96 KB
 Downloaded:  162 Time(s)

saltpro15




PostPosted: Sun May 24, 2009 7:57 am   Post subject: RE:Rigid Body and Cloth Physics

that is so friggin cool Very Happy

time to start reading that reference!
Sponsor
Sponsor
Sponsor
sponsor
zero-impact




PostPosted: Sun May 24, 2009 8:52 am   Post subject: RE:Rigid Body and Cloth Physics

I have a few problems and I'm wondering if anyone has any idea's.
Right now my scale is effectively 1pixel == 1m and each particle has a mass of 1g. How could I change it so that the scale is more like 500pixel == 1m?

This brings me to my second problem, since the scale is so large, I have to use a relativly large timestep for it too look right (0.3s) when in reality the time between frames is 0.03s. Using such a large timestep seems to "break" cloth and especially softbodies. However if I set my timestep to 0.03 or lower they work perfectly fine and look really neat, if you want to watch it in ultra slow-mo that is.

So yea, basically if I fix the scale that will allow me to fix the timestep thing.

Sorry if that doesn't make sense at all.
CodeMonkey2000




PostPosted: Sun May 24, 2009 11:57 am   Post subject: Re: Rigid Body and Cloth Physics

You have memory leaks all over the place.

Turing:

fcn add (vec2 : ^Vector2) : ^Vector2
        var temp : ^Vector2
        new Vector2, temp
        temp -> initialize (x + vec2 -> getx, y + vec2 -> gety)
        result temp
end add


Everytime functions like add are called you allocate memory for new pointers, but old useless memory is never freed, so your program keeps using up memory. If you kept the program running for a few minutes, it will crash (or at least windows will force it to stop execution). You should go back and fix all the functions with pointers.
andrew.




PostPosted: Sun May 24, 2009 1:29 pm   Post subject: RE:Rigid Body and Cloth Physics

Pretty damn cool. Never really expected something that advanced to be done with Turing.
zero-impact




PostPosted: Sun May 24, 2009 2:45 pm   Post subject: RE:Rigid Body and Cloth Physics

Thanks a bunch CodeMonkey. I had no idea about that.
I'm not sure what you mean by fixing it with pointers though?
CodeMonkey2000




PostPosted: Sun May 24, 2009 5:18 pm   Post subject: Re: Rigid Body and Cloth Physics

I meant to say fix all the functions that return a pointer, my bad.

Let's closely analyze what's going on.

Turing:

fcn add (vec2 : ^Vector2) : ^Vector2
        var temp : ^Vector2
        new Vector2, temp
        temp -> initialize (x + vec2 -> getx, y + vec2 -> gety)
        result temp
end add


So if I do

Turing:

     foo := foo->add(bar)


What's really going on here? You initialized memory for foo. Then when you called add, add allocates more memory, and foo now points to what add allocated. The previous memory location that foo was pointing to is still there, you never freed it. To fix this you need to somehow free the previous memory foo was pointing to. This can easily be fixed if turing could do operator overloading and had , and just overloading the "=" operator. There are a few ways of fixing this.

One is to change your functions (that return a pointer) directly like so:
Turing:

     proc add (vec2 : ^Vector2)
        x=vec2->getx
        y=vec2-gety
    end add


So you instead do:
Turing:

     foo->add(bar)


Or if you don't want to change the functions:

Turing:

     var holder:^Vector2
     holder=foo->add(bar)
     free Vector2,foo
     foo=holder


I have to go now, so if there is anything you want me to clear up, let me know.
zero-impact




PostPosted: Sun May 24, 2009 6:36 pm   Post subject: RE:Rigid Body and Cloth Physics

Changing the functions wont work very well because of things like this
code:
newPos := (pos -> multiply (2) -> subtract (pos_) ->
            add (accel -> multiply (timestep * timestep)))
CodeMonkey2000




PostPosted: Sun May 24, 2009 6:39 pm   Post subject: RE:Rigid Body and Cloth Physics

Hmm, then my last example is your only choice, but it will be a pain.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 2  [ 21 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: