#pragma once #include "spheres.hpp" #include void draw(const Sphere<2>& s, std::array color = {0, 0, 0}, unsigned nPoints = 20) { glColor3d(color[0], color[1], color[2]); glBegin(GL_POLYGON); for (unsigned i = 0; i < nPoints; i++) { glVertex2d(s.x(0) + s.r * cos(2 * i * M_PI / nPoints), s.x(1) + s.r * sin(2 * i * M_PI / nPoints)); } glEnd(); } void initializeAnimation(int argc, char** argv, unsigned window_size = 1000) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutInitWindowSize(window_size, window_size); glutCreateWindow("spheres"); glClearColor(0.0, 0.0, 0.0, 0.0); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0, 1.0, 0, 1.0); glClearColor(1.0f, 1.0f, 1.0f, 1.0f); } template T> void draw(const Model<2, T>& m) { glClear(GL_COLOR_BUFFER_BIT); for (const Sphere<2>& p : m.particles) { std::array color = {0, 0, 0}; if (p.m) { color = {0, 1, 0}; } Sphere<2> pTmp = p; pTmp.x = m.orientation.inverse().act(p.x); draw(pTmp, color); if (pTmp.intersectsBoundary()) { for (Vector<2> Δy : {(Vector<2>){1,0}, {-1,0}, {0,1}, {0,-1}, {-1,1}, {1,1}, {1,-1},{-1,-1}}) { draw({(Vector<2>)pTmp.x + Δy, p.r}, color); } } } glFlush(); }