Kiwi::Kiwi() : ObjectBase( Point3D(0.5,0.5,1.0),Velocity3D (),new KiwiRenderer(this) ) {}
/** * Create or load a particle system and simulate a number of time steps. */ int main(int argc, char *argv[]) { // Create particles and springs. particles.reserve(dimx * dimy * dimz); for (size_t z = 0; z < dimz; ++z) { for (size_t y = 0; y < dimy; ++y) { for (size_t x = 0; x < dimx; ++x) { Length3D p; p[0] = (x / float(dimx > 1 ? dimx - 1 : 1) - 0.5) * m - 1 * m;// - 6 * m; p[1] = (y / float(dimy > 1 ? dimy - 1 : 1) - 0.5) * 0.005 * m - 1.7 * m;// + 5 * m; p[2] = (z / float(dimz > 1 ? dimz - 1 : 1) - 0.5) * m; particles.push_back(Particle(mass, p, Velocity3D())); // create connections to all existing neighbors std::vector<size_t> other_xs, other_ys, other_zs; if (z > 0) other_zs.push_back(z - 1); if (y > 0) other_ys.push_back(y - 1); if (x > 0) other_xs.push_back(x - 1); other_zs.push_back(z); other_ys.push_back(y); other_xs.push_back(x); if (z + 1 < dimz) other_zs.push_back(z + 1); if (y + 1 < dimy) other_ys.push_back(y + 1); if (x + 1 < dimx) other_xs.push_back(x + 1); for (std::vector<size_t>::const_iterator oz = other_zs.begin(); oz != other_zs.end(); ++oz) { for (std::vector<size_t>::const_iterator oy = other_ys.begin(); oy != other_ys.end(); ++oy) { for (std::vector<size_t>::const_iterator ox = other_xs.begin(); ox != other_xs.end(); ++ox) { size_t idx = *oz * dimy * dimx + *oy * dimx + *ox; if (idx < particles.size() - 1) { springs.push_back(Spring(particles[idx], particles.back(), stiffness, springDamping, shrinkage)); } } } } } } } // Create obstacles. /*Number3D plane_normal; plane_normal[0] = 0.5; plane_normal[1] = 1.0; plane_normal[2] = 0.0; obstacles.push_back(new Plane(plane_normal / norm(plane_normal), -1.0 * m, bounciness, friction)); plane_normal[0] = 0.0; plane_normal[1] = 1.0; plane_normal[2] = 0.0; obstacles.push_back(new Plane(plane_normal / norm(plane_normal), -1.5 * m, bounciness, friction)); plane_normal[0] = -1.0; plane_normal[1] = 0.0; plane_normal[2] = 0.0; obstacles.push_back(new Plane(plane_normal / norm(plane_normal), -5.0 * m, bounciness, friction)); */ Number3D table_normal; table_normal[0] = 0.0; table_normal[1] = 1.0; table_normal[2] = 0.0; Length table_radius = 0.35 * m; Length3D table_origin; table_origin[0] = -1.0 * m; table_origin[1] = -2.0 * m; table_origin[2] = 0.0 * m; obstacles.push_back(new Table(table_origin, table_normal, table_radius, bounciness, friction)); table_origin[0] = -1.15 * m; table_origin[1] = -1.9 * m; obstacles.push_back(new Table(table_origin, table_normal, table_radius, bounciness, friction)); table_origin[0] = -0.85 * m; table_origin[1] = -2.1 * m; obstacles.push_back(new Table(table_origin, table_normal, table_radius, bounciness, friction)); // Create a particle system. particle_system = new MassSpringSystem(particles, springs, obstacles, particleDamping); // Create a solver. solver = new RungeKuttaSolver(particle_system); quadObj = gluNewQuadric(); glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); glutInitWindowPosition(0, 0); glutInitWindowSize(windowWidth, windowHeight); glutCreateWindow("Particle System"); glutIdleFunc(idle); glutDisplayFunc(display); glutReshapeFunc(reshape); glutMouseFunc(mouse); glutMotionFunc(motion); glutKeyboardFunc(keyboard); glEnable(GL_DEPTH_TEST); glutMainLoop(); return 0; }