Пример #1
0
void trackpad_mouse_scroll(float delta_x, float delta_y) {
	checkGesture(TRACKPAD_SCROLL);
	
	scrollVelocity.set(delta_x, delta_y);
	scrollPosition += scrollVelocity;
	
	cam = camStart;
	cam.truck(scrollScale * scrollPosition.x);
	cam.boom(scrollScale * -scrollPosition.y);
}
Пример #2
0
bool getTriangleFromSegmentSize(double _szA, double _szB, double _szC, double x0, double y0, double _angle, double _scale, ofVec2f & _ptA, ofVec2f & _ptB, ofVec2f & _ptC) {

    double r0 = _szB * _scale;
    double x1 = 0 + _szA * _scale;
    double y1 = 0;
    double r1 = _szC * _scale;

    vector<ofVec2f> _points;

    circlesIntersection(0, 0, r0, x1, y1, r1, _points);

    if(_points.size() == 0) return false; // dont intersect --- sides dont make a triangle

    _ptA.set(0, 0);
    _ptB.set(x1, y1);
    _ptC.set(_points[1].x, _points[1].y);

    _ptC.x = _ptB.x + (_ptA.x - _ptC.x);
    _ptC.y = _ptB.y + (_ptA.y - _ptC.y);

    double _sin = sin(ofDegToRad(_angle));
    double _cos = cos(ofDegToRad(_angle));

    ofVec2f _pivot = (_ptA + _ptB + _ptC) / 3.0;

    _ptA -= _pivot;
    _ptB -= _pivot;
    _ptC -= _pivot;

    _ptA = rotatePoint(_ptA.x, _ptA.y, 0, 0, 0, 0, _sin, _cos);
    _ptB = rotatePoint(_ptB.x, _ptB.y, 0, 0, 0, 0, _sin, _cos);
    _ptC = rotatePoint(_ptC.x, _ptC.y, 0, 0, 0, 0, _sin, _cos);

    _ptA += ofVec2f(x0,y0);
    _ptB += ofVec2f(x0,y0);
    _ptC += ofVec2f(x0,y0);

    return true;
}
Пример #3
0
void handle::pivot(float f, ofVec2f p, ofVec2f t, string jType, string actor){

    ofVec2f np(m_posC);

    if(jType == "weld"){

        np = m_posC.getRotated(f, p, ofVec3f(0,0,1));
        t.set(np - m_posC);
        m_posC.set(np);
        m_rotC += f;

    }else if(jType == "pivot"){
        if(m_posC != p){
            m_posC += t;
        }
    }

    //recursive function call on children
    vector <handleJoint>::iterator it = m_children.begin();

    while(it != m_children.end()){
        if(it->m_handle->getIndex() == actor){++it; continue;} //actor is to prevent double calls
        if(it->m_type == "free"){++it; continue;}
        if(jType == "weld" &&  it->m_type == "weld"){
            it->m_handle->pivot(f, p, t, "weld", m_index);
        }else if(jType == "pivot" || it->m_type == "pivot"){
            if(m_posC != p)it->m_handle->pivot(f, p, t, "pivot", m_index);
        }
        ++it;
    }

    //pivot the parent
    if(m_parent){
        if(actor != m_parent->getIndex()){

            handleJoint hj = m_parent->getChildJoint(m_index);

            if(jType == "weld" &&  hj.m_type == "weld"){
                m_parent->pivot(f, p, t, "weld", m_index);
            }else if(jType == "pivot" || hj.m_type == "pivot"){
                if(m_posC != p)m_parent->pivot(f, p, t, "pivot", m_index);
            }

        }
    }

}
Пример #4
0
	void fitLine(const ofPolyline& polyline, ofVec2f& point, ofVec2f& direction) {
		Vec4f line;
		fitLine(Mat(toCv(polyline)), line, CV_DIST_L2, 0, .01, .01);
		direction.set(line[0], line[1]);
		point.set(line[2], line[3]);
	}
Пример #5
0
	void setForce(float x, float y) {
		force.set(x,y);
	}
Пример #6
0
	void setPos(float x, float y) {
		pos.set(x,y);
	}
