A verlet based approach for... 3D physics?

Please don't post Bullet support questions here, use the above forums instead.
Post Reply
ConvexHull
Posts: 9
Joined: Sun Mar 10, 2013 5:03 pm

A verlet based approach for... 3D physics?

Post by ConvexHull »

Hi guys,
I've readed recently http://www.gamedev.net/page/resources/_ ... sics-r2714
article and tried to apply it to 3D.
The main idea is to represent each vertex of rigid body with 3D Position, 3D PrevPosition, and 3D Accell and connect those vertices with Edge structures (Vertex *V1, Vertex *V2, and EdgeLenght).
Then the vertices are moved (with verlet motion equation) and edges are used to keep vertices together.
I've recoded everything in three dimensions but it seems that edges code doesnt work for by cube (8 vertices, 18 edges).
Any ideas what's causing this problem?

Here's the code, I've just changed it to 3D.

Code: Select all

void Physics::UpdateEdges() {
  for( int I = 0; I < EdgeCount; I++ ) {
    Edge& E = *Edges[ I ];

    //Calculate the vector mentioned above
    Vec2 V1V2 = E.V2->Position - E.V1->Position; 

    //Calculate the current distance
    float V1V2Length = V1V2.Length(); 
    
    //Calculate the difference from the original length
    float Diff       = V1V2Length - E.OriginalLength; 
    
    V1V2.Normalize();

    //Push both vertices apart by half of the difference respectively 
    //so the distance between them equals the original length
    E.V1->Position += V1V2*Diff*0.5f; 
    E.V2->Position -= V1V2*Diff*0.5f;
  }
}
It's like in 2D but in 3D each vertex is connected by more than 2 edges.
Please help.
bone
Posts: 231
Joined: Tue Feb 20, 2007 4:56 pm

Re: A verlet based approach for... 3D physics?

Post by bone »

I can't figure out where you're coming up with 18 edges. If every vert in the cube is converted to every other, it should be 28, no? What's not working for you?
User avatar
Dennis
Posts: 12
Joined: Sat Jun 23, 2007 9:13 pm
Location: San Francisco
Contact:

Re: A verlet based approach for... 3D physics?

Post by Dennis »

Without knowing that much detail, I'm pretty sure Rigs of Rods uses a 3D particle approach for "rigid" body physics, not sure if it's verlet though: http://www.rigsofrods.com
ConvexHull
Posts: 9
Joined: Sun Mar 10, 2013 5:03 pm

Re: A verlet based approach for... 3D physics?

Post by ConvexHull »

bone wrote:I can't figure out where you're coming up with 18 edges. If every vert in the cube is converted to every other, it should be 28, no? What's not working for you?
6 cube sides, 8 vertices, 6 quads, each quad is two triangles (so 12 tris)
down side 4 + up side 4 + up-down connection 4 + center edge for each of 6 sides (because each side is a quad and a quad is two triangles)
4 + 4 + 4 + 6 = 18

I need some kind of rigid-spring solver?
bone
Posts: 231
Joined: Tue Feb 20, 2007 4:56 pm

Re: A verlet based approach for... 3D physics?

Post by bone »

My previous post should have said "connected" not "converted". Anyway ...

Your original post said: "it seems that edges code doesnt work for by cube." I'm asking what isn't working. Does the cube collapse? Blow up? In other words, in what way does it not work? I'm guessing it collapses.

Also, I don't think simply taking a 2-D quad and applying it 6 times for a cube is going to work (and I'm still not quite understanding your description of how you count them, sorry). You need something to preserve the volume in the middle of the cube. In particular, each vert should probably have a connection to its opposite vert - the one furthest away. In other words, four (4) edges that cross right through the middle of the cube.

I'd probably also include both diagonals of each face (so 2x6=12). Finally, of course the normal 12 cube edges. 4+12+12=28.
ConvexHull
Posts: 9
Joined: Sun Mar 10, 2013 5:03 pm

Re: A verlet based approach for... 3D physics?

Post by ConvexHull »

You were right, I had to add more edges (more than box triangles geometry had).
Now the question is how to generate contact points between boxes defined by 8 vertices each? They are not axis aligned....
I know how to implement GJK and SAT but I dont know how to get separate contact point for EACH vertex.
Any ideas?
bone
Posts: 231
Joined: Tue Feb 20, 2007 4:56 pm

Re: A verlet based approach for... 3D physics?

Post by bone »

Indeed, that's going to be more difficult. Particularly the edge/edge case (when an edge of one cube touches the edge of another cube, yet no verts have penetrated the faces of the other cube). I believe some people just skip that case altogether.
Post Reply