//-------------------------------------------
void ofxAssimpModelLoader::draw(ofPolyRenderMode renderType) {
    if(scene == NULL) {
        return;
    }
    
    ofPushStyle();
    
    if(!ofGetGLProgrammableRenderer()){
	#ifndef TARGET_OPENGLES
		glPushAttrib(GL_ALL_ATTRIB_BITS);
		glPushClientAttrib(GL_CLIENT_ALL_ATTRIB_BITS);
		glPolygonMode(GL_FRONT_AND_BACK, ofGetGLPolyMode(renderType));
	#endif
		glEnable(GL_NORMALIZE);
    }
    
    ofPushMatrix();
    ofMultMatrix(modelMatrix);
    
    for(unsigned int i=0; i<modelMeshes.size(); i++) {
        ofxAssimpMeshHelper & mesh = modelMeshes[i];
        
        ofPushMatrix();
        ofMultMatrix(mesh.matrix);
        
        if(bUsingTextures){
            if(mesh.hasTexture()) {
                ofTexture * tex = mesh.getTexturePtr();
                if(tex->isAllocated()) {
                    tex->bind();
                }
            }
        }
        
        if(bUsingMaterials){
            mesh.material.begin();
        }
        
        if(mesh.twoSided) {
            glEnable(GL_CULL_FACE);
        }
        else {
            glDisable(GL_CULL_FACE);
        }
        
        ofEnableBlendMode(mesh.blendMode);
#ifndef TARGET_OPENGLES
        mesh.vbo.drawElements(GL_TRIANGLES,mesh.indices.size());
#else
        switch(renderType){
		    case OF_MESH_FILL:
		    	mesh.vbo.drawElements(GL_TRIANGLES,mesh.indices.size());
		    	break;
		    case OF_MESH_WIREFRAME:
		    	mesh.vbo.drawElements(GL_LINES,mesh.indices.size());
		    	break;
		    case OF_MESH_POINTS:
		    	mesh.vbo.drawElements(GL_POINTS,mesh.indices.size());
		    	break;
        }
#endif
        
        if(bUsingTextures){
            if(mesh.hasTexture()) {
                ofTexture * tex = mesh.getTexturePtr();
                if(tex->isAllocated()) {
                    tex->unbind();
                }
            }
        }
        
        if(bUsingMaterials){
            mesh.material.end();
        }
        
        ofPopMatrix();
    }
    
    ofPopMatrix();

    if(!ofGetGLProgrammableRenderer()){
	#ifndef TARGET_OPENGLES
		glPopClientAttrib();
		glPopAttrib();
	#endif
    }
    ofPopStyle();
}
// selfDraw draws in 3D using the default ofEasyCamera
// you can change the camera by returning getCameraRef()
void CloudsVisualSystemLaplacianTunnel::selfDraw(){
	
	//glEnable(GL_CULL_FACE);
	ofEnableDepthTest();
	glDisable(GL_LIGHTING);
	//glFrontFace(GL_CCW);
	
	glPointSize(2);
	if(vbos.size() > 0){
		shader.begin();
		
		ofFloatColor color = ofFloatColor::fromHsb(bgHue/255., bgSat/255., bgBri/255.);
		float spread = (max.y - min.y);
		shader.setUniform1f("minFogDist",spread*(numReplications-2.));
		shader.setUniform1f("maxFogDist",spread*(numReplications-1.));
		shader.setUniform1f("cameray", tunnelCam.getPosition().y);
		shader.setUniform3f("fogColor",color.r,color.g,color.b);
//		shader.setUniformMatrix4f("inverseView", tunnelCam.getModelViewMatrix().getInverse());
		float startY = min.y + tunnelCam.getPosition().y - fmod(tunnelCam.getPosition().y, spread);
		
		ofMatrix4x4 geo;
		ofSetColor(255);
		
		for(int i = 0; i < numReplications; i++){
			ofPushMatrix();
			
			float translateAmount = (startY + i*spread);
			float rotationAngle = (i+int(tunnelCam.getPosition().y/spread))*90;
//			ofTranslate(0,translateAmount,0);
//			ofTranslate(center);
//			ofRotate(rotationAngle,0,-1,0);
//			ofTranslate(-center);
			
			geo.makeIdentityMatrix();
			geo.translate(-center);
			geo.rotate(rotationAngle,0,-1,0);
			geo.translate(center);
			geo.translate(0, translateAmount, 0);
			ofMultMatrix(geo);
			
			shader.setUniformMatrix4f("geoTransform",geo);
			
			float cameraoffset = tunnelCam.getPosition().y - translateAmount - spread;
			
			int index;
			if(bPalindrome){
				index = fmod(currentGrowthIndex, vbos.size()*2);
				//palindrome wrap
				if(index >= vbos.size()){
					index = vbos.size()*2 - index - 1;
				}
			}
			else{
				index = int( ofMap(cameraoffset, 0, -spread*numReplications, vbos.size()-1, 0.0, true) );
			}
			if(bDrawPoints){
				vbos[index].vbo->draw(GL_POINTS, 0, vbos[index].indexCount);
			}
			else{
				vbos[index].vbo->drawElements(GL_TRIANGLES, vbos[index].indexCount);
			}
			
			ofPopMatrix();
		}

		shader.end();
	}
	
//	glDisable(GL_CULL_FACE);

}
Exemple #3
0
//--------------------------------------------------------------
void Tunnel::draw(float alph){
    if (!isPaused) {
        camera.enableMove();
    }
    camera.begin();
    if (!camTargSet) {
        camera.target(ofVec3f(0,0,1));
        camTargSet = true;
    }
    
    camPos = camera.getPosition();
	hallLight.enable();

    if (!secondTime) {
        hallLight.setPosition(camera.getPosition());
        float attenuationFactor = 0.008 * (2560.0/ofGetScreenWidth());
        hallLight.setAttenuation(0,attenuationFactor,0);
    } else {
        hallLight.setPosition(0,0,0);
        hallLight.setAttenuation(1,0,0);
    }
    
    ofPushMatrix();
    ofSetColor(255,255-alph);
    glLineWidth(1);
    
    ofxAssimpMeshHelper & meshHelper = hallModel.getMeshHelper(0);
    ofMultMatrix(hallModel.getModelMatrix());
    ofMultMatrix(meshHelper.matrix);


    //*
    
    if (isClipping) {
    
        ofVec3f testPos = camPos;                       //Hacky-ass clipping
        
        
        if (testPos.x < goal2.x + hallWidth) {
            if (testPos.x < goal2.x-hallWidth) {
                testPos.x = goal2.x-hallWidth;
            }
        }
        
        if ((testPos.z >= goal1.z && testPos.x > goal2.x+hallWidth*1.5) || (testPos.z <= goal1.z-hallWidth && abs(testPos.x) >= hallWidth*1.5)) {
            if (testPos.z > goal1.z+(hallWidth*0.8)) {
                testPos.z = goal1.z+(hallWidth*0.8);
            } else if (testPos.z < goal1.z-(hallWidth)) {
                testPos.z = goal1.z-(hallWidth);
            }
        }
        
        if (testPos.x > goal2.x+hallWidth && testPos.z >= goal1.z+hallWidth*1.5){
            testPos.x = goal2.x+hallWidth;
        }
        
        if (testPos.z < goal1.z-hallWidth && abs(testPos.x) < hallWidth*1.5) {
            if (testPos.x > hallWidth){
                testPos.x = hallWidth;
            } else if (camPos.x < -hallWidth) {
                testPos.x = -hallWidth;
            }
            
            if (testPos.z < -53 * distFactor) {
                testPos.z = -53 * distFactor;
            }
        }
        
        if (testPos != camPos) {
            camera.clip(testPos);
        }
    }
    //cout << "camPos.z: " << camPos.z << " | camPos.z: " << camPos.z/distFactor << endl;

    //*/
    
    if (!secondTime) {
        if (camera.getPosition().squareDistance(goal1) < (4900.0 * distFactor)) {
            ofSendMessage("TunnelA:1:3");
        }
        
        if (camera.getPosition().squareDistance(goal2) < (4900.0 * distFactor)) {
            ofSendMessage("TunnelA:2:3");
        }
    }
    
    if (secondTime) {
        if (camera.getPosition().squareDistance(goal1) < (250000.0 * distFactor) || camera.getPosition().squareDistance(goal2) < (250000.0 * distFactor)) {
            ofSendMessage("TunnelB:0:7");
        }
    }
    
    //hallMesh.drawFaces();
    hallMesh.drawWireframe();
    
    
    
    ofPopMatrix();
    
    hallLight.disable();
    ofDisableLighting();
    
    camera.end();
}
//--------------------------------------------------------------
void ofApp::drawScene(bool isPreview){
	
	ofEnableDepthTest();

	if (isPreview) {
		ofPushStyle();
		ofSetColor(150, 100, 100);
		ofDrawGrid(1.0f, 5.0f, true);
		
		ofSetColor(255);
		
		//--
		//draw camera preview
		//
		headTrackedCamera.transformGL();
		
		ofPushMatrix();
		ofScale(0.002f, 0.002f, 0.002f);
		ofNode().draw();
		ofPopMatrix();
		
		ofMultMatrix(headTrackedCamera.getProjectionMatrix().getInverse());
		
		ofPushStyle();
		ofNoFill();
		ofDrawBox(2.0f);
		ofPopStyle();
		
		headTrackedCamera.restoreTransformGL();
		//
		//--
		
		//--
		//draw window preview
		//
		window.clear();
		window.addVertex(windowTopLeft);
		window.addVertex(windowBottomLeft);
		window.addVertex(windowBottomRight);
		window.setMode(OF_PRIMITIVE_LINE_STRIP);
		window.draw();
		glPointSize(3.0f);
		window.drawVertices();
		//
		//--
	}
	
	ofPushStyle();
	ofNoFill();
	ofColor col(200,100,100);
	for (float z = 0.0f; z > -40.0f; z-= 0.1f){
		col.setHue(int(-z * 100.0f + ofGetElapsedTimef() * 10.0f) % 360);
		ofSetColor(col);
		ofRect(-windowWidth / 2.0f, -windowHeight / 2.0f, z, windowWidth, windowHeight);
	}
	ofPopStyle();
	
	ofPushStyle();
	ofEnableSmoothing();
	ofSetColor(255);
	ofSetLineWidth(5.0f);
	ofBeginShape();
	for (unsigned int i=0; i<headPositionHistory.size(); i++) {
		ofPoint vertex(headPositionHistory[i].x, headPositionHistory[i].y, -float( headPositionHistory.size() - i ) * 0.05f);
		ofCurveVertex(vertex);
	}
	ofEndShape(false);
	ofPopStyle();
	
	ofDisableDepthTest();
}
// ---------------------------------------------------------------------------------------------------------------------------------------------------
//
void ofxOculusRift::setupScreenPerspective(float _interOcularDistance, float width, float height, ofOrientation orientation, bool vFlip, float fov, float nearDist, float farDist)
{
	if(width == 0) width = ofGetWidth();
	if(height == 0) height = ofGetHeight();
	
	float viewW = ofGetViewportWidth();
	float viewH = ofGetViewportHeight();
	
	float eyeX = viewW / 2;
	float eyeY = viewH / 2;
	float halfFov = PI * fov / 360;
	float theTan = tanf(halfFov);
	float dist = eyeY / theTan;
	float aspect = (float) viewW / viewH;
	
	if(nearDist == 0) nearDist = dist / 10.0f;
	if(farDist == 0) farDist = dist * 10.0f;
	
	ofSetMatrixMode(OF_MATRIX_PROJECTION);
	ofLoadIdentityMatrix();
	
	ofTranslate( ofPoint(_interOcularDistance,0,0) );
	
	ofMatrix4x4 persp;
	persp.makePerspectiveMatrix(fov, aspect, nearDist, farDist);
	ofMultMatrix( persp );
	//gluPerspective(fov, aspect, nearDist, farDist);
	
	
	ofSetMatrixMode(OF_MATRIX_MODELVIEW);
	ofLoadIdentityMatrix();
	
	ofMatrix4x4 lookAt;
	lookAt.makeLookAtViewMatrix( ofVec3f(eyeX, eyeY, dist),  ofVec3f(eyeX, eyeY, 0),  ofVec3f(0, 1, 0) );
	ofLoadMatrix( lookAt );
	
	//note - theo checked this on iPhone and Desktop for both vFlip = false and true
	if(ofDoesHWOrientation()){
		if(vFlip){
			ofScale(1, -1, 1);
			ofTranslate(0, -height, 0);
		}
	}else{
		if( orientation == OF_ORIENTATION_UNKNOWN ) orientation = ofGetOrientation();
		switch(orientation) {
			case OF_ORIENTATION_180:
				ofRotate(-180, 0, 0, 1);
				if(vFlip){
					ofScale(1, -1, 1);
					ofTranslate(-width, 0, 0);
				}else{
					ofTranslate(-width, -height, 0);
				}
				
				break;
				
			case OF_ORIENTATION_90_RIGHT:
				ofRotate(-90, 0, 0, 1);
				if(vFlip){
					ofScale(-1, 1, 1);
				}else{
					ofScale(-1, -1, 1);
					ofTranslate(0, -height, 0);
				}
				break;
				
			case OF_ORIENTATION_90_LEFT:
				ofRotate(90, 0, 0, 1);
				if(vFlip){
					ofScale(-1, 1, 1);
					ofTranslate(-width, -height, 0);
				}else{
					ofScale(-1, -1, 1);
					ofTranslate(-width, 0, 0);
				}
				break;
				
			case OF_ORIENTATION_DEFAULT:
			default:
				if(vFlip){
					ofScale(1, -1, 1);
					ofTranslate(0, -height, 0);
				}
				break;
		}
	}
	
}
Exemple #6
0
//--------------------------------------------------------------
void ofxGLWarper::begin(){
    ofPushMatrix();
    ofMultMatrix(myMatrix);
    ofTranslate(-1*x,-1*y); //if not, you have to draw from warper's origin. As you wish.
}
void demoAdvanced::draw( ) {

    int tx = 0;
    int ty = 0;
    
    ofBackground( 0, 0, 0 );
    
    // quaternion
    ofPushMatrix();

        ofTranslate( ofGetWidth() * 0.5f, ofGetHeight() * 0.5f, -200 );
        
        ofNoFill();
        ofSetColor( 255,255,255 );
        float rotationAmount;
        ofVec3f rotationAngle;
        quaternion.getRotate(rotationAmount, rotationAngle);
        ofRotate(rotationAmount, rotationAngle.x, rotationAngle.y, rotationAngle.z);
        ofBox( 0,0,0, 100, 100, 100 );
        
        ofSetColor( 255,0,0 );
        ofLine( 0,0,0, 100,0,0 );
        ofSetColor( 0,255,0 );
        ofLine( 0,0,0, 0,100,0 );
        ofSetColor( 0,0,255 );
        ofLine( 0,0,0, 0,0,100 );
    
    ofPopMatrix();
    
    // matrix 4x4
    ofPushMatrix();

        ofTranslate( ofGetWidth() * 0.5f, ofGetHeight() * 0.5f, -200 );
        
        ofNoFill();
        ofSetColor( 255,255,255 );
        
        ofMultMatrix( mat );
        ofBox( 0,0,0, 200, 200, 200 );
        
        ofSetColor( 255,0,0 );
        ofLine( 0,0,0, 100,0,0 );
        ofSetColor( 0,255,0 );
        ofLine( 0,0,0, 0,100,0 );
        ofSetColor( 0,0,255 );
        ofLine( 0,0,0, 0,0,100 );
    
    ofPopMatrix();
    
    
    
    ofSetColor( 255,255,255 );
    ty = 25;
    ofDrawBitmapString( "tweener fps: " + ofToString( _tweener->fps() ), 10, ty ); ty += 15;
    ofDrawBitmapString( "tweener time speed: " + ofToString( _tweener->timespeed() ), 10, ty ); ty += 15;
    ofDrawBitmapString( "tweener inner time: " + ofToString( _tweener->innertime() ), 10, ty ); ty += 15;
    if ( _tweener->running() ) {
        ofDrawBitmapString( "tweener is playing", 10, ty ); ty += 15;
    } else {
        ofDrawBitmapString( "tweener is paused", 10, ty ); ty += 15;
    }
    ofDrawBitmapString( "millis: " + ofToString( ofGetElapsedTimeMillis() ), 10, ty ); ty += 15;
    ofDrawBitmapString( "of fps: " + ofToString( ofGetFrameRate() ), 10, ty ); ty += 15;
    
    ofSetColor( 255,255,100 );
    stringstream ss;
    for ( int i = 1; i < lognum; ++i ) {
        ss << logs[ i ] << endl;
    }
    ofDrawBitmapString( ss.str(), 300, 25 );
    
}
void testApp::draw() {
	ofSetColor(255,255);
//	camera1.draw(0, 0);
	
	ofRectangle rgbdRect(0, 0, 1280, 720);

	cam.applyRotation = cam.applyTranslation = showRGBD && rgbdRect.inside(mouseX, mouseY);
	if(showRGBD){
		ofSetColor(0);
		ofRect(rgbdRect);
		ofSetColor(255);
		cam.begin(rgbdRect);
		
		glEnable(GL_DEPTH);
		renderer1.drawWireFrame();
		
		ofPushMatrix();
		
//		ofMultMatrix(calibrationMatrix);
//		ofVec3f axis;
//		float angle;
//		rotation.getRotate(angle, axis);
//		ofRotate(-angle, axis.x,axis.y,axis.z);
//		ofTranslate(-translation);
		
		ofMultMatrix(getMatrix());
		renderer2.drawWireFrame();
		
		ofPopMatrix();
		
		glDisable(GL_DEPTH);

		cam.end();
	}
	else{
//		front.getColorImage().draw(0,0);
		//back.getRawIRImage().draw(640, 480);
		depthImage1Rect = ofRectangle(0,0,640,480);
		depthImage2Rect = ofRectangle(640,0,640,480);

		if(depthImage1.isAllocated()) depthImage1.draw(0, 0);
		if(depthImage2.isAllocated()) depthImage2.draw(640, 0);
		
		if(inThreshold){
			ofSetColor(255,200,10);
		}
		else{
			ofSetColor(255);
		}
		contourFinder.draw();
		
		ofPushMatrix();
		ofTranslate(640, 0);
		backContourFinder.draw();
		ofPopMatrix();
		
		ofSetColor(255);
		
		ofPushStyle();
//		for(int i = 0; i < 4; i++){
//			ofSetColor(	markerColors[i] );
//			ofCircle(depthImage1Rect.getTopLeft() + cam1Calib[i], 5);
//			ofCircle(depthImage2Rect.getTopLeft() + cam2Calib[i], 5);
//
//		}
		//draw cross hires
		ofSetLineWidth(3);
		ofSetColor(255, 100, 100, 150);
		ofLine(320, 0, 320, 480);
		ofLine(640+320, 0, 640+320, 480);
		ofLine(0, 240, 640*2, 240);
		ofPopStyle();
		
	}
	ofDrawBitmapString("framerate " + ofToString(ofGetFrameRate()) + "\n" +
					   "area depth: " + ofToString(areaDepth,1) + "\n"+
					   "time in thresdhold: " + ofToString(ofGetElapsedTimef() - thresholdEnteredTime,1),
					   10, 500);

	gui.draw();
	
//	camera2.draw(0, 0);

	// camera.drawPhoto(0, 0, 432, 288);
	/*
	if(camera.isLiveReady()) {
		stringstream status; 
			status << camera.getWidth() << "x" << camera.getHeight() << " @ " <<
			(int) ofGetFrameRate() << " app-fps " << " / " <<
			(int) camera.getFrameRate() << " cam-fps";
		ofDrawBitmapString(status.str(), 10, 20);
	}
	*/
	
	if(pix.isAllocated()){
//		pix.draw(0,0);
	}
}
//--------------------------------------------------------------
void ofApp::draw(){
    
    // テクスチャー作成
    ofDisableDepthTest();
    switch (source) {
        case 0:
            envTex = envImage.getTexture();
            break;
            
        case 1:
            if(videoPlayer.isFrameNew()){
                fbo.begin();
                ofClear(0);
                ofEnableArbTex();
                videoPlayer.draw(0, 0, 1920, 960);
                ofDisableArbTex();
                fbo.end();
                envTex = fbo.getTexture();
            }
            break;
            
        case 2:
            if(theta.isFrameNew()){
                fbo.begin();
                ofClear(0);
                equirectShader.begin();
                equirectShader.setUniformTexture("mainTex", theta.getTexture(), 0);
                equirectShader.setUniform1f("radius", 0.445);
                equirectShader.setUniform4f("uvOffset", 0, 0, 0, 0);
                theta.draw(0, 0, 1280, 640);
                equirectShader.end();
                fbo.end();
                envTex = fbo.getTexture();
            }
            break;
            
        default:
            break;
    }
    
    // 描画
    ofEnableDepthTest();
    cam.begin();
    
    envTex.bind();
    envSphere.draw();
    envTex.unbind();
    
    envMapShader.begin();
    envMapShader.setUniformTexture("envMap", envTex, 0);
    envMapShader.setUniformMatrix4f("viewTranspose", ofMatrix4x4::getTransposedOf(cam.getModelViewMatrix()));
    
    switch (object) {
        case 0:
        case 1:
            ofPushMatrix();
            ofTranslate(0, -150);
            for(int i=0; i<model.getNumMeshes(); i++){
                ofPushMatrix();
                ofMultMatrix(model.getMeshHelper(i).matrix);
                ofScale(modelScale.x, modelScale.y, modelScale.z);
                model.getCurrentAnimatedMesh(i).draw();
                ofPopMatrix();
            }
            ofPopMatrix();
            break;
        
        case 2:
            ofDrawSphere(0, 0, 300);
            break;
    }
    
    envMapShader.end();
    cam.end();
}
//-------------------------------------------
void ofxAssimpModelLoader::draw(ofPolyRenderMode renderType) {
    if(scene == NULL) {
        return;
    }
    
    ofPushStyle();
    
    ofPushMatrix();
    ofMultMatrix(modelMatrix);
    
    int curRenderType = -1;
    
    for(unsigned int i=0; i<modelMeshes.size(); i++) {
        ofxAssimpMeshHelper & mesh = modelMeshes[i];
        
        ofPushMatrix();
        ofMultMatrix(mesh.matrix);

        if(bUsingTextures){
            if(mesh.hasTexture()) {
                mesh.getTextureRef().bind();
            }
        }
        
        if(bUsingMaterials){
            mesh.material.begin();
        }

        if(mesh.twoSided) {
            glEnable(GL_CULL_FACE);
        }
        else {
            glDisable(GL_CULL_FACE);
        }
        
        ofEnableBlendMode(mesh.blendMode);
#ifndef TARGET_OPENGLES
        
        //avoid setting it over and over again for the same type.
        if( curRenderType != renderType ){
            glPolygonMode(GL_FRONT_AND_BACK, ofGetGLPolyMode(renderType));
            curRenderType = renderType;
        }
        
        mesh.vbo.drawElements(GL_TRIANGLES,mesh.indices.size());
#else
        switch(renderType){
		    case OF_MESH_FILL:
		    	mesh.vbo.drawElements(GL_TRIANGLES,mesh.indices.size());
		    	break;
		    case OF_MESH_WIREFRAME:
		    	mesh.vbo.drawElements(GL_LINES,mesh.indices.size());
		    	break;
		    case OF_MESH_POINTS:
		    	mesh.vbo.drawElements(GL_POINTS,mesh.indices.size());
		    	break;
        }
#endif
        
        if(bUsingTextures){
            if(mesh.hasTexture()) {
            	 mesh.getTextureRef().unbind();
            }
        }
        
        if(bUsingMaterials){
            mesh.material.end();
        }
        
        ofPopMatrix();
    }
    
    #ifndef TARGET_OPENGLES
        if( curRenderType != OF_MESH_FILL ){
            glPolygonMode(GL_FRONT_AND_BACK, ofGetGLPolyMode(OF_MESH_FILL));
        }
    #endif

    ofPopMatrix();
    ofPopStyle();
}
Exemple #11
0
void ofxBone::draw(){
	ofPushMatrix();
	ofMultMatrix(getGlobalTransformMatrix());
	customDraw();
	ofPopMatrix();
};
Exemple #12
0
//--------------------------------------------------------------
void ofApp::draw(){
    
    
    ofPushMatrix();
    
    float _x = (screenWidth - processScreenWidth) * 0.5;
    float _y = (screenHeight - processScreenHeight) * 0.5;
    ofTranslate(_x, _y);
    
    ofPushMatrix();
    
    
    spectrum->update();
    
    if (imageProcessView) {
        processingImagFbo.draw(0, 0);
    } else {
        originalFbo.draw(0, 0);
        cam.begin();
        
        //        ofRotateY(90);
        
        //    ofSetColor(150);
        
        ofxAssimpMeshHelper & meshHelper = figureModel.getMeshHelper(0);
        
        ofMultMatrix(figureModel.getModelMatrix());
        ofMultMatrix(meshHelper.matrix);
        
        ofMaterial & material = meshHelper.material;
        if(meshHelper.hasTexture()){
            meshHelper.getTextureRef().bind();
        }
        material.begin();
        mesh.drawWireframe();
        material.end();
        if(meshHelper.hasTexture()){
            meshHelper.getTextureRef().unbind();
        }
        
        
        cam.end();
    }
    
    
    playerHead->drawPlayHead();
    
    ofPopMatrix();
    
    
    drawVolumeLine();
    
    
    ofPopMatrix();
    
    if (bGuiView) {
        ofDisablePointSprites();
        ofDisableDepthTest();
        gui.draw();
    }
    
    
}
Exemple #13
0
//--------------------------------------------------------------
void testApp::draw()
{
    glEnable( GL_DEPTH_TEST );
    if (bDebug) {
        oculusRift.setNeedSensorReadingThisFrame( true );
        
        cam.begin();
        {
            ofPushMatrix();
            {
                ofPushMatrix();
                {
                    positionPointCloud();
                    drawUFO();

                    ofPushMatrix();
                    {
                        ofMultMatrix(oculusRift.getHeadsetOrientationMat());
                        ofSetColor( 255, 0, 0 );
                        ofBox( 200 );
                        
                        ofSetColor( 0, 0, 255 );
                        ofPushMatrix();
                        {
                            ofTranslate(0, 0, -100);
//                            ofScale(1,1,20);
                            ofBox( 100 );
                        }
                        ofPopMatrix();
                    }
                    ofPopMatrix();
                }
                ofPopMatrix();
            }
            ofPopMatrix();
        }
        cam.end();
        
        glDisable( GL_DEPTH_TEST );
    }
    else
    {
        oculusRift.beginRenderSceneLeftEye();
        {
            positionPointCloud();
            if (bDrawUFO) drawUFO();
        }
        oculusRift.endRenderSceneLeftEye();
        
        oculusRift.beginRenderSceneRightEye();
        {
            positionPointCloud();
            if (bDrawUFO) drawUFO();
        }
        oculusRift.endRenderSceneRightEye();
        
        
        ofSetColor( 255 );
        oculusRift.draw( ofVec2f(0,0), ofVec2f( ofGetWidth(), ofGetHeight() ) );
    }
}
	//----------
	void Device::drawWorld() {
		auto colorSource = this->getColorSource();
		auto depthSource = this->getDepthSource();
		auto bodySource = this->getBodySource();

		if (!depthSource) {
			ofLogError("ofxKinectForWindows2::Device::drawPrettyMesh") << "No depth source initialised";
			return;
		}
		
		//point cloud
		{
			//setup some point cloud properties for kicks
			bool usePointSize = true;

#if OF_VERSION_MAJOR > 0 || OF_VERSION_MINOR >= 10
			auto mainWindow = std::static_pointer_cast<ofAppGLFWWindow>(ofGetCurrentWindow());
			usePointSize = mainWindow ? mainWindow->getSettings().glVersionMajor <= 2 : false;
#endif

			usePointSize = false;

			if (usePointSize) {
				glPushAttrib(GL_POINT_BIT);
				glPointSize(5.0f);
				glEnable(GL_POINT_SMOOTH);
			}

			ofPushStyle();

			bool useColor = colorSource.get();
			if (useColor) {
				useColor &= colorSource->getTexture().isAllocated();
			}

			if (useColor) {
				//bind kinect color camera texture and draw mesh from depth (which has texture coordinates)
				colorSource->getTexture().bind();
			}

			auto opts = Source::Depth::PointCloudOptions(true, Source::Depth::PointCloudOptions::TextureCoordinates::ColorCamera);
			auto mesh = depthSource->getMesh(opts);

			//draw point cloud
			mesh.drawVertices();

			//draw triangles
			ofSetColor(255, 150);
			mesh.drawWireframe();

			//draw fills faded
			ofSetColor(255, 50);
			mesh.drawFaces();

			if (useColor) {
				//unbind colour camera
				colorSource->getTexture().unbind();
			}

			ofPopStyle();

			//clear the point cloud drawing attributes
			if (usePointSize) {
				glPopAttrib();
			}
		}
		
		//bodies and floor
		if (bodySource) {
			bodySource->drawWorld();

			ofPushMatrix();
			ofRotateDeg(90, 0, 0, 1);
			ofMultMatrix(bodySource->getFloorTransform());
			ofDrawGridPlane(5.0f);
			ofPopMatrix();
		}

		//draw the view cones of depth and colour cameras
		ofPushStyle();
		ofNoFill();
		ofSetLineWidth(2.0f);
		ofSetColor(100, 200, 100);
		depthSource->drawFrustum();
		if (colorSource) {
			ofSetColor(200, 100, 100);
			colorSource->drawFrustum();
		}
		ofPopStyle();
	}