Пример #7
0
//--------------------------------------------------------------
void ofApp::setup(){
    // Init
    ofBackground(255, 255, 255);
    ofSetFrameRate(59.94);
    
    font.load("MuseoSans_500.otf", 45);
    fontSmall.load("MuseoSans_500.otf", 22);
    
    // Videos loading
    videoSize.set(1280, 720);
    ofFbo f;
    f.allocate(videoSize.x, videoSize.y);
    fbos.push_back(f);
    
    thumbVideoSize.set(320, 180);
    
    image.load(targetDate + "/kmeans.png");
    for (int i = 0; i < 1; i++) {
        ofVideoPlayer v;
        videos.push_back(v);
        
        videos[i].load(targetDate + "/movie.mov");
        videos[i].play();
        
        float speed = 1;
        videoSpeeds.push_back(videoSpeed);
        
        f.allocate(thumbVideoSize.x, thumbVideoSize.y);
        fbos.push_back(f);
    }
    
    myGlitch.setup(&fbos[0]);
    
    // GUI Set up
    gui.setup();
    gui.add(rateThreshold.setup("rate", ofVec2f(50, 120), ofVec2f(0, 0), ofVec2f(180, 180)));
    gui.add(taionThreshold.setup("taion", 35, 30.0, 40.0));
    gui.setPosition(videoSize.x + 20, 300);
    
    setupJsons();
    averageTaion = getAverage(taions);
    minMaxTaion = getMinMax(taions);
    minMaxRate  = getMinMax(rates);
    
    loading = false;

    
    csv.load(targetDate + "/rt.csv");
    
    for(int i = 0; i < csv.getNumRows(); i++) {
        // Rt mode
        int a = ofToInt(csv[i][3]);
        
        // D mode
//        int a = ofToInt(csv[i][2]) + 1;
        cls.push_back(a);
    }
    
    afont.loadFont("fontawesome-webfont.ttf", 40);
    setPieChart();
    
    for (int i = 0; i < 4; i++) {
        ofPath path;
        switch (i) {
            case 0:
                path.setColor(ofColor(69,105,144));
                break;
            case 1:
                path.setColor(ofColor(239,118,122));
                break;
            case 2:
                path.setColor(ofColor(73,190,170));
                break;
            case 3:
                path.setColor(ofColor(238,184,104));
                break;
            default:
                break;
        }

        path.setCircleResolution(360);
        path.moveTo(150, 150);
        path.arc( 150, 150, 200, 200, lastAngle, lastAngle + angles[i]);
        lastAngle += angles[i];
        
        paths.push_back(path);
    }
    
    choosedCluster = 1;
    //ウィンドウ初期位置
    ofSetWindowPosition(1441,0);
    
    for (int i = 0; i < cls.size(); i++) {
        cout << cls[i] << endl;
    }
}
Пример #8
0
void trackpad_mouse_move(float x, float y) {
	mousePosition.set(x, y);
}
Пример #9
0
void trackpad_swipe(float delta_x, float delta_y) {
	checkGesture(TRACKPAD_SWIPE);
	
	swipeVelocity.set(delta_x, delta_y);
	swipePosition += swipeVelocity;
}
	void setPosition(float x, float y) {
		position.set(x, y);
		midi.sendControlChange(1, 64 + index, getPresence());
	}
