I went through the demo. Everything's clear, except the drawing part.
I noticed that in the function btSoftBodyHelpers::Draw, which is used to draw the soft body.
Each face is drawn seperately. No indices are being used. is there any reason for that?
Why is the following step being done while drawing:
Code: Select all
const btVector3 x[]={f.m_n[0]->m_x,f.m_n[1]->m_x,f.m_n[2]->m_x};
// here an average of the three positions of the face vertices is computed.
// why is this required?
const btVector3 c=(x[0]+x[1]+x[2])/3;
// Here some linear interpolation is being done
// whys is this required?
idraw->drawTriangle((x[0]-c)*scl+c, (x[1]-c)*scl+c, (x[2]-c)*scl+c, col, alp);
These are the steps i was planning do:
1. Init the dynamics with btSoftRigidDynamicsWorld.
2. I have my soft body being represented by a sphere geometry.
a. The sphere geometry has vertex buffer (dynamic) and index buffer (static).
b. I copy all the positions of the vertices from the vertex buffer into a btScalar array. (three btScalar for each vertex position)
c. I copy all the indices into an int array. (three int's for each face)
d. Then I call btSoftBodyHelpers::CreateFromTriMesh and get back the soft body.
3. Every loop, I lock the dynamic vertex buffer, and copy the new vertex values from btSoftBody::m_nodes.
Will this work?
Will the vertex list from the vertex buffer match the vertex list from the soft body?
Thanks