模拟一根可以自由摆动的绳子,介绍如何利用弹簧-质量-阻尼系统模拟一个弹性对象。在该例子中,绳子的一段固定,另一端可自由摆动。绳子所受外力仅为重力。
RopeSimulation* ropeSimulation = new RopeSimulation(
80, // 80 Particles (Masses)
0.05f, // Each Particle Has A Weight Of 50 Grams
500.0f, // springConstant In The Rope
0.05f, // Normal Length Of Springs In The Rope
0.2f, // Spring Inner Friction Constant
Vector3D(0, -9.81f, 0)); // Gravitational Acceleration
int InitGL(GLvoid) // All Setup For OpenGL Goes Here
{
ropeSimulation->getMass(ropeSimulation->numOfMasses - 1)->vel.z = 10.0f;
glClearColor(0.0f, 0.0f, 0.0f, 0.5f); // Black Background
glClearDepth(1.0f); // Depth Buffer Setup
glShadeModel(GL_SMOOTH); // Select Smooth Shading
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Set Perspective Calculations To Most Accurate
return true; // Initialization Went OK
}
效果