void Controller::setup(ofTexture * texture, ofVec2f originalSize, ofRectangle originalCoordinates, ofPoint originalPerspective[4], string name, float guiWidth, float guiHeight ){
    // Arguments
    this->texture = texture;
	this->name = name;
    this->guiWidth = guiWidth;
    this->guiHeight = guiHeight;
    if(originalSize.x==0.0
       && originalSize.y==0.0){
        originalSize.set(texture->getWidth(), texture->getHeight());
    }
    this->originalSize = originalSize;
    if(originalCoordinates.x==0.0
       && originalCoordinates.y==0.0
       && originalCoordinates.width==0.0
       && originalCoordinates.height==0.0){
        if(ofGetUsingNormalizedTexCoords())originalCoordinates.set(0.0, 0.0, 1.0, 1.0);
        else originalCoordinates.set(0.0, 0.0, texture->getWidth(), texture->getHeight());
    }
    this->originalCoordinates = originalCoordinates;
    if(originalPerspective[0].x == 0 && originalPerspective[0].y == 0
       && originalPerspective[1].x == 0 && originalPerspective[1].y == 0
       && originalPerspective[2].x == 0 && originalPerspective[2].y == 0
       && originalPerspective[3].x == 0 && originalPerspective[3].y == 0){
        originalPerspective[0].x = ofGetWidth()/2 - texture->getWidth()/2;
        originalPerspective[0].y = ofGetHeight()/2 - texture->getHeight()/2;
        originalPerspective[1].x = ofGetWidth()/2 + texture->getWidth()/2;
        originalPerspective[1].y = ofGetHeight()/2 - texture->getHeight()/2;
        originalPerspective[2].x = ofGetWidth()/2 + texture->getWidth()/2;
        originalPerspective[2].y = ofGetHeight()/2 + texture->getHeight()/2;
        originalPerspective[3].x = ofGetWidth()/2 - texture->getWidth()/2;
        originalPerspective[3].y = ofGetHeight()/2 + texture->getHeight()/2;
    }
    memcpy(this->originalPerspective,originalPerspective,sizeof(ofPoint)*4);
    
	// Register draw event for the enable/disable magic
	ofAddListener(ofEvents().draw, this, &Controller::drawEvent);
	drawing = false;
    drawn = true;
	
	// Some intial setup
	guiHelperFbo.allocate(150, 60);
	blendB = blendL = blendR = blendT = 0;
	lastClickTime = ofGetElapsedTimeMillis();
	historyIndex = -1;
    guiHasChanged = false;
    perspectiveHasChanged = false;

	// Generate filenames
	safename = safe_string(name);
	stringstream ss_guiFile;
	ss_guiFile << safename << "/gui.xml";	
	guiFile = ss_guiFile.str();
	
	stringstream ss_perspectiveFile;
	ss_perspectiveFile << safename << "/perspective.xml";
	perspectiveFile = ss_perspectiveFile.str();
	
	stringstream ss_meshFile;
	ss_meshFile << safename << "/mesh";
	meshFile = ss_meshFile.str();
	
	// Perspective
    perspective.setup(0, 0, getWindowWidth(), getWindowHeight());
    perspective.setCornerSensibility(0.03);
    perspective.activate();
    ofAddListener(perspective.changeEvent, this, &Controller::onPerspectiveChange);
    
	// Meshes
    controlMesh.setMode(OF_PRIMITIVE_POINTS);
	internalMesh.setMode(OF_PRIMITIVE_TRIANGLES);
	
	// GUI
    gui.setup(name, guiFile,guiWidth, guiHeight);
	gui.setPosition(originalPerspective[0].x, originalPerspective[0].y);
	
	ofxButton * load = new ofxButton();
    load->setup("Load", guiWidth, guiHeight);
    load->addListener(this, &Controller::onLoad);
    gui.add(load);
	
	ofxButton * save = new ofxButton();
    save->setup("Save", guiWidth, guiHeight);
    save->addListener(this, &Controller::onSave);
    gui.add(save);
    
    ofxToggle * enablePerspective = new ofxToggle();
    enablePerspective->setup("Perspective Warp", true, guiWidth, guiHeight);
    enablePerspective->addListener(this, &Controller::onEnablePerspective);
    gui.add(enablePerspective);
    
    ofxButton * resetPerspective = new ofxButton();
    resetPerspective->setup("Reset Perspective", guiWidth, guiHeight);
    resetPerspective->addListener(this, &Controller::onResetPerspective);
    gui.add(resetPerspective);
    
    ofxButton * resetMesh = new ofxButton();
    resetMesh->setup("Reset Mesh", guiWidth, guiHeight);
    resetMesh->addListener(this, &Controller::onResetMesh);
    gui.add(resetMesh);
    
    ofxIntSlider * resolutionX = new ofxIntSlider();
    resolutionX->setup("Horizontal Resolution", 4, 1, 20, guiWidth, guiHeight);
    resolutionX->addListener(this, &Controller::onGridChange);
    gui.add(resolutionX);
	
	ofxIntSlider * resolutionY = new ofxIntSlider();
    resolutionY->setup("Vertical Resolution", 4, 1, 20, guiWidth, guiHeight);
    resolutionY->addListener(this, &Controller::onGridChange);
    gui.add(resolutionY);
    
    ofxIntSlider * columns = new ofxIntSlider();
    columns->setup("Grid Columns", 4, 1, 20, guiWidth, guiHeight);
    columns->addListener(this, &Controller::onGridChange);
    gui.add(columns);
    
    ofxIntSlider * rows = new ofxIntSlider();
    rows->setup("Grid Rows", 4, 1, 20, guiWidth, guiHeight);
    rows->addListener(this, &Controller::onGridChange);
    gui.add(rows);
    
    ofxFloatSlider * startX = new ofxFloatSlider();
	float startXmin = originalCoordinates.x;
	float startXmax = originalCoordinates.x+originalCoordinates.width;
	float startXmargin = (startXmax - startXmin) * 0.3333;
    startX->setup("UV Start X", startXmin, startXmin - startXmargin, startXmax + startXmargin, guiWidth, guiHeight);
    startX->addListener(this, &Controller::onCoordinatesChange);
    gui.add(startX);
    
    ofxFloatSlider * startY = new ofxFloatSlider();
	float startYmin = originalCoordinates.y;
	float startYmax = originalCoordinates.y+originalCoordinates.height;
	float startYmargin = (startYmax - startYmin) * 0.3333;
    startY->setup("UV Start Y", startYmin, startYmin - startYmargin, startYmax + startYmargin, guiWidth, guiHeight);
    startY->addListener(this, &Controller::onCoordinatesChange);
    gui.add(startY);
    
    ofxFloatSlider * endX = new ofxFloatSlider();
	float endXmin = originalCoordinates.x;
	float endXmax = originalCoordinates.x+originalCoordinates.width;
	float endXmargin = (endXmax - endXmin) * 0.3333;
    endX->setup("UV End X", endXmax, endXmin - endXmargin, endXmax + endXmargin, guiWidth, guiHeight);
    endX->addListener(this, &Controller::onCoordinatesChange);
    gui.add(endX);
    
    ofxFloatSlider * endY = new ofxFloatSlider();
	float endYmin = originalCoordinates.y;
	float endYmax = originalCoordinates.y+originalCoordinates.height;
	float endYmargin = (endYmax - endYmin) * 0.3333;
    endY->setup("UV End Y", endYmax, endYmin - endYmargin, endYmax + endYmargin, guiWidth, guiHeight);
    endY->addListener(this, &Controller::onCoordinatesChange);
    gui.add(endY);
	
	ofxFloatSlider * blendTSlider = new ofxFloatSlider();
    blendTSlider->setup("Blend Top", 0, 0, 1, guiWidth, guiHeight);
    blendTSlider->addListener(this, &Controller::onBlendChange);
    gui.add(blendTSlider);
	
	ofxFloatSlider * blendDSlider = new ofxFloatSlider();
    blendDSlider->setup("Blend Down", 0, 0, 1, guiWidth, guiHeight);
    blendDSlider->addListener(this, &Controller::onBlendChange);
    gui.add(blendDSlider);
	
	ofxFloatSlider * blendLSlider = new ofxFloatSlider();
    blendLSlider->setup("Blend Left", 0, 0, 1, guiWidth, guiHeight);
    blendLSlider->addListener(this, &Controller::onBlendChange);
    gui.add(blendLSlider);
	
	ofxFloatSlider * blendRSlider = new ofxFloatSlider();
    blendRSlider->setup("Blend Right", 0, 0, 1, guiWidth, guiHeight);
    blendRSlider->addListener(this, &Controller::onBlendChange);
    gui.add(blendRSlider);
    
    ofxToggle * scissorEnable = new ofxToggle();
    scissorEnable->setup("Scissor Active", false, guiWidth, guiHeight);
    scissorEnable->addListener(this, &Controller::onScissorEnabled);
    gui.add(scissorEnable);
    
    ofxIntSlider * scissorX = new ofxIntSlider();
    scissorX->setup("Scissor Start X", 0, 0, ofGetScreenWidth(), guiWidth, guiHeight);
    scissorX->addListener(this, &Controller::onScissorChange);
    gui.add(scissorX);
    
    ofxIntSlider * scissorY = new ofxIntSlider();
    scissorY->setup("Scissor Start Y", 0, 0, ofGetScreenHeight(), guiWidth, guiHeight);
    scissorY->addListener(this, &Controller::onScissorChange);
    gui.add(scissorY);
    
    ofxIntSlider * scissorWidth = new ofxIntSlider();
    scissorWidth->setup("Scissor End X", ofGetScreenWidth(), 0, ofGetScreenWidth(), guiWidth, guiHeight);
    scissorWidth->addListener(this, &Controller::onScissorChange);
    gui.add(scissorWidth);
    
    ofxIntSlider * scissorHeight = new ofxIntSlider();
    scissorHeight->setup("Scissor End Y", ofGetScreenHeight(), 0, ofGetScreenHeight(), guiWidth, guiHeight);
    scissorHeight->addListener(this, &Controller::onScissorChange);
    gui.add(scissorHeight);
	
	
	ofxFloatSlider * postBrtSlider = new ofxFloatSlider();
    postBrtSlider->setup("Brighteness", 1, 0, 5, guiWidth, guiHeight);
    postBrtSlider->addListener(this, &Controller::onPostProcessingValueChanged);
    gui.add(postBrtSlider);
	
	ofxFloatSlider * postConSlider = new ofxFloatSlider();
    postConSlider->setup("Contrast", 1, 0, 5, guiWidth, guiHeight);
    postConSlider->addListener(this, &Controller::onPostProcessingValueChanged);
    gui.add(postConSlider);
	
	ofxFloatSlider * postSatSlider = new ofxFloatSlider();
    postSatSlider->setup("Saturation", 1, 0, 5, guiWidth, guiHeight);
    postSatSlider->addListener(this, &Controller::onPostProcessingValueChanged);
    gui.add(postSatSlider);
	
	ofxFloatSlider * postRMultSlider = new ofxFloatSlider();
    postRMultSlider->setup("Red Multiplier", 1, 0, 5, guiWidth, guiHeight);
    postRMultSlider->addListener(this, &Controller::onPostProcessingValueChanged);
    gui.add(postRMultSlider);
	
	ofxFloatSlider * postGmultSlider = new ofxFloatSlider();
    postGmultSlider->setup("Green Multiplier", 1, 0, 5, guiWidth, guiHeight);
    postGmultSlider->addListener(this, &Controller::onPostProcessingValueChanged);
    gui.add(postGmultSlider);
	
	ofxFloatSlider * postBMultSlider = new ofxFloatSlider();
    postBMultSlider->setup("Blue Multipler", 1, 0, 5, guiWidth, guiHeight);
    postBMultSlider->addListener(this, &Controller::onPostProcessingValueChanged);
    gui.add(postBMultSlider);
	
	ofxIntSlider * lineThickness = new ofxIntSlider();
    lineThickness->setup("GUI Lines Thickness", 1, 1, 10, guiWidth, guiHeight);
    lineThickness->addListener(this, &Controller::onGuiLinesThicknessChange);
    gui.add(lineThickness);
    
	
	// Post processing
    if(ofIsGLProgrammableRenderer()){
	shader.setupShaderFromSource(GL_VERTEX_SHADER, VertShaderProgrammable);
	if(ofGetUsingNormalizedTexCoords()) shader.setupShaderFromSource(GL_FRAGMENT_SHADER, NormalizedFragShaderProgrammable);
        else shader.setupShaderFromSource(GL_FRAGMENT_SHADER, UnnormalizedFragShaderProgrammable);
        shader.bindDefaults();
	shader.linkProgram();
    }
    else {
        shader.setupShaderFromSource(GL_VERTEX_SHADER, VertShader);
	if(ofGetUsingNormalizedTexCoords()) shader.setupShaderFromSource(GL_FRAGMENT_SHADER, NormalizedFragShader);
	else shader.setupShaderFromSource(GL_FRAGMENT_SHADER, UnnormalizedFragShader);
	shader.linkProgram();
    }
	
	// load settings
	onLoad();
	
	
}