A verlet based approach for... 3D physics?
Posted: Mon Apr 15, 2013 5:56 pm
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.
It's like in 2D but in 3D each vertex is connected by more than 2 edges.
Please help.
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;
}
}
Please help.