Пример #1
0
Scene::Scene(World *world) {
    this->world = world;

    std::vector<Intersection*> intersections = world->getIntersections();
    QPen solidLinePen(Qt::SolidLine);
    solidLinePen.setColor(Qt::white);
    solidLinePen.setWidth(5);
    QPen dashedLinePen(Qt::DashLine);
    dashedLinePen.setColor(Qt::white);
    dashedLinePen.setWidth(5);
    QBrush brush(Qt::gray);

    addIntersections(solidLinePen, brush);
    addRoads(solidLinePen, dashedLinePen, brush);
    addTrafficLights();
    addCars();
}
Пример #2
0
//--------------------------------------------------------------
void ofApp::setup() {
    ofEnableSmoothing();
    ofEnableAlphaBlending();
    ofSetFrameRate(22);
    
    float r = 0.4f;
    
    memset( dmxData_, 0, DMX_DATA_LENGTH );
    
    //open the device
    dmxInterface_ = ofxGenericDmx::createDevice(DmxDevice::DMX_DEVICE_RAW);
    bool opened = dmxInterface_->open();
    if ( dmxInterface_ == 0 || !opened ) {
        printf( "No FTDI Device Found\n" );
    } else {
        printf( "isOpen: %i\n", dmxInterface_->isOpen() );
    }
    
    printf("ofxGenericDmx addon version: %s.%s\n", ofxGenericDmx::VERSION_MAJOR, ofxGenericDmx::VERSION_MINOR);
    
    addCar.addListener(this, &ofApp::carPressed);
    addPerson.addListener(this,&ofApp::personPressed);
    addBike.addListener(this,&ofApp::bikePressed);
    addTrain.addListener(this,&ofApp::trainPressed);
    
    gui.setup(); // most of the time you don't need a name
    gui.add(bColor.setup("Background Color",ofColor(100),ofColor(0,0),ofColor(255,255), 20.0));
    gui.add(lColor.setup("Left Color",ofColor(255,255,0),ofColor(0,0),ofColor(255,255), 20.0));
    gui.add(rColor.setup("Right Color",ofColor(0,0,250),ofColor(0,0),ofColor(255,255), 20.0));
    gui.add(autoMode.setup("Automate Traffic", false));
    gui.add(addCar.setup("Add Car"));
    gui.add(addPerson.setup("Add Person"));
    gui.add(addBike.setup("Add Bike"));
    gui.add(addTrain.setup("Add Train"));
//    gui.add(region1Info.setup("Region1 Info", false));
//    gui.add(region2Info.setup("Region2 Info", false));
//    gui.add(region3Info.setup("Region3 Info", false));
//    gui.add(region4Info.setup("Region4 Info", false));
//    gui.add(region5Info.setup("Region5 Info", false));
//    gui.add(region6Info.setup("Region6 Info", false));

    curWidth = 1280;
    curHeight = 900;
    
    decayRate = 0.99f;
    growthRate = 1.0001f;
    aGrowthRate = 3.0f;
    bAccel = 0.99;
    
    pulseGrowth = 19.0;
    pulseDecay = 0.5f;
    pulseHeightLeft = 1.01f;
    pulseHeightRight = 1.01f;
    pulseLeftGrowing = false;
    pulseRightGrowing = false;
    trainGrowing = false;;
    trainGrowthRate = 1.009f;
    trainDecay = 0.98;
    ambientLevel = 51.0;
    
    std::string file = "Lightweave_loops.json";
    std::string columnsFile = "Lightweave_columns.json";
    
    // Now parse the JSON
    bool parsingSuccessful = result.open(file);
    
    bool parsingSuccessfulColumn = columnGeometry.open(columnsFile);
    
    if (parsingSuccessful) {
        ofLogNotice("ofApp::setup") << result.getRawString();
        if (!result.save("example_output_pretty.json", true)) {
            ofLogNotice("ofApp::setup") << "example_output_pretty.json written unsuccessfully.";
        } else {
            ofLogNotice("ofApp::setup") << "example_output_pretty.json written successfully.";
        }
        // now write without pretty print
        if (!result.save("example_output_fast.json", false)) {
            ofLogNotice("ofApp::setup") << "example_output_pretty.json written unsuccessfully.";
        } else {
            ofLogNotice("ofApp::setup") << "example_output_pretty.json written successfully.";
        }
    } else {
        ofLogError("ofApp::setup")  << "Failed to parse JSON" << endl;
    }
    
    if (parsingSuccessfulColumn) {
        ofLogNotice("ofApp::setup") << result.getRawString();
        if (!result.save("example_output_pretty.json", true)) {
            ofLogNotice("ofApp::setup") << "example_output_pretty.json written unsuccessfully.";
        } else {
            ofLogNotice("ofApp::setup") << "example_output_pretty.json written successfully.";
        }
        // now write without pretty print
        if (!result.save("example_output_fast.json", false)) {
            ofLogNotice("ofApp::setup") << "example_output_pretty.json written unsuccessfully.";
        } else {
            ofLogNotice("ofApp::setup") << "example_output_pretty.json written successfully.";
        }
    } else {
        ofLogError("ofApp::setup")  << "Failed to parse JSON" << endl;
    }
    
    
    for (int region = 0; region < 6; region++) {
        string blah = "region" + ofToString(region);
        for (int rings = 0; rings < result[blah].size(); rings++) {
            string ring = "ring" + ofToString(rings);
            for (int pointPos = 0; pointPos < 3; pointPos++) {
                string point = "point" + ofToString(pointPos);
                if (result[blah][ring][point][2].asFloat() > maxZ) {
                    maxZ = result[blah][ring][point][2].asFloat();
                }
                if (result[blah][ring][point][2].asFloat() < minZ && result[blah][ring][point][2].asFloat() != 0.0) {
                    minZ = result[blah][ring][point][2].asFloat();
                }
                if (result[blah][ring][point][1].asFloat() > maxY) {
                    maxY = result[blah][ring][point][1].asFloat();
                }
                if (result[blah][ring][point][1].asFloat() < minY && result[blah][ring][point][1].asFloat() != 0.0) {
                    minY = result[blah][ring][point][1].asFloat();
                }
            }
        }
    }
    maxZ*=(1280.0/1920.0);
    maxY*=(900.0/1080.0);
    backgroundImage.loadImage("unnamed.jpg");
    addCars(4);
    addTrains();
    addPeople(20);
    addBikes(4);
}
Пример #3
0
//--------------------------------------------------------------
void ofApp::carPressed(){
    addCars(2);
}