Exemplo n.º 1
0
void zerokernel::VariableListEntry::setVariable(settings::IVariable *variable)
{
    switch (variable->getType())
    {
    case settings::VariableType::BOOL:
        control = std::move(createCheckbox(variable));
        break;
    case settings::VariableType::INT:
    case settings::VariableType::FLOAT:
        control = std::move(createSpinner(variable));
        break;
    case settings::VariableType::STRING:
        control = std::move(createTextInput(variable));
        break;
    case settings::VariableType::COLOR:
        control = std::move(createColorPicker(variable));
        break;
    case settings::VariableType::KEY:
        control = std::move(createKeyInput(variable));
        break;
    }
    if (control)
    {
        control->setParent(this);
        control->bb.setMargin(0, 0, 0, 4);
    }
}
Exemplo n.º 2
0
static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods){

    //EXIT
    if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
        glfwSetWindowShouldClose(window, GL_TRUE);

    //PLAYBACK
    if (key == GLFW_KEY_SPACE && action == GLFW_PRESS){
        pause = !pause;
    }
    if (key == GLFW_KEY_RIGHT && action == GLFW_PRESS)
        forward = true;
    if (key == GLFW_KEY_RIGHT && action == GLFW_RELEASE)
        forward = false;
    if (key == GLFW_KEY_LEFT && action == GLFW_PRESS)
        backward = true;
    if (key == GLFW_KEY_LEFT && action == GLFW_RELEASE)
        backward = false;


    //MODIFICATION
    if (key == GLFW_KEY_M && action == GLFW_PRESS){
        float m = readFloat("Enter particle mass: ");
        mcs->particles.setMasses(m, Particles::ALL);
    }

    if (key == GLFW_KEY_L && action == GLFW_PRESS){
        float l = readFloat("Enter connection length: ");
        mcs->connections.setLengths(l);
    }

    if (key == GLFW_KEY_S && action == GLFW_PRESS){
        float s = readFloat("Enter spring constant: ");
        mcs->connections.setSpringConstant(s);
    }

    if (key == GLFW_KEY_D && action == GLFW_PRESS){
        float d = readFloat("Enter damper constant: ");
        mcs->connections.setDamperConstant(d);
    }
    if (key == GLFW_KEY_F && action == GLFW_PRESS){
        mcs->freeze();
    }
    if (key == GLFW_KEY_TAB && action == GLFW_PRESS){
        if(!wireframe){
            glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
            glDisable(GL_CULL_FACE);
            wireframe = true;
        }
        else{
            glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
            glEnable(GL_CULL_FACE);
            wireframe = false;
        }
    }

    //INITS
    if (key == GLFW_KEY_1 && action == GLFW_PRESS){
        std::cout << "Loading Floppy Thing... " << std::endl;
        delete mcs;
        drawable_mcs->deleteBuffers();
        drawable_mcs->setUpBuffers(cloth1_textureID);
        mcs = createFloppyThing();
        cam->setTarget(mcs);
        drawable_mcs->updateAllBuffers(mcs, *ground_material, matrices,cloth1_textureID);
        for (int i = 0; i<drawable_planes.size(); ++i) {
            delete drawable_planes[i];
        }
        drawable_planes.resize(0);
        for (int i=0; i<mcs->collisionPlanes.size(); ++i) {
            drawable_planes.push_back(new OpenGL_drawable(&mcs->collisionPlanes[i], *ground_material, programID, floor3_textureID));
        }
        std::cout << "Done" << std::endl;
    }

    if (key == GLFW_KEY_2 && action == GLFW_PRESS){
        std::cout << "Loading Rolling Dice..." << std::endl;
        delete mcs;
        drawable_mcs->deleteBuffers();
        drawable_mcs->setUpBuffers(die_textureID);
        mcs = createRollingDice();
        cam->setTarget(mcs);
        drawable_mcs->updateAllBuffers(mcs, *ground_material, matrices,die_textureID);
        for (int i = 0; i<drawable_planes.size(); ++i) {
            delete drawable_planes[i];
        }
        drawable_planes.resize(0);
        for (int i=0; i<mcs->collisionPlanes.size(); ++i) {
            drawable_planes.push_back(new OpenGL_drawable(&mcs->collisionPlanes[i], *ground_material, programID, floor2_textureID));
        }
        std::cout << "Done" << std::endl;
    }

    if (key == GLFW_KEY_3 && action == GLFW_PRESS){
        std::cout << "Loading Standing Snake..." << std::endl;
        delete mcs;
        drawable_mcs->deleteBuffers();
        drawable_mcs->setUpBuffers(textureID);
        mcs = createStandingSnake();
        cam->setTarget(mcs);
        drawable_mcs->updateAllBuffers(mcs, *ground_material, matrices,textureID);
        for (int i = 0; i<drawable_planes.size(); ++i) {
            delete drawable_planes[i];
        }
        drawable_planes.resize(0);
        for (int i=0; i<mcs->collisionPlanes.size(); ++i) {
            drawable_planes.push_back(new OpenGL_drawable(&mcs->collisionPlanes[i], *ground_material, programID, textureID));
        }
        std::cout << "Done" << std::endl;
    }

    if (key == GLFW_KEY_4 && action == GLFW_PRESS){
        std::cout << "Loading Cloth..." << std::endl;
        delete mcs;
        drawable_mcs->deleteBuffers();
        drawable_mcs->setUpBuffers(cloth2_textureID);
        mcs = createCloth();
        cam->setTarget(mcs);
        drawable_mcs->updateAllBuffers(mcs, *ground_material, matrices, cloth2_textureID);
        for (int i = 0; i<drawable_planes.size(); ++i) {
            delete drawable_planes[i];
        }
        drawable_planes.resize(0);
        for (int i=0; i<mcs->collisionPlanes.size(); ++i) {
            drawable_planes.push_back(new OpenGL_drawable(&mcs->collisionPlanes[i], *ground_material, programID, textureID));
        }
        std::cout << "Done" << std::endl;
    }

    if (key == GLFW_KEY_5 && action == GLFW_PRESS){
        std::cout << "Loading SoftCube..." << std::endl;
        delete mcs;
        drawable_mcs->deleteBuffers();
        drawable_mcs->setUpBuffers(faces_textureID);
        mcs = createSoftCube();
        cam->setTarget(mcs);
        drawable_mcs->updateAllBuffers(mcs, *ground_material, matrices,faces_textureID);
        for (int i = 0; i<drawable_planes.size(); ++i) {
            delete drawable_planes[i];
        }
        drawable_planes.resize(0);
        for (int i=0; i<mcs->collisionPlanes.size(); ++i) {
            switch (i) {
                case 0: // Ground
                    drawable_planes.push_back(new OpenGL_drawable(&mcs->collisionPlanes[i], *ground_material, programID, wall2_textureID));
                    break;
                case 1: // Wall
                    drawable_planes.push_back(new OpenGL_drawable(&mcs->collisionPlanes[i], *ground_material, programID, wall3_textureID));
                    break;
                default:
                    drawable_planes.push_back(new OpenGL_drawable(&mcs->collisionPlanes[i], *ground_material, programID, wall3_textureID));
                    break;
            }
        }
        std::cout << "Done" << std::endl;
    }
    
    if (key == GLFW_KEY_6 && action == GLFW_PRESS){
        std::cout << "Loading Spinner..." << std::endl;
        delete mcs;
        drawable_mcs->deleteBuffers();
        drawable_mcs->setUpBuffers(cloth1_textureID);
        mcs = createSpinner();
        cam->setTarget(mcs);
        drawable_mcs->updateAllBuffers(mcs, *ground_material, matrices,cloth1_textureID);
        for (int i = 0; i<drawable_planes.size(); ++i) {
            delete drawable_planes[i];
        }
        drawable_planes.resize(0);
        for (int i=0; i<mcs->collisionPlanes.size(); ++i) {
            switch (i) {
                case 0: // Ground
                    drawable_planes.push_back(new OpenGL_drawable(&mcs->collisionPlanes[i], *ground_material, programID, floor3_textureID));
                    break;
                case 1: // Wall
                    drawable_planes.push_back(new OpenGL_drawable(&mcs->collisionPlanes[i], *ground_material, programID, cloth5_textureID));
                    break;
                default:
                    drawable_planes.push_back(new OpenGL_drawable(&mcs->collisionPlanes[i], *ground_material, programID, cloth5_textureID));
                    break;
            }
        }
        std::cout << "Done" << std::endl;
    }
    
    if (key == GLFW_KEY_7 && action == GLFW_PRESS){
        std::cout << "Loading Jelly..." << std::endl;
        delete mcs;
        drawable_mcs->deleteBuffers();
        drawable_mcs->setUpBuffers(slime_textureID);
        mcs = createJelly();
        cam->setTarget(mcs);
        Material slime_material;
        slime_material.wetness = 0.1;
        slime_material.shinyness = 64;
        slime_material.specularity = 0.5;
        drawable_mcs->updateAllBuffers(mcs, slime_material, matrices,slime_textureID);
        for (int i = 0; i<drawable_planes.size(); ++i) {
            delete drawable_planes[i];
        }
        drawable_planes.resize(0);
        for (int i=0; i<mcs->collisionPlanes.size(); ++i) {
            switch (i) {
                case 0: // Ground
                    drawable_planes.push_back(new OpenGL_drawable(&mcs->collisionPlanes[i], *ground_material, programID, floor2_textureID));
                    break;
                case 1: // Wall
                    drawable_planes.push_back(new OpenGL_drawable(&mcs->collisionPlanes[i], *ground_material, programID, floor2_textureID));
                    break;
                default:
                    drawable_planes.push_back(new OpenGL_drawable(&mcs->collisionPlanes[i], *ground_material, programID, floor2_textureID));
                    break;
            }
        }
        std::cout << "Done" << std::endl;
    }
    if (key == GLFW_KEY_8 && action == GLFW_PRESS){
        std::cout << "Loading Waffle... " << std::endl;
        delete mcs;
        drawable_mcs->deleteBuffers();
        drawable_mcs->setUpBuffers(waffle_textureID);
        mcs = createWaffle();
        cam->setTarget(mcs);
      Material waffle_material;
      waffle_material.wetness = 0.0;
      waffle_material.shinyness = 4;
      waffle_material.specularity = 0.2;
        drawable_mcs->updateAllBuffers(mcs, waffle_material, matrices,waffle_textureID);
      
      Material tiling_material;
      tiling_material.wetness = 0.001;
      tiling_material.shinyness = 128;
      tiling_material.specularity = 0.3;
      
      Material induction_material;
      induction_material.wetness = 0.0;
      induction_material.shinyness = 512;
      induction_material.specularity = 0.4;
        for (int i = 0; i<drawable_planes.size(); ++i) {
            delete drawable_planes[i];
        }
        drawable_planes.resize(0);
        for (int i=0; i<mcs->collisionPlanes.size(); ++i) {
            switch (i) {
                case 0: // Ground
                    drawable_planes.push_back(new OpenGL_drawable(&mcs->collisionPlanes[i], induction_material, programID, induction_textureID));
                    break;
                case 1: // Wall
                    drawable_planes.push_back(new OpenGL_drawable(&mcs->collisionPlanes[i], tiling_material, programID, tiling_textureID));
                    break;
                default:
                    drawable_planes.push_back(new OpenGL_drawable(&mcs->collisionPlanes[i], *ground_material, programID, floor2_textureID));
                    break;
            }
            
        }
        std::cout << "Done" << std::endl;
    }

}