示例#1
0
void testApp::drawTent() {
    ofSetColor(100);
    
	cam.begin();
    //cityModel.drawWireframe();
    tentMesh.drawWireframe();
    
    // check to see if anything is selected
    // draw hover point magenta
    
    ofMesh imageMesh = getProjectedMesh(tentMesh);
    
    
    if (bScreen) {
        ofSetColor(0, 0, 255,100);
        
        for (vector<screen>::iterator siter=screens.begin(); siter!=screens.end(); siter++) {
            ofBeginShape();
            
            ofVec3f pnt = siter->origin;
            ofVec3f wVec = siter->xVec*ofGetWidth()/scale;
            ofVec3f hVec = siter->yVec*ofGetHeight()/scale;
            
            ofVertex(pnt);
            pnt+=wVec;
            ofVertex(pnt);
            pnt+=hVec;
            ofVertex(pnt);
            pnt-=wVec;
            ofVertex(pnt);
            ofEndShape(true);
        }
    }
    
	cam.end();
    
    if (bProject) {
                
        ofMatrix4x4 projMat;    
        cam.begin();
        glGetFloatv(GL_PROJECTION_MATRIX, projMat.getPtr());
        cam.end();
        
        glMatrixMode(GL_PROJECTION);
        glPushMatrix();
        glLoadMatrixf(projMat.getPtr());
        
        for (vector<screen>::iterator siter=screens.begin(); siter!=screens.end(); siter++) {
        
            

            ofMatrix4x4 mvMat;
                        
            cam.begin();
            
            ofPushMatrix();
            glMultMatrixf(siter->glMat.getPtr());
            glGetFloatv(GL_MODELVIEW_MATRIX,  mvMat.getPtr());
            
            ofPopMatrix();
            cam.end();
            
            glPushMatrix();
            glLoadMatrixf(mvMat.getPtr());
            
            ofFill();
            ///ofRect(0, 0, 1, 1);
            ofSetColor(255, 0, 0);
            ofLine(0, 0, 200, 0);
            ofSetColor(0, 255, 0);
            ofLine(0, 0, 0, 200);
            
            ofTranslate(rects.front().x,rects.front().y);            
            ofFill();
            ofSetColor(255);
            
            //ofCircle(ofGetWidth()/2, ofGetHeight()/2, ofGetHeight()/2);   
            wstring message = L"יתרבח קדצ שרוד םעה";
            font.drawString(message, 0, font.stringHeight(message)); // 
            
            
            glPopMatrix();
        }
        
        
        glMatrixMode(GL_PROJECTION);
        glPopMatrix();
        glMatrixMode(GL_MODELVIEW);
        
        
    }

    
    ofSetColor(150);
    
    for (int i=0; i<selection.size(); i++) {
        if (selection[i].second) {
            ofVec3f &pos = imageMesh.getVerticesPointer()[selection[i].first];
            ofCircle(pos, 5);
            ofDrawBitmapString(ofToString(i+1), pos+ofVec2f(5, 25));
        }
    }
    
    ofSetColor(255);
    
    float distance;
    ofVec3f selected = getClosestPointOnMesh(imageMesh, mouseX, mouseY, &choice, &distance);
    
    ofCircle(selected, 5);
    ofDrawBitmapString(ofToString(choice), selected+ofVec2f(5, -25));
}
示例#2
0
void ofxMapaMok::draw(ofTexture *_texture){

    if (_texture != NULL)
        if ((_texture->getWidth() != textWidth ) ||
            (_texture->getHeight() != textHeight) )
            ofLog(OF_LOG_WARNING, "The applied texture have a diferent size of the one spected");
    
    if( setupMode == SETUP_SELECT ) {
    
		//  Init easyCam
        //
        cam.begin( (ofRectangle)*this );
        
        //  Reference
        //
        if(refMode == REFERENCE_AXIS)
            ofDrawAxis(100);
        else if (refMode == REFERENCE_GRID)
            ofDrawGrid(100);
        
        //  Scale
        //
        ofScale(scale, scale, scale);
        
        //  Render
        //
        render(_texture);
        
        //  Update dots positions
        //
        if( setupMode ) {
            imageMesh = getProjectedMesh(objectMesh);
        }
        
        cam.end();
        
        //  On any tipe of setup mode
        //
        if( setupMode ) {
            ofPushStyle();
            
            //  Draw all points cyan small
            //
            ofSetColor( ofxCv::cyanPrint );
            for(int i=0; i< imageMesh.getVertices().size(); i++){
                if( inside(ofVec2f(imageMesh.getVertex(i).x,imageMesh.getVertex(i).y))){
                    ofCircle(imageMesh.getVertex(i).x, imageMesh.getVertex(i).y, 2);
                }
            }
            
            //  Draw all reference points cyan
            //
            int n = referencePoints.size();
            for(int i = 0; i < n; i++) {
                if(referencePoints[i]) {
                    drawLabeledPoint(i, imageMesh.getVertex(i), ofxCv::cyanPrint );
                }
            }
            
            //  Check to see if anything is selected
            //  Draw hover point magenta
            //
            int choice;
            float distance;
			if (imageMesh.getNumVertices())
            {
				ofVec3f selected = getClosestPointOnMesh(imageMesh, ofGetAppPtr()->mouseX, ofGetAppPtr()->mouseY, &choice, &distance);
				if(!ofGetMousePressed() && distance < selectionRadius) {
					hoverChoice = choice;
					hoverSelected = true;
					drawLabeledPoint(choice, selected, ofxCv::magentaPrint);
				} else {
					hoverSelected = false;
				}
			}
			else
			{
				hoverSelected = false;
				ofLogError() << "Mesh is empty";
			}
            //  Draw selected point yellow
            //
            if( selectedVert ) {
                int choice = selectionChoice;
                ofVec2f selected = imageMesh.getVertex(choice);
                drawLabeledPoint(choice, selected, ofxCv::yellowPrint, ofColor::white, ofColor::black);
            }
            
            ofPopStyle();
        }
        
	} else {
		
        if ( calibrationReady ) {
            
            begin(near, far);
            
            render(_texture);
            if(setupMode) {
                imageMesh = getProjectedMesh(objectMesh);
            }
            
            end();
            
        } else {
            
            ofDrawBitmapString("CALIBRATION NOT READY", x+width*0.5-80, y+height*0.5 );
            ofDrawBitmapString("(you need to set more dots)", x+width*0.5-100, y+height*0.5 + 15);
            
        }
        
        if( setupMode ) {
            ofPushStyle();
            
            // draw all reference points cyan
            //
            int n = referencePoints.size();
            for(int i = 0; i < n; i++) {
                if(referencePoints[i]) {
					if(i == selectionChoice){
						drawLabeledPoint(i, ofxCv::toOf(imagePoints[i]), ofxCv::yellowPrint, ofColor::white, ofColor::black);
					}else{
						drawLabeledPoint(i, ofxCv::toOf(imagePoints[i]), ofxCv::cyanPrint);
					}
                }
            }
            
            // move points that need to be dragged
            // draw selected yellow
            //
            int choice = selectionChoice;
            if(selectedVert) {
                referencePoints[choice] = true;
                cv::Point2f& cur = imagePoints[choice];
                if(cur == cv::Point2f()) {
                    if(calibrationReady) {
                        cur = ofxCv::toCv(ofVec2f(imageMesh.getVertex(choice)));
                    } else {
                        cur = cv::Point2f(ofGetAppPtr()->mouseX, ofGetAppPtr()->mouseY);
                    }
                }
            }
            if(dragging) {
                cv::Point2f& cur = imagePoints[choice];
                float rate = ofGetMousePressed(0) ? slowLerpRate : fastLerpRate;
                cur = cv::Point2f(ofLerp(cur.x, ofGetAppPtr()->mouseX, rate), ofLerp(cur.y, ofGetAppPtr()->mouseY, rate));
                drawLabeledPoint(choice, ofxCv::toOf(cur), ofxCv::yellowPrint, ofColor::white, ofColor::black);
                ofSetColor(ofColor::black);
                ofRect( ofxCv::toOf(cur), 1, 1);
            } else if(arrowing) {
                cv::Point2f& cur = imagePoints[choice];
                drawLabeledPoint(choice, ofxCv::toOf(cur), ofxCv::yellowPrint, ofColor::white, ofColor::black);
                ofSetColor(ofColor::black);
                ofRect( ofxCv::toOf(cur), 1, 1);
            } else {
                // check to see if anything is selected
                // draw hover magenta
                float distance;
                ofVec2f selected = ofxCv::toOf(getClosestPoint(imagePoints, ofGetAppPtr()->mouseX, ofGetAppPtr()->mouseY, &choice, &distance));
                if(!ofGetMousePressed() && referencePoints[choice] && distance < selectionRadius) {
                    hoverChoice = choice;
                    hoverSelected = true;
                    drawLabeledPoint(choice, selected, ofxCv::magentaPrint);
                } else {
                    hoverSelected = false;
                }
            }
            
            ofPopStyle();
        }
        
	}
    
    if( setupMode != SETUP_NONE ) {
        if (inside(ofGetMouseX(), ofGetMouseY())){
            ofPushStyle();
            ofSetColor(255,100);
            ofNoFill();
            ofRect( (ofRectangle)*this );
            if ( setupMode == SETUP_CALIBRATE)
                ofDrawBitmapString("CALIBRATE the DOT", x+width*0.5-80,y+15);
            else if ( setupMode == SETUP_SELECT ){
                if (selectedVert)
                    ofDrawBitmapString("PRESS SPACE to CALIBRATE", x+width*0.5-100,y+15);
                else
                    ofDrawBitmapString("CLICK ONE DOT", x+width*0.5-60,y+15);
            }
            
            ofPopStyle();
        }
    }
}
示例#3
0
void testApp::drawModel() {
    ofSetColor(100);
    
	cam.begin();
    //cityModel.drawWireframe();
   // cityMesh.drawWireframe();
    cityMesh.draw();
    
    // check to see if anything is selected
    // draw hover point magenta
    
    ofMesh imageMesh = getProjectedMesh(cityMesh);
    
    
    
	cam.end();
    
    
    
    ofSetColor(255);
    
    
    ofVec3f selected = getClosestPointOnMesh(imageMesh, mouseX, mouseY, &choice, NULL);
    
    
    ofCircle(selected, 5);
    ofDrawBitmapString(ofToString(choice), selected+ofVec2f(5, -25));
    
    
    cam.begin();
    
    for (vector<tent>::iterator iter=tents.begin(); iter!=tents.end(); iter++) {
        ofVec3f p0 = cityMesh.getVerticesPointer()[iter->first];
        ofVec3f dir = cityMesh.getVerticesPointer()[iter->second]-cityMesh.getVerticesPointer()[iter->first];
        
        ofPushMatrix();
        glTranslatef(p0.x,p0.y,p0.z);
        ofRotate(atan2(dir.y, dir.x)*180/M_PI);
        
        ofSetColor(255);
        tentModel.getMesh(0).draw();
        
       
        if (bScreen) {
            ofSetColor(0, 0, 255,100);
            for (vector<screen>::iterator siter=screens.begin(); siter!=screens.end(); siter++) {
                ofBeginShape();
                
                ofVec3f pnt = siter->origin;
                ofVec3f wVec = siter->xVec*ofGetWidth()/scale;
                ofVec3f hVec = siter->yVec*ofGetHeight()/scale;
                
                ofVertex(pnt);
                pnt+=wVec;
                ofVertex(pnt);
                pnt+=hVec;
                ofVertex(pnt);
                pnt-=wVec;
                ofVertex(pnt);
                ofEndShape(true);
            }

        }

       
        ofPopMatrix();
    }
    
    
    
    

    
    
    
    ofSetColor(255);
    
    if (bTent && !bOrigin) {
        
        ofVec3f p0 = cityMesh.getVerticesPointer()[choice];
        ofPushMatrix();
        glTranslatef(p0.x,p0.y,p0.z);
        tentModel.getMesh(0).drawWireframe();
        ofPopMatrix();
    } 
    
    
    if(bOrigin) {    
        ofVec3f p0 = cityMesh.getVerticesPointer()[origin];
        ofVec3f dir = cityMesh.getVerticesPointer()[choice]-cityMesh.getVerticesPointer()[origin];
        float angle = atan2(dir.y, dir.x)*180/M_PI;
        
        ofPushMatrix();
        glTranslatef(p0.x,p0.y,p0.z);
        ofRotate(angle);
        
        tentModel.getMesh(0).drawWireframe();
        ofPopMatrix();
        
    }
	cam.end();
    
    if (bProject && !rects.empty()) {
        
        vector<wstring> words;
        words.push_back(L"םעה");
        words.push_back(L"שרוד");
        words.push_back(L"קדצ");
        words.push_back(L"יתרבח");
        
        
        ofMatrix4x4 projMat;  
        ofMatrix4x4 mvMat;
        cam.begin();
        glGetFloatv(GL_PROJECTION_MATRIX, projMat.getPtr());
        glGetFloatv(GL_MODELVIEW_MATRIX,  mvMat.getPtr());
        cam.end();
        
        glMatrixMode(GL_PROJECTION);
        glPushMatrix();
        glLoadMatrixf(projMat.getPtr());
        
        glMatrixMode(GL_MODELVIEW);
        glPushMatrix();
        glLoadMatrixf(mvMat.getPtr());
        
        for (vector<tent>::iterator iter=tents.begin(); iter!=tents.end(); iter++) {
            ofPushMatrix();
            glMultMatrixf(iter->glMat.getPtr());
            
            for (vector<screen>::iterator siter=screens.begin(); siter!=screens.end(); siter++) {
                ofPushMatrix();
                glMultMatrixf(siter->glMat.getPtr());
        
                ofTranslate(rects.front().x,rects.front().y);            
                ofFill();
                ofSetColor(0);
                
                int dist = distance(screens.begin(),siter);
                    
                if (dist<words.size()) {
                    wstring word = words[dist];
                    font.drawString(word, (rects.front().width-font.stringWidth(word))/2, font.stringHeight(word)); 
                }
                
                 
                
                glPopMatrix();
            }
            glPopMatrix();
        }
        glPopMatrix();
        
        glMatrixMode(GL_PROJECTION);
        glPopMatrix();
        glMatrixMode(GL_MODELVIEW);
    }
}