Exemple #15
0
//----------------------------------------
void ofNode::transformGL() const {
	ofPushMatrix();
	ofMultMatrix( getGlobalTransformMatrix() );
	//glMultMatrixf( getGlobalTransformMatrix().getPtr() );
}
Exemple #16
0
//--------------------------------------------------------------
void ofApp::draw(){
	if (path_est.size() > 0)
	{
		cam.begin();
		ofPushStyle();
		/// Render points as 3D cubes
		for (size_t i = 0; i < point_cloud_est.size(); ++i)
		{
			cv::Vec3d point = point_cloud_est[i];
			cv::Affine3d point_pose(cv::Mat::eye(3, 3, CV_64F), point);
			
			char buffer[50];
			sprintf(buffer, "%d", static_cast<int>(i));

			ofBoxPrimitive box;
			ofSetLineWidth(2.0f);
			ofSetColor(ofColor::blue);
			box.set(0.1, 0.1, -0.1);
			box.setPosition(point[0], point[1], point[2]);
			box.drawWireframe();	
		}
		ofPopStyle();
		cam.end();

		cv::Affine3d cam_pose = path_est[idx];
		
		cv::Matx44d mat44 = cam_pose.matrix;
			ofMatrix4x4 m44(mat44(0, 0), mat44(1, 0), mat44(2, 0), mat44(3, 0),
				mat44(0, 1), mat44(1, 1), mat44(2, 1), mat44(3, 1),
				mat44(0, 2), mat44(1, 2), mat44(2, 2), mat44(3, 2),
				mat44(0, 3), mat44(1, 3), mat44(2, 3), mat44(3, 3));

		if (camera_pov) {	
			cam.setPosition(m44.getTranslation());
			cam.lookAt(ofVec3f(0,0,1)*m44, ofVec3f(mat44(1,0),mat44(1,1), mat44(1,2)));
		}
		else
		{
			std::vector<ofPoint> path;
			for (int i = 0; i < path_est.size()-1; i++) {
				cv::Vec3d point = path_est[i].translation();
				path.push_back(ofPoint(point[0], point[1], point[2]));
			}
			ofPolyline trajectory(path);
			
			// render complete trajectory
			cam.begin();
			ofSetColor(ofColor::green);
			trajectory.draw();
			ofSetColor(ofColor::yellow);
			ofPushMatrix();
			ofMultMatrix(m44);
			ofDrawAxis(0.25);
			drawFrustum(f, cx, cy, 0.025, 0.4);
			ofPopMatrix();
			cam.end();
		}

		// update trajectory index (spring effect)
		forw *= (idx == n-1 || idx == 0) ? -1 : 1; idx += forw;
	}
}
void CloudsVisualSystem3DModelLoader::drawSceneGeometry( ofCamera* cam)
{
	
	//rotation velocity
	float t = ofGetElapsedTimef();
	accumulatedRotation += globalRotationVelocity * 1. / ofGetFrameRate();
	
	//draw infinite grid by positioning it infront of the camera
	if(bDrawGrid)
	{
		//	ofVec3f camPos;
		//	camPos = cam->getPosition();
		//	camPos += cam->getUpDir().cross(cam->getSideDir()).normalize() * gridDim * gridScale * .5;
		
		ofSetColor(255,255, 255, 150 );// make this an adjustable color in th GUI
		
		gridShader.begin();
		gridShader.setUniform1f("halfGridDim", gridDim * .5 );
		gridShader.setUniform1f("falloffDist", fogFalloffDistance );
		gridShader.setUniform1f("falloffExpo", fogFalloffExpo );
		gridShader.setUniform1f("falloffScl", fogFalloffScale );
		gridShader.setUniform1f("alphaScale", gridAlphaScale );
		
		//draw  minor grid
		ofPushMatrix();
		ofScale( gridScale, gridScale, gridScale );
		
		ofSetLineWidth( gridLineWidth );
		ofSetColor( gridColor.r*gridBrightness, gridColor.g*gridBrightness, gridColor.b*gridBrightness, gridAlpha );
		grid.draw(GL_LINES, 0, numGridVertices );
		
		ofPopMatrix();
		
		//draw  major grid
		ofPushMatrix();
		int gms = gridMajorScale;
		ofTranslate( getCameraRef().getLookAtDir() * -gridLineWidth / gridScale );
		ofScale( gridScale * gms,gridScale * gms, gridScale * gms );
		
		ofSetLineWidth( majorGridLineWidth );
		ofSetColor( gridMajorColor.r*gridMajorBrightness, gridMajorColor.g*gridMajorBrightness, gridMajorColor.b*gridMajorBrightness, gridMajorAlpha );
		grid.draw(GL_LINES, 0, numGridVertices );
		
		ofPopMatrix();
		
		gridShader.end();
	}
	
	//draw wireframe view cameras to the scene
	if(bDrawCameras)
	{
		drawMultipleViewCameras( cameraLineScale, cam );
	}
	
	if(bDrawArrows)
	{
		//draw arrows at model's min bound
		ofPushMatrix();
		ofTranslate( minBound * modelTransform.getGlobalTransformMatrix() );
		ofMultMatrix( modelTransform.getGlobalOrientation() );
		
		ofSetColor(0, 255, 0);
		ofPushMatrix();
		ofScale( arrowScale.x, arrowScale.y, arrowScale.z );
		arrowMesh.draw();
		ofPopMatrix();
		
		ofSetColor(255, 0, 0);
		ofPushMatrix();
		ofRotate(90, 1, 0, 0);
		ofScale( arrowScale.x, arrowScale.y, arrowScale.z );
		arrowMesh.draw();
		ofPopMatrix();
		
		ofSetColor(0, 0, 255);
		ofPushMatrix();
		ofRotate(90, 1, 0, 0);
		ofRotate(90, 0, 0, -1);
		ofScale( arrowScale.x, arrowScale.y, arrowScale.z );
		arrowMesh.draw();
		ofPopMatrix();
		
		ofPopMatrix();
	}
	
	
	//draw our model
	ofPushMatrix();
	
//	ofTranslate(-boundCenter);
	
	ofMultMatrix( modelTransform.getGlobalTransformMatrix() );
	
	if(currentSingleCam != &pathCamera)
	{
		ofTranslate( positionOffset - boundCenter );
		ofRotateX( globalRotation.x + accumulatedRotation.x );
		ofRotateY( globalRotation.y + accumulatedRotation.y );
		ofRotateZ( globalRotation.z + accumulatedRotation.z );
	}
	
	//draw bounding box
	if(bDrawBoundingBox)
	{
		ofSetColor(255, 255, 255, 255);
		drawBoundingBox();
	}
	
	if(bDrawCameraPath)
	{
		ofSetLineWidth(majorGridLineWidth);
		simpleShader.begin();
		pathCamera.drawPaths();
		simpleShader.end();
	}
	
	ofSetColor(modelColor);
	if(activeShader != NULL )
	{
		
		activeShader->begin();
		activeShader->setUniform1f( "discardThreshold", discardThreshold );
		activeShader->setUniform1f( "specularExpo", specularExpo );
		activeShader->setUniform1f( "specularScale", specularScale );
		activeShader->setUniform1f("falloffDist", fogFalloffDistance );
		activeShader->setUniform1f("falloffExpo", fogFalloffExpo );
		activeShader->setUniform1f("falloffScl", fogFalloffScale );
		
		if(activeShader == &XRayShader){
			/*
			 sfactor
			 Specifies how the red, green, blue, and alpha source blending factors are computed. The following symbolic constants are accepted: GL_ZERO, GL_ONE, GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR, GL_DST_COLOR, GL_ONE_MINUS_DST_COLOR, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA, GL_CONSTANT_COLOR, GL_ONE_MINUS_CONSTANT_COLOR, GL_CONSTANT_ALPHA, GL_ONE_MINUS_CONSTANT_ALPHA, and GL_SRC_ALPHA_SATURATE. The initial value is GL_ONE.
			 
			 dfactor
			 Specifies how the red, green, blue, and alpha destination blending factors are computed. The following symbolic constants are accepted: GL_ZERO, GL_ONE, GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR, GL_DST_COLOR, GL_ONE_MINUS_DST_COLOR, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA. GL_CONSTANT_COLOR, GL_ONE_MINUS_CONSTANT_COLOR, GL_CONSTANT_ALPHA, and GL_ONE_MINUS_CONSTANT_ALPHA. The initial value is GL_ZERO.
			 */
			
			//GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA
			glDisable( GL_DEPTH_TEST );
			glBlendFunc(GL_ONE, GL_ONE);
			
//			modelMesh.draw();
			bWireframe?	modelMesh.drawWireframe() : modelMesh.draw();
			
			ofBlendMode( OF_BLENDMODE_ADD );
			glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
		}
		else{
			if(bWireframe)	ofSetLineWidth( wireframeLinewidth );
			bWireframe?	modelMesh.drawWireframe() : modelMesh.draw();
		}
		
		activeShader->end();
	}
	
	ofPopMatrix();
}