//-------------------------------------------------------------- void ofxGLWarper::setCorner(CornerLocation cornerLocation, ofPoint screenLocation){ corners[cornerLocation] = screenLocation;// / ofPoint(width, height, 1); processMatrices(); CornerLocation location = cornerLocation; ofNotifyEvent(changeEvent, location, this); }
// Loads a model with supported ASSIMP extensions from file and stores the resulting meshes in the meshes vector. void Model::loadModel(string path) { // Read file via ASSIMP Assimp::Importer importer; const aiScene* scene = importer.ReadFile(path, aiProcess_Triangulate | aiProcess_FlipUVs); // Check for errors if(!scene || scene->mFlags == AI_SCENE_FLAGS_INCOMPLETE || !scene->mRootNode) // if is Not Zero { cout << "ERROR::ASSIMP:: " << importer.GetErrorString() << endl; return; } // Retrieve the directory path of the filepath this->directory = path.substr(0, path.find_last_of('/')); aiMatrix4x4 modelMatrix; this->processMaterial(scene); this->processLight(scene); // Process ASSIMP's root node recursively this->processNode(scene->mRootNode, scene, modelMatrix); processMatrices(); m_lightShaderStorageBuffer.bind(); m_matricesSSBO.bind(); }
//-------------------------------------------------------------- void ofxGLWarper::begin(){ if (active) { processMatrices(); } ofPushMatrix(); ofMultMatrix(myMatrix); }
//-------------------------------------------------------------- void ofxGLWarper::loadFromXml(ofXml &XML, const string& warperID){ auto c = XML.getChild(warperID); if(!c){ ofLog(OF_LOG_ERROR, "ofxGLWarper : incorrrect xml formating. No \"" + warperID + "\" tag found"); return; } if (c.find("corner").size()<4 ) { ofLog(OF_LOG_ERROR, "ofxGLWarper : incorrrect xml formating. less than 4 \"corner\" tags found"); return; } auto cor = c.getChildren("corner"); int i = 0; for(auto& ch: cor){ if(i<4){ corners[i] = glm::vec2(ch.getChild("x").getFloatValue(), ch.getChild("y").getFloatValue()); } i++; } this->activate(c.getChild("active").getBoolValue()); processMatrices(); //ofLog(OF_LOG_WARNING, "ofxGLWarper : xml object loaded OK!."); // Since the method works, this can be quiet... }
//-------------------------------------------------------------- void ofxGLWarper::load(string loadFile){ ofxXmlSettings XML; if( !XML.loadFile(loadFile) ){ ofLog(OF_LOG_ERROR, "ofxGLWarper : xml file not loaded. Check file path."); } if(!XML.tagExists("corners")){ ofLog(OF_LOG_ERROR, "ofxGLWarper : incorrrect xml formating. No \"corners\" tag found"); return; } XML.pushTag("corners"); if (XML.getNumTags("corner")<4 ) { ofLog(OF_LOG_ERROR, "ofxGLWarper : incorrrect xml formating. less than 4 \"corner\" tags found"); return; } for(int i =0; i<4; i++){ int t = XML.addTag("corner"); XML.pushTag("corner", i); if (XML.tagExists("x") && XML.tagExists("y")){ corners[i].x = XML.getValue("x", double(1.0)); corners[i].y = XML.getValue("y", double(1.0)); } XML.popTag(); } processMatrices(); ofLog(OF_LOG_ERROR, "ofxGLWarper : xml file loaded OK!."); }
//-------------------------------------------------------------- void ofxGLWarper::begin(){ if (active) { processMatrices(); } glPushMatrix(); glMultMatrixf(myMatrix); }
//-------------------------------------------------------------- void ofxGLWarper::setAllCorners(glm::vec2 &top_left, glm::vec2 &top_right, glm::vec2 &bot_left, glm::vec2 &bot_right){ //if you want to set all corners and avoid 3 useless processMatrices() corners[TOP_LEFT] = top_left; corners[TOP_RIGHT] = top_right; corners[BOTTOM_LEFT] = bot_left; corners[BOTTOM_RIGHT] = bot_right; processMatrices(); }
//-------------------------------------------------------------- void ofxGLWarper::keyPressed(ofKeyEventArgs &args){ if (cornerIsSelected && selectedCorner >= 0) { switch (args.key) { case OF_KEY_DOWN: corners[selectedCorner] += glm::vec2(0,1); processMatrices(); break; case OF_KEY_UP: corners[selectedCorner] += glm::vec2(0,-1); processMatrices(); break; case OF_KEY_LEFT: corners[selectedCorner] += glm::vec2(-1,0); processMatrices(); break; case OF_KEY_RIGHT: corners[selectedCorner] += glm::vec2(1,0); processMatrices(); break; default: break; } } }
//-------------------------------------------------------------- void ofxGLWarper::loadFromXml(ofxXmlSettings &XML){ if(!XML.tagExists("corners")){ ofLog(OF_LOG_ERROR, "ofxGLWarper : incorrrect xml formating. No \"corners\" tag found"); return; } XML.pushTag("corners"); if (XML.getNumTags("corner")<4 ) { ofLog(OF_LOG_ERROR, "ofxGLWarper : incorrrect xml formating. less than 4 \"corner\" tags found"); return; } for(int i =0; i<4; i++){ int t = XML.addTag("corner"); XML.pushTag("corner", i); if (XML.tagExists("x") && XML.tagExists("y")){ corners[i].x = XML.getValue("x", double(1.0)); corners[i].y = XML.getValue("y", double(1.0)); } XML.popTag(); } XML.popTag(); processMatrices(); ofLog(OF_LOG_WARNING, "ofxGLWarper : xml object loaded OK!."); }
//-------------------------------------------------------------- void ofxGLWarper::setup(int _x, int _y, int _w, int _h){ ofLogVerbose() << "ofxGLWarper setup: " <<_x << " " <<_y << " " <<_w << " " <<_h << endl; corners[TOP_LEFT] = glm::vec2( _x , _y ); corners[TOP_RIGHT] = glm::vec2( _x + _w , _y ); corners[BOTTOM_RIGHT] = glm::vec2( _x + _w , _y + _h ); corners[BOTTOM_LEFT] = glm::vec2( _x , _y + _h ); deactivate(); // function checks if was already active myMatrix = glm::mat4(); // identity x=_x; y=_y; width=_w; height=_h; selectedCorner = -1; cornerIsSelected = false; cornerSensibility = 0.5; bUseKeys = true; bUseMouse = true; processMatrices(); }
//-------------------------------------------------------------- void ofxGLWarper::moveCorner(CornerLocation cornerLocation, glm::vec2 &moveBy){ corners[cornerLocation] += moveBy; processMatrices(); }
//-------------------------------------------------------------- void ofxGLWarper::setCorner(CornerLocation cornerLocation, float onScreenLocationX, float onScreenLocationY){ corners[cornerLocation] = glm::vec2(onScreenLocationX, onScreenLocationY);// glm::vec2(width, height); processMatrices(); }
//-------------------------------------------------------------- void ofxGLWarper::setCorner(CornerLocation cornerLocation, glm::vec2 &onScreenLocation){ corners[cornerLocation] = onScreenLocation;// glm::vec2(width, height); processMatrices(); }
//-------------------------------------------------------------- void ofxGLWarper::moveAllCorners(glm::vec2 &moveBy){ for (int i = 0; i < 4; ++i) { corners[i] += moveBy; } processMatrices(); }
//-------------------------------------------------------------- void ofxGLWarper::mouseDragged(ofMouseEventArgs &args){ if(cornerIsSelected && selectedCorner >= 0){ corners[selectedCorner] = glm::vec2(args.x, args.y); } processMatrices(); }