Пример #1
0
int main(int argc, char* argv[])
{

;
    MANAGER.init(argc, argv);

    GlutUI::Window & mainWindow = MANAGER.createWindow(640,480, "TestWindow");
    GlutUI::Panel & mainPanel = MANAGER.createPanel(mainWindow, 640,480, "TestPanel");
    std::cout << std::string((char *) glGetString(GL_VENDOR)) << std::endl;
    std::cout << std::string((char *) glGetString(GL_RENDERER)) << std::endl;
    std::cout << "OpenGL " << std::string((char *) glGetString(GL_VERSION)) << std::endl;
    std::cout << "====================================================" << std::endl;
    Scene::World world = Scene::createWorld();
    mainPanel.setWorld(&world);

    GlutUI::Button & testButton = MANAGER.createButton(mainPanel, 40, 20, 10, 10, "TestButton");


    Scene::Grid * gridXZ = new Scene::Grid();
    world.addObject(gridXZ);
    gridXZ->setTy(-5);

    Scene::Grid * gridXY = new Scene::Grid();
    world.addObject(gridXY);
    gridXY->setRotx(90);
    gridXY->setTz(-5);

    Scene::Grid * gridYZ = new Scene::Grid();
    world.addObject(gridYZ);
    gridYZ->setRotz(90);
    gridYZ->setTx(-5);

    mainPanel.setWorld(&world);
    mainPanel.setCamera(new Scene::Camera());
    GlutUI::Controls::Mouse(mainPanel.getCamera());

    MANAGER.drawElements();
	return 0;
}
Пример #2
0
int main(int argc, char* argv[])
{
    MANAGER.init(argc, argv);
    int windowWidth = 256;
    int windowHeight = 256;
    GlutUI::Window & mainWindow = MANAGER.createWindow(windowWidth, windowHeight, "Render Window");
    GlutUI::Panel & mainPanel = MANAGER.createPanel(mainWindow, windowWidth, windowHeight, "Render Panel");
    Scene::World world = Scene::createWorld();
    std::cout << std::string((char *)glGetString(GL_VENDOR)) << std::endl;
    std::cout << std::string((char *)glGetString(GL_RENDERER)) << std::endl;
    std::cout << "OpenGL " << std::string((char *)glGetString(GL_VERSION)) << std::endl;
    std::cout << "====================================================" << std::endl;

    Scene::Shader* rainbowShader = new Scene::Shader("shaders/rainbow_vert.glsl", "shaders/rainbow_frag.glsl");

    //char* fileName = argv[1];


    char* fileName = "models/sphere.off";

    Scene::MeshObject* meshObject = new Scene::MeshObject(fileName);
    world.assignShader(meshObject, rainbowShader);
    meshObject->readGeom();
    world.addObject(meshObject);

    float xMin = meshObject->xMin();
    float xMax = meshObject->xMax();
    float yMin = meshObject->yMin();
    float yMax = meshObject->yMax();
    float zMin = meshObject->zMin();
    float zMax = meshObject->zMax();
    float xSpan = xMax - xMin;
    float ySpan = yMax - yMin;
    float zSpan = zMax - zMin;
    float xMid = (xMin + xMax) / 2;
    float yMid = (yMin + yMax) / 2;
    float zMid = (zMin + zMax) / 2;
    meshObject->setTx(-xMid);
    meshObject->setTy(-yMid);
    meshObject->setTz(-zMid);
    float s = 0.5;
    float xAxisMin = -s*xSpan;
    float yAxisMin = -s*ySpan;
    float zAxisMin = -s*zSpan;
    float xAxisMax = s*xSpan;
    float yAxisMax = s*ySpan;
    float zAxisMax = s*zSpan;
    Scene::Arrow * xAxis = new Scene::Arrow(glm::vec3(xAxisMin, yAxisMin, zAxisMin), glm::vec3(xAxisMax, yAxisMin, zAxisMin), glm::vec4(1, 0, 0, 1));
    Scene::Arrow * yAxis = new Scene::Arrow(glm::vec3(xAxisMin, yAxisMin, zAxisMin), glm::vec3(xAxisMin, yAxisMax, zAxisMin), glm::vec4(0, 1, 0, 1));
    Scene::Arrow * zAxis = new Scene::Arrow(glm::vec3(xAxisMin, yAxisMin, zAxisMin), glm::vec3(xAxisMin, yAxisMin, zAxisMax), glm::vec4(0, 0, 1, 1));
    world.addObject(xAxis);
    world.addObject(yAxis);
    world.addObject(zAxis);
    float maxSpan = std::max({ xSpan, ySpan, zSpan });
    float minSpan = std::min({ xSpan, ySpan, zSpan });
    s = 1.5;
    Scene::Camera * cam = new Scene::Camera();
    if (xSpan == minSpan) {
        cam->setThe(-90);
        cam->setTz(xMid + s * maxSpan);
    }
    else if (ySpan == minSpan) {
        cam->setPhi(90);
        cam->setThe(90);
        cam->setTz(yMid + s * maxSpan);
    }
    else {
        cam->setTz(zMid + s * maxSpan);
    }
    world.addObject(cam);
    mainPanel.setWorld(&world);
    mainPanel.setCamera(cam);
    mainPanel.setMeshObject(meshObject);
    GlutUI::Controls::Keyboard keyboard(&mainPanel);
    GlutUI::Controls::Mouse mouse(&mainPanel, mainPanel.getCamera(), mainPanel.getMeshObject());
    /*std::set<int> f11 = meshObject->adjacency(11);
    std::set<int> f23 = meshObject->adjacency(23);
    std::set<int> vSet;
    for (auto it = f11.begin(); it != f11.end(); it++) {
    for (int i = 0; i < 3; i++) {
    vSet.insert(meshObject->faces(*it)[i]);
    }
    }
    for (auto it = f23.begin(); it != f23.end(); it++) {
    for (int i = 0; i < 3; i++) {
    vSet.insert(meshObject->faces(*it)[i]);
    }
    }
    for (auto it = vSet.begin(); it != vSet.end(); it++) {
    printf("\n%i: ", *it);
    std::set<int> asdf = meshObject->adjacency(*it);
    for (auto i = asdf.begin(); i != asdf.end(); i++) {
    printf("(%i,%i,%i) ", meshObject->faces(*i)[0], meshObject->faces(*i)[1], meshObject->faces(*i)[2]);
    }
    }
    meshObject->collapse(11, 23, Scene::BINARY_APPROXIMATION_METHOD);
    std::set<int> f11New = meshObject->adjacency(11);
    std::set<int> vSetNew;
    for (auto it = f11New.begin(); it != f11New.end(); it++) {
    for (int i = 0; i < 3; i++) {
    vSetNew.insert(meshObject->faces(*it)[i]);
    }
    }
    printf("\n\n");
    for (auto it = vSetNew.begin(); it != vSetNew.end(); it++) {
    printf("\n%i: ", *it);
    std::set<int> asdf = meshObject->adjacency(*it);
    for (auto i = asdf.begin(); i != asdf.end(); i++) {
    printf("(%i,%i,%i) ", meshObject->faces(*i)[0], meshObject->faces(*i)[1], meshObject->faces(*i)[2]);
    }
    }*/
    ///////////////////////////////////////
    ///// Keyboard Hotkey Assignments /////
    ///////////////////////////////////////
    int bmpCounter = 0;
    float complexityMultiplier = 1.0 / 32.0;
    float complexityIncrement = 1.0 / 16.0;
    auto alambda = [&]() {
        if (meshObject->format() == "off") {
            meshObject->collapseRandomEdge(Scene::MIDPOINT_APPROXIMATION_METHOD);
        }
    };
    auto slambda = [&]() {
        
        if (meshObject->format() == "off") {
            int nVV = meshObject->nVisibleVertices();
            int n = fmax(1, nVV / 100);
            printf("Random edge midpoint collapsing %i times...\n", n);
            for (int i = 0; i < n; i++) meshObject->collapseRandomEdge(Scene::MIDPOINT_APPROXIMATION_METHOD);
        }
    };
    auto zlambda = [&]() {
        if (meshObject->format() == "off"){
            meshObject->quadricSimplify();
        }
    };
    auto xlambda = [&]() {
        if (meshObject->format() == "off") {
            int nCP = meshObject->nCollapsablePairs();
            int n = sqrt(nCP) / 2;
            if (n == 0) n = fmin(nCP, 1);
            printf("%i  ", n);
            for (int i = 0; i < n; i++) {
                meshObject->quadricSimplify();
            }
        }
    };
    auto nlambda = [&]() {
        printf("Writing progressive mesh data to %s\n", meshObject->outFileName());
        meshObject->makeProgressiveMeshFile();
    };
    auto mlambda = [&]() {
        if (meshObject->format() == "off") {
            int collapseCount = 0;
            for (int i = 0; i < meshObject->nVertices(); i++) {
                if (collapseCount % 10 == 0) printf("Pairs Collapsed: %i\r", collapseCount);
                meshObject->quadricSimplify();
                collapseCount++;
            }
            //printf("Pairs Collapsed: %i\n", collapseCount);
            printf("\nMaking Progressive Mesh File: %s\n", meshObject->outFileName());
            meshObject->makeProgressiveMeshFile();
        }
    };
    auto pluslambda = [&]() {
        if (meshObject->format() == "offpm") {
            if (meshObject->complexity() < meshObject->nVertices()) {
                //std::string bmpName = fileName + std::to_string(bmpCounter) + ".bmp";
                //SaveAsBMP(bmpName.c_str());
                //bmpCounter++;
                meshObject->collapseTo((1.0f + complexityMultiplier)*meshObject->complexity());
            }
        }
    };
    auto minuslambda = [&]() {
        if (meshObject->format() == "offpm") meshObject->collapseTo((1.0 - complexityMultiplier)*meshObject->complexity());
    };
    auto rbracketlambda = [&]() {
        if (meshObject->format() == "offpm") {
            if (meshObject->complexity() < meshObject->nVertices()) {
                //std::string bmpName = fileName + std::to_string(bmpCounter) + ".bmp";
                //SaveAsBMP(bmpName.c_str());
                //bmpCounter++;
                meshObject->collapseTo(meshObject->complexity() + complexityIncrement);
            }
        }
    };
    auto lbracketlambda = [&]() {
        if (meshObject->format() == "offpm") meshObject->collapseTo(meshObject->complexity() - complexityIncrement);
    };
    auto ilambda = [&]() {
        std::string bmpName = fileName + std::to_string(bmpCounter) + ".bmp";
        SaveAsBMP(bmpName.c_str());
        bmpCounter++;
    };
    auto quotelambda = [&]() {
        complexityMultiplier += 1.0 / 256.0;
        printf("Complexity Multiplier:_%f_____\r", complexityMultiplier);
    };
    auto colonlambda = [&]() {
        complexityMultiplier = fmax(0.0, complexityMultiplier - 1.0 / 256);
        printf("Complexity Multiplier:_%f_____\r", complexityMultiplier);
    };
    auto slashlambda = [&]() {
        complexityIncrement += 1.0 / 256.0;
        printf("Complexity Increment:__%f_____\r", complexityIncrement);
    };
    auto periodlambda = [&]() {
        complexityIncrement = fmin(0.0, complexityIncrement - 1.0 / 256.0);
        printf("Complexity Increment:__%f_____\r", complexityIncrement);
    };
    auto tlambda = [&]() {
        meshObject->toggleDrawMode();
    };
    auto ylambda = [&]() {
        meshObject->toggleCustomColors();
    };
    keyboard.register_hotkey('\'', quotelambda);
    keyboard.register_hotkey(';', colonlambda);
    keyboard.register_hotkey('/', slashlambda);
    keyboard.register_hotkey('.', periodlambda);
    keyboard.register_hotkey(']', rbracketlambda);
    keyboard.register_hotkey('[', lbracketlambda);
    keyboard.register_hotkey('i', ilambda);
    keyboard.register_hotkey('=', pluslambda);
    keyboard.register_hotkey('-', minuslambda);
    keyboard.register_hotkey('a', alambda);
    keyboard.register_hotkey('s', slambda);
    keyboard.register_hotkey('x', xlambda);
    keyboard.register_hotkey('z', zlambda);
    keyboard.register_hotkey('t', tlambda);
    keyboard.register_hotkey('y', ylambda);
    keyboard.register_hotkey('n', nlambda);
    keyboard.register_hotkey('m', mlambda);

    MANAGER.drawElements();

    return 0;
}