//////////////////////////////////////////////////////////////////////////////// // // Paella // Copyright (C) 2015 - Thomas FORGIONE, Emilie JALRAS, Marion LENFANT, Thierry MALON, Amandine PAILLOUX // Authors : // Thomas FORGIONE // Emilie JALRAS // Marion LENFANT // Thierry MALON // Amandine PAILLOUX // // This file is part of the project Paella // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. // // Permission is granted to anyone to use this software for any purpose, // including commercial applications, and to alter it and redistribute it freely, // subject to the following restrictions: // // 1. The origin of this software must not be misrepresented; // you must not claim that you wrote the original software. // If you use this software in a product, an acknowledgment // in the product documentation would be appreciated but is not required. // // 2. Altered source versions must be plainly marked as such, // and must not be misrepresented as being the original software. // // 3. This notice may not be removed or altered from any source distribution. //////////////////////////////////////////////////////////////////////////////// #include #include #include #include #include #include #include #include #include #include "SFMLTools/FreeFlyCamera.hpp" #include "Geometry/Mesh.hpp" #include "Meshing/Skeleton3D.hpp" // Full hd : 1920x1080 constexpr auto WIDTH = 1920; constexpr auto HEIGHT = 1080; void drawScene(sft::FreeFlyCamera const& camera, geo::Mesh const& mesh, std::vector> const& circles, geo::Vector4f const& plane); void drawCircle(geo::Circle const& circle); int main(int argc, char *argv[]) { // Init mesh // pae::Skeleton3D, float> skeleton; // skeleton.loadFromFile("skel.skl"); unsigned int screenNumber = 0; geo::Mesh mesh; #include "Circles1.cxx" std::vector>> splines_circles; std::vector> circles; circles.push_back(c1); circles.push_back(c2); circles.push_back(c3); // circles.push_back(c4); for (auto const& c : circles) { for (auto const& pt : c.points) { mesh.vertices.push_back(pt.second); } } // skeleton.meshExtremities(mesh, splines_circles, profondeur); auto plane = pae::meshJunction(mesh,geo::Vector3{0.0f,0.0f,0.0f}, 2, circles); std::cout << plane << std::endl; // Création de la fenêtre sf::RenderWindow window(sf::VideoMode(WIDTH, HEIGHT), "pae", sf::Style::Fullscreen, sf::ContextSettings(32)); window.setVerticalSyncEnabled(true); window.setMouseCursorVisible(false); //Initialisation du mode 3D glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(70,(double)WIDTH/HEIGHT,0.2,1000); // Initialisation de Z-Buffer glEnable(GL_DEPTH_TEST); // Activer les textures glEnable(GL_TEXTURE_2D); // Autoriser la transparence glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // Ces 2 lignes améliorent le rendu glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST); glHint(GL_POINT_SMOOTH_HINT,GL_NICEST); // On efface le tampon d'affichage glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glFlush(); mesh.prepare(); // Camera auto camera = sft::FreeFlyCamera{}; // la boucle principale auto running = true; auto captureRequired = false; while (running) { // gestion des évènements sf::Event event; while (window.pollEvent(event)) { if (event.type == sf::Event::Closed) { // on stoppe le programme running = false; } else if (event.type == sf::Event::KeyPressed) { if (event.key.code == sf::Keyboard::Escape) { running = false; } else if (event.key.code == sf::Keyboard::P) { captureRequired = true; } } else if (event.type == sf::Event::MouseMoved) { // Hum... } else if (event.type == sf::Event::Resized) { // on ajuste le viewport lorsque la fenêtre est redimensionnée glViewport(0, 0, event.size.width, event.size.height); } } // Les trucs qui sont pas des évènements camera.nextStep(WIDTH, HEIGHT); sf::Mouse::setPosition(sf::Vector2i{WIDTH/2, HEIGHT/2}); // Dessin de la scene drawScene(camera, mesh, circles, plane); if (captureRequired) { sf::Vector2u windowSize = window.getSize(); sf::Texture texture; texture.create(windowSize.x, windowSize.y); texture.update(window); sf::Image screenshot = texture.copyToImage(); screenshot.saveToFile("data/img/capture" + std::to_string(screenNumber) + ".png"); screenNumber++; captureRequired = false; } // termine la trame courante (en interne, échange les deux tampons de rendu) window.display(); } // libération des ressources... return 0; } void drawScene(sft::FreeFlyCamera const& camera, geo::Mesh const& mesh, std::vector> const& circles, geo::Vector4f const& plane) { // Initialisation glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); // Position Camera gluLookAt(positionCamera, positionCible, vecteurVertical) camera.look(); glBegin(GL_LINES); glColor3f(1,0,0); glVertex3f(0,0,0); glVertex3f(1,0,0); glColor3f(0,1,0); glVertex3f(0,0,0); glVertex3f(0,1,0); glColor3f(0,0,1); glVertex3f(0,0,0); glVertex3f(0,0,1); glEnd(); // Dessin de carrés mesh.draw(); // Dessin des cercles glColor3f(1,0,0); drawCircle(circles[0]); glColor3f(0,1,0); drawCircle(circles[1]); glColor3f(0,0,1); drawCircle(circles[2]); // // Dessin du plan // auto p1 = geo::Vector3f{-plane.y(), plane.x(), -plane.t() / plane.z()}; // auto v1 = geo::Vector3f{-plane.z(), 0.0f, plane.x()}; // auto v2 = geo::crossProduct(geo::Vector3{plane.x(), plane.y(), plane.z()}, v1); // v1 /= v1.norm(); // v2 /= v2.norm(); // auto pt1 = p1 - 5*v1; // auto pt2 = p1 + 5*v2; // auto pt3 = p1 + 5*v1; // auto pt4 = p1 - 5*v2; // glColor4f(1.0,1.0,1.0,0.5); // glBegin(GL_QUADS); // glVertex3fv(&pt1.data[0]); // glVertex3fv(&pt2.data[0]); // glVertex3fv(&pt3.data[0]); // glVertex3fv(&pt4.data[0]); // glEnd(); // MAJ de l'écran glFlush(); } void drawCircle(geo::Circle const& circle) { glBegin(GL_LINE_LOOP); for (auto const& pt : circle.points) glVertex3fv(&pt.second.data[0]); glEnd(); }