Пример #1
0
 //--------------------------------------------------------------
 void Gui::draw() {
     if(!checkOkToRun()) return;
     
     ofPushStyle();
     ofEnableSmoothing();
     ofDisableNormalizedTexCoords();
     ofDisableLighting();
     glDisable(GL_DEPTH_TEST);
     
     Renderer::instance().clearControls();
     
     // iterate all controls on page, set position and add to render queue
     Page &page = getCurrentPage();
     page.layout.x = getConfig()->layout.scrollbarWidth;
     pLayoutManager->clearParentRect(*this);
     page.arrangeControls(true);
     _pGuiControls->arrangeControls(true);
     pLayoutManager->update();
     
     // sort and draw
     Renderer::instance().draw();
     
     ofPopStyle();
     
     // draw debug boxes around containers
     //                ofPushStyle();
     //                ofSetRectMode(OF_RECTMODE_CORNER);
     //                ofNoFill();
     //                ofSetColor(0, 255 ,0);
     //                ofDrawRectangle(page.x, page.y, page.width, page.height);
     //                ofSetColor(0, 0, 255);
     //                ofDrawRectangle(x, y, width, height);
     //                ofPopStyle();
 }
Пример #2
0
//--------------------------------------------------------------
void testApp::setup() {
    ofEnableNormalizedTexCoords();
    ofImage img;
    img.loadImage("hci.png");
    img.mirror(false, true);
    tex.allocate(640, 640, GL_RGB, true);
    ang = 0;
    glEnable(GL_DEPTH_TEST); // enable depth testing, otherwise things will
    tex.loadData(img.getPixels(), 640, 640, GL_RGB);
    ofDisableNormalizedTexCoords();
    
    ofSetLogLevel(OF_LOG_VERBOSE);
    openNIDevice.setup();
    openNIDevice.setLogLevel(OF_LOG_VERBOSE);
    openNIDevice.addDepthGenerator();
    openNIDevice.addImageGenerator(); // comment this out
    openNIDevice.start();
    
    verdana.loadFont(ofToDataPath("verdana.ttf"), 24);
    selectedPoint = ofPoint(200,200);
    
    

    


}
Пример #3
0
void ofkMeshRectRenderer::render()
{
    glMatrixMode(GL_MODELVIEW);
    ofPushMatrix();
    
    ofEnableNormalizedTexCoords();
    
    mTexture.bind();
    
    for (int vertical = 0; vertical < GridRES; vertical++) 
    {
        mVbos[vertical].draw(GL_TRIANGLE_STRIP, 0, 2*(GridRES+1));
        mVbos[vertical].draw(GL_LINE_STRIP, 0, 2*(GridRES+1));

    }
    
    ofDisableNormalizedTexCoords();
    
    mTexture.unbind();
    
    glMatrixMode(GL_MODELVIEW);
    ofPopMatrix();
    
    glMatrixMode(GL_TEXTURE);
    glLoadIdentity();
    
    glMatrixMode(GL_MODELVIEW);
    
    
}
Пример #4
0
void ofxSphereMeshRenderer::render()
{
    ofEnableNormalizedTexCoords();

    tex.bind();
    mSphere.draw();
    tex.unbind();
    ofDisableNormalizedTexCoords();
    
}
Пример #5
0
void CameraSource::draw(){
	ofClear(0);
	ofSetHexColor(0xffffff);
	
	if(_videoGrabber.isInitialized()){
		ofDisableNormalizedTexCoords();
		_videoGrabber.draw(0, 0);
		ofEnableNormalizedTexCoords();
	}else{
		ofDrawBitmapString("no camera", _cameraWidth / 2.0f - 40.0f, _cameraHeight / 2.0f + 10.0f);
	}
}
Пример #6
0
void Mask::setup(){

    if (maskFbo.getWidth() != width || maskFbo.getHeight() != height)
        maskFbo.allocate(width, height, GL_RGBA32F_ARB);

    maskFbo.begin();
        ofClear(255,255,255,0);
    maskFbo.end();

    if (maskFboImage->isAllocated()) {
        ofDisableAlphaBlending();
        ofDisableNormalizedTexCoords();
        maskFbo.begin();
        ofSetColor(255, 255, 255, 255);
            maskFboImage->draw(0,0, 1024, 768);
        maskFbo.end();
        ofEnableNormalizedTexCoords();
        ofEnableAlphaBlending();
    }
}
Пример #7
0
//--------------------------------------------------------------
void ofxBerkelium::draw(float x, float y, float w, float h) {

	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D, web_texture);
	
	ofPushMatrix();
		ofTranslate(x, y);
		ofEnableNormalizedTexCoords();
			glBegin(GL_QUADS);
				glTexCoord2f(0.f, 0.f); glVertex3f(0, 0, 0.f);
				glTexCoord2f(0.f, 1.f); glVertex3f(0, h, 0.f);
				glTexCoord2f(1.f, 1.f); glVertex3f(w,  h, 0.f);
				glTexCoord2f(1.f, 0.f); glVertex3f(w, 0, 0.f);
			glEnd();
		ofDisableNormalizedTexCoords();
	ofPopMatrix();

	glBindTexture(GL_TEXTURE_2D, 0);
	glDisable(GL_TEXTURE_2D);
	
}
Пример #8
0
//--------------------------------------------------------------
void ofApp::draw() {
    
    //----------------------------------------------------------
    gui.draw();
    
    int w = 512;
    int h = 256;
    int x = 20;
    int y = ofGetHeight() - h - 20;
    fftLive.draw(x, y, w, h);
    
    //----------------------------------------------------------
    ofEnableDepthTest();
    
    float dist = 400;
    camera.setDistance(dist);
    camera.begin();
    
    if(bUseTexture == true) {
        ofEnableNormalizedTexCoords();
        meshTexture.bind();
    }
    
    ofSetColor(ofColor::white);
    meshWarped.drawFaces();
    
    if(bUseTexture == true) {
        meshTexture.unbind();
        ofDisableNormalizedTexCoords();
    }
    
    ofSetColor(ofColor::black);
    meshWarped.drawWireframe();
    
    camera.end();
    
    ofDisableDepthTest();
    ofSetColor(ofColor::white);
    
}
Пример #9
0
//--------------------------------------------------------------
void ofApp::draw(){

    ofSetColor(255);
    
    ofClear(0);
    ofPushMatrix();
    ofScale(2, 2);
    ofBackgroundGradient(ofColor(180), ofColor(70), OF_GRADIENT_CIRCULAR);
    ofPopMatrix();
    
    ofPushMatrix();
    ofTranslate(ofGetWidth() / 2, ofGetHeight() / 2);

    ofEnableAlphaBlending();
    ofEnableDepthTest();
    ofDisableNormalizedTexCoords();
    
    light.enable();

    // first
    litSphere.begin();
        displacement.draw();
    litSphere.end();

    // second
    litSphere02.begin();
        glPushMatrix();
        ofDrawSphere(0, 0, 180);
        ofPopMatrix();
    litSphere02.end();
//
//    light.disable();
    
    ofDisableDepthTest();
    ofEnableAlphaBlending();
    ofPopMatrix();
    ofDrawBitmapString(". , change sourse", ofPoint(20, 20));
}
Пример #10
0
void facade::draw()
{
	ofBackground(0, 0, 0);
	ofSetColor(255);

	//Particles
	if(doRender) {
		
		ofEnableAlphaBlending();
		
		// center scene
		glPushMatrix();
		glTranslatef(width/2, 0, -width / 3);
		glRotatef(rotation, 0, 1, 0);
		
		if(forceTimer) {
			float translateMax = forceTimer;
			glTranslatef(ofRandom(-translateMax, translateMax), ofRandom(-translateMax, translateMax), ofRandom(-translateMax, translateMax));
			forceTimer--;
		}

		
		/*
		// enable back-face culling (so we can see through the walls)
		glCullFace(GL_BACK);
		glEnable(GL_CULL_FACE);

		glEnable(GL_DEPTH_TEST);

		ofFill();
		
		glBegin(GL_QUADS);
		// draw right wall
		glColor3f(.1, 0.1, 0.1);		glVertex3f(width/2, height+1, width/2);
		glColor3f(0, 0, 0);				glVertex3f(width/2, -height, width/2);
		glColor3f(0.05, 0.05, 0.05);	glVertex3f(width/2, -height, -width/2);
		glColor3f(.15, 0.15, 0.15);		glVertex3f(width/2, height+1, -width/2);
		
		// back wall
		glColor3f(.1, 0.1, 0.1);		glVertex3f(width/2, height+1, -width/2);
		glColor3f(0, 0, 0);				glVertex3f(width/2, -height, -width/2);
		glColor3f(0.05, 0.05, 0.05);	glVertex3f(-width/2, -height, -width/2);
		glColor3f(.15, 0.15, 0.15);		glVertex3f(-width/2, height+1, -width/2);
		
		// left wall
		glColor3f(.1, 0.1, 0.1);		glVertex3f(-width/2, height+1, -width/2);
		glColor3f(0, 0, 0);				glVertex3f(-width/2, -height, -width/2);
		glColor3f(0.05, 0.05, 0.05);	glVertex3f(-width/2, -height, width/2);
		glColor3f(.15, 0.15, 0.15);		glVertex3f(-width/2, height+1, width/2);
		
		// front wall
		glColor3f(0.05, 0.05, 0.05);	glVertex3f(width/2, -height, width/2);
		glColor3f(.15, 0.15, 0.15);		glVertex3f(width/2, height+1, width/2);
		glColor3f(.1, 0.1, 0.1);		glVertex3f(-width/2, height+1, width/2);
		glColor3f(0, 0, 0);				glVertex3f(-width/2, -height, width/2);
		
		// floor
		glColor3f(.2, 0.2, 0.2);
		glVertex3f(width/2, height+1, width/2);
		glVertex3f(width/2, height+1, -width/2);
		glVertex3f(-width/2, height+1, -width/2);
		glVertex3f(-width/2, height+1, width/2);
		glEnd();
		glDisable(GL_DEPTH_TEST);
		glDisable(GL_CULL_FACE);
		*/

		//canvas
		glRotatef(rotation, 0, -1, 0);
		if(config::useCanvas) {
			canvas.begin();

			ofSetColor(255, canvasFade);
			canvasTrace.draw(0,0);
			glTranslatef(width/2, 0, -width / 3);
		}
		glRotatef(rotation, 0, 1, 0);

		//particles
		//glAlphaFunc(GL_GREATER, 0.5);


		if(currentSkeletonIndex>=0 && false){
			ofPolyline pLine;
			ofPushStyle();
			ofSetColor(255, 0, 0);
			ofNoFill();
			ofSetLineWidth(4);
			// HEAD
			pLine.clear();
			pLine.addVertex(bone[NUI_SKELETON_POSITION_HIP_CENTER]->getPosition().x, bone[NUI_SKELETON_POSITION_HIP_CENTER]->getPosition().y, bone[NUI_SKELETON_POSITION_HIP_CENTER]->getPosition().z);
			pLine.addVertex(bone[NUI_SKELETON_POSITION_SPINE]->getPosition().x, bone[NUI_SKELETON_POSITION_SPINE]->getPosition().y, bone[NUI_SKELETON_POSITION_SPINE]->getPosition().z);
			pLine.addVertex(bone[NUI_SKELETON_POSITION_SHOULDER_CENTER]->getPosition().x, bone[NUI_SKELETON_POSITION_SHOULDER_CENTER]->getPosition().y, bone[NUI_SKELETON_POSITION_SHOULDER_CENTER]->getPosition().z);
			pLine.addVertex(bone[NUI_SKELETON_POSITION_HEAD]->getPosition().x, bone[NUI_SKELETON_POSITION_HEAD]->getPosition().y, bone[NUI_SKELETON_POSITION_HEAD]->getPosition().z);
			pLine.draw();
	
			// BODY_LEFT
			pLine.clear();
			pLine.addVertex(bone[NUI_SKELETON_POSITION_SHOULDER_CENTER]->getPosition().x, bone[NUI_SKELETON_POSITION_SHOULDER_CENTER]->getPosition().y, bone[NUI_SKELETON_POSITION_SHOULDER_CENTER]->getPosition().z);
			pLine.addVertex(bone[NUI_SKELETON_POSITION_SHOULDER_LEFT]->getPosition().x, bone[NUI_SKELETON_POSITION_SHOULDER_LEFT]->getPosition().y, bone[NUI_SKELETON_POSITION_SHOULDER_LEFT]->getPosition().z);
			pLine.addVertex(bone[NUI_SKELETON_POSITION_ELBOW_LEFT]->getPosition().x, bone[NUI_SKELETON_POSITION_ELBOW_LEFT]->getPosition().y, bone[NUI_SKELETON_POSITION_ELBOW_LEFT]->getPosition().z);
			pLine.addVertex(bone[NUI_SKELETON_POSITION_WRIST_LEFT]->getPosition().x, bone[NUI_SKELETON_POSITION_WRIST_LEFT]->getPosition().y, bone[NUI_SKELETON_POSITION_WRIST_LEFT]->getPosition().z);
			pLine.addVertex(bone[NUI_SKELETON_POSITION_HAND_LEFT]->getPosition().x, bone[NUI_SKELETON_POSITION_HAND_LEFT]->getPosition().y, bone[NUI_SKELETON_POSITION_HAND_LEFT]->getPosition().z);
			pLine.draw();

			// BODY_RIGHT
			pLine.clear();
			pLine.addVertex(bone[NUI_SKELETON_POSITION_SHOULDER_CENTER]->getPosition().x, bone[NUI_SKELETON_POSITION_SHOULDER_CENTER]->getPosition().y, bone[NUI_SKELETON_POSITION_SHOULDER_CENTER]->getPosition().z);
			pLine.addVertex(bone[NUI_SKELETON_POSITION_SHOULDER_RIGHT]->getPosition().x, bone[NUI_SKELETON_POSITION_SHOULDER_RIGHT]->getPosition().y, bone[NUI_SKELETON_POSITION_SHOULDER_RIGHT]->getPosition().z);
			pLine.addVertex(bone[NUI_SKELETON_POSITION_ELBOW_RIGHT]->getPosition().x, bone[NUI_SKELETON_POSITION_ELBOW_RIGHT]->getPosition().y, bone[NUI_SKELETON_POSITION_ELBOW_RIGHT]->getPosition().z);
			pLine.addVertex(bone[NUI_SKELETON_POSITION_WRIST_RIGHT]->getPosition().x, bone[NUI_SKELETON_POSITION_WRIST_RIGHT]->getPosition().y, bone[NUI_SKELETON_POSITION_WRIST_RIGHT]->getPosition().z);
			pLine.addVertex(bone[NUI_SKELETON_POSITION_HAND_RIGHT]->getPosition().x, bone[NUI_SKELETON_POSITION_HAND_RIGHT]->getPosition().y, bone[NUI_SKELETON_POSITION_HAND_RIGHT]->getPosition().z);
			pLine.draw();

			// LEG_LEFT
			pLine.clear();
			pLine.addVertex(bone[NUI_SKELETON_POSITION_HIP_CENTER]->getPosition().x, bone[NUI_SKELETON_POSITION_HIP_CENTER]->getPosition().y, bone[NUI_SKELETON_POSITION_HIP_CENTER]->getPosition().z);
			pLine.addVertex(bone[NUI_SKELETON_POSITION_HIP_LEFT]->getPosition().x, bone[NUI_SKELETON_POSITION_HIP_LEFT]->getPosition().y, bone[NUI_SKELETON_POSITION_HIP_LEFT]->getPosition().z);
			pLine.addVertex(bone[NUI_SKELETON_POSITION_KNEE_LEFT]->getPosition().x, bone[NUI_SKELETON_POSITION_KNEE_LEFT]->getPosition().y, bone[NUI_SKELETON_POSITION_KNEE_LEFT]->getPosition().z);
			pLine.addVertex(bone[NUI_SKELETON_POSITION_ANKLE_LEFT]->getPosition().x, bone[NUI_SKELETON_POSITION_ANKLE_LEFT]->getPosition().y, bone[NUI_SKELETON_POSITION_ANKLE_LEFT]->getPosition().z);
			pLine.addVertex(bone[NUI_SKELETON_POSITION_FOOT_LEFT]->getPosition().x, bone[NUI_SKELETON_POSITION_FOOT_LEFT]->getPosition().y, bone[NUI_SKELETON_POSITION_FOOT_LEFT]->getPosition().z);
			pLine.draw();

			// LEG_RIGHT
			pLine.clear();
			pLine.addVertex(bone[NUI_SKELETON_POSITION_HIP_CENTER]->getPosition().x, bone[NUI_SKELETON_POSITION_HIP_CENTER]->getPosition().y, bone[NUI_SKELETON_POSITION_HIP_CENTER]->getPosition().z);
			pLine.addVertex(bone[NUI_SKELETON_POSITION_HIP_RIGHT]->getPosition().x, bone[NUI_SKELETON_POSITION_HIP_RIGHT]->getPosition().y, bone[NUI_SKELETON_POSITION_HIP_RIGHT]->getPosition().z);
			pLine.addVertex(bone[NUI_SKELETON_POSITION_KNEE_RIGHT]->getPosition().x, bone[NUI_SKELETON_POSITION_KNEE_RIGHT]->getPosition().y, bone[NUI_SKELETON_POSITION_KNEE_RIGHT]->getPosition().z);
			pLine.addVertex(bone[NUI_SKELETON_POSITION_ANKLE_RIGHT]->getPosition().x, bone[NUI_SKELETON_POSITION_ANKLE_RIGHT]->getPosition().y, bone[NUI_SKELETON_POSITION_ANKLE_RIGHT]->getPosition().z);
			pLine.addVertex(bone[NUI_SKELETON_POSITION_FOOT_RIGHT]->getPosition().x, bone[NUI_SKELETON_POSITION_FOOT_RIGHT]->getPosition().y, bone[NUI_SKELETON_POSITION_FOOT_RIGHT]->getPosition().z);
			pLine.draw();
			ofPopStyle();
		}

		ofEnableNormalizedTexCoords();
		ballImage.getTextureReference().bind();
		msa::physics::Particle3D *p;
		float alpha;
		int red, green, blue;
		for(int i=0; i<physics.numberOfParticles(); i++) {
			p = physics.getParticle(i);
			if(!p->isFixed()){
				
				red = particleColor.r*colorSpaceVariation + ofMap(p->getPosition().x, -width/2, width/2, 0, 255-(255*colorSpaceVariation));
				green = particleColor.g*colorSpaceVariation + ofMap(p->getPosition().y, -height, height, 0, 255-(255*colorSpaceVariation));
				blue = particleColor.b*colorSpaceVariation + ofMap(p->getPosition().z, -width/2, width/2, 0, 255-(255*colorSpaceVariation));
					
				// draw ball
				glPushMatrix();
					glTranslatef(p->getPosition().x, p->getPosition().y, p->getPosition().z);
					glRotatef(180-rotation, 0, 1, 0);
					ofSetColor(red, green, blue);
					drawParticle(p->getRadius());
				glPopMatrix();
			
				//draw shadow
				alpha = ofMap(p->getPosition().y, -height * 1.5, height, 0, 1);
				if(alpha>0) {
					glPushMatrix();
						glTranslatef(p->getPosition().x, height, p->getPosition().z);
						glRotatef(-90, 1, 0, 0);
						ofSetColor(red, green, blue, alpha * alpha * alpha * alpha * 255);
						drawParticle(p->getRadius() * alpha);
					glPopMatrix();
				}
			}
			
		}
		ballImage.getTextureReference().unbind();
		ofDisableNormalizedTexCoords();

		if(config::useCanvas) {
			canvas.end();
		}
		glPopMatrix();

		
		
		
		if(config::useCanvas) {
			canvasTrace.begin();

				/*glColorMask(FALSE, FALSE, FALSE, TRUE);
				glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
				glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
				glColorMask(TRUE, TRUE, TRUE, TRUE);*/

				ofSetColor(255);
				canvas.draw(0,0);
			canvasTrace.end();
		
			canvasTrace.draw(0,canvasY);
		
			canvas.begin();
				ofClear(0);
			canvas.end();
		}
		
		if(blackout>0){
			ofSetColor(0,0,0,blackout);
			ofRect(0,0,0,width, height);
		}

		ofDisableAlphaBlending();
	}

	


	/*
	// HEAD
	pLine.clear();
	pLine.addVertex(src[NUI_SKELETON_POSITION_HIP_CENTER].x, src[NUI_SKELETON_POSITION_HIP_CENTER].y);
	pLine.addVertex(src[NUI_SKELETON_POSITION_SPINE].x, src[NUI_SKELETON_POSITION_SPINE].y);
	pLine.addVertex(src[NUI_SKELETON_POSITION_SHOULDER_CENTER].x, src[NUI_SKELETON_POSITION_SHOULDER_CENTER].y);
	pLine.addVertex(src[NUI_SKELETON_POSITION_HEAD].x, src[NUI_SKELETON_POSITION_HEAD].y);
	pLine.draw();
	
	// BODY_LEFT
	pLine.clear();
	pLine.addVertex(src[NUI_SKELETON_POSITION_SHOULDER_CENTER].x, src[NUI_SKELETON_POSITION_SHOULDER_CENTER].y);
	pLine.addVertex(src[NUI_SKELETON_POSITION_SHOULDER_LEFT].x, src[NUI_SKELETON_POSITION_SHOULDER_LEFT].y);
	pLine.addVertex(src[NUI_SKELETON_POSITION_ELBOW_LEFT].x, src[NUI_SKELETON_POSITION_ELBOW_LEFT].y);
	pLine.addVertex(src[NUI_SKELETON_POSITION_WRIST_LEFT].x, src[NUI_SKELETON_POSITION_WRIST_LEFT].y);
	pLine.addVertex(src[NUI_SKELETON_POSITION_HAND_LEFT].x, src[NUI_SKELETON_POSITION_HAND_LEFT].y);
	pLine.draw();

	// BODY_RIGHT
	pLine.clear();
	pLine.addVertex(src[NUI_SKELETON_POSITION_SHOULDER_CENTER].x, src[NUI_SKELETON_POSITION_SHOULDER_CENTER].y);
	pLine.addVertex(src[NUI_SKELETON_POSITION_SHOULDER_RIGHT].x, src[NUI_SKELETON_POSITION_SHOULDER_RIGHT].y);
	pLine.addVertex(src[NUI_SKELETON_POSITION_ELBOW_RIGHT].x, src[NUI_SKELETON_POSITION_ELBOW_RIGHT].y);
	pLine.addVertex(src[NUI_SKELETON_POSITION_WRIST_RIGHT].x, src[NUI_SKELETON_POSITION_WRIST_RIGHT].y);
	pLine.addVertex(src[NUI_SKELETON_POSITION_HAND_RIGHT].x, src[NUI_SKELETON_POSITION_HAND_RIGHT].y);
	pLine.draw();

	// LEG_LEFT
	pLine.clear();
	pLine.addVertex(src[NUI_SKELETON_POSITION_HIP_CENTER].x, src[NUI_SKELETON_POSITION_HIP_CENTER].y);
	pLine.addVertex(src[NUI_SKELETON_POSITION_HIP_LEFT].x, src[NUI_SKELETON_POSITION_HIP_LEFT].y);
	pLine.addVertex(src[NUI_SKELETON_POSITION_KNEE_LEFT].x, src[NUI_SKELETON_POSITION_KNEE_LEFT].y);
	pLine.addVertex(src[NUI_SKELETON_POSITION_ANKLE_LEFT].x, src[NUI_SKELETON_POSITION_ANKLE_LEFT].y);
	pLine.addVertex(src[NUI_SKELETON_POSITION_FOOT_LEFT].x, src[NUI_SKELETON_POSITION_FOOT_LEFT].y);
	pLine.draw();

	// LEG_RIGHT
	pLine.clear();
	pLine.addVertex(src[NUI_SKELETON_POSITION_HIP_CENTER].x, src[NUI_SKELETON_POSITION_HIP_CENTER].y);
	pLine.addVertex(src[NUI_SKELETON_POSITION_HIP_RIGHT].x, src[NUI_SKELETON_POSITION_HIP_RIGHT].y);
	pLine.addVertex(src[NUI_SKELETON_POSITION_KNEE_RIGHT].x, src[NUI_SKELETON_POSITION_KNEE_RIGHT].y);
	pLine.addVertex(src[NUI_SKELETON_POSITION_ANKLE_RIGHT].x, src[NUI_SKELETON_POSITION_ANKLE_RIGHT].y);
	pLine.addVertex(src[NUI_SKELETON_POSITION_FOOT_RIGHT].x, src[NUI_SKELETON_POSITION_FOOT_RIGHT].y);
	pLine.draw();*/

	

	//glDisable(GL_BLEND);

	
	if(showFPS)
	{
		glColor4f(1, 1, 1, 1);
		ofDrawBitmapString(" FPS: " + ofToString(ofGetFrameRate(), 2)
					+ " | particles: " + ofToString(physics.numberOfParticles(), 2)
					+ " | springs: " + ofToString(physics.numberOfSprings(), 2)
				   , 20, 15);
	}
}
Пример #11
0
//--------------------------------------------------------------
void testApp::draw() {
	if(doRender) {
		
		ofEnableAlphaBlending();
		glEnable(GL_DEPTH_TEST);
		
		glPushMatrix();
		
		glTranslatef(width/2, 0, -width / 3);		// center scene
		static float rot = 0;
		glRotatef(rot, 0, 1, 0);			// rotate scene
		rot += rotSpeed;						// slowly increase rotation (to get a good 3D view)
		
		if(forceTimer) {
			float translateMax = forceTimer;
			glTranslatef(ofRandom(-translateMax, translateMax), ofRandom(-translateMax, translateMax), ofRandom(-translateMax, translateMax));
			forceTimer--;
		}
		
		
		glDisable(GL_LIGHTING);
		glBegin(GL_QUADS);
		// draw right wall
		glColor3f(.9, 0.9, 0.9);		glVertex3f(width/2, height+1, width/2);
		glColor3f(1, 1, 1);				glVertex3f(width/2, -height, width/2);
		glColor3f(0.95, 0.95, 0.95);	glVertex3f(width/2, -height, -width/2);
		glColor3f(.85, 0.85, 0.85);		glVertex3f(width/2, height+1, -width/2);
		
		// back wall
		glColor3f(.9, 0.9, 0.9);		glVertex3f(width/2, height+1, -width/2);
		glColor3f(1, 1, 1);				glVertex3f(width/2, -height, -width/2);
		glColor3f(0.95, 0.95, 0.95);	glVertex3f(-width/2, -height, -width/2);
		glColor3f(.85, 0.85, 0.85);		glVertex3f(-width/2, height+1, -width/2);
		
		// left wall
		glColor3f(.9, 0.9, 0.9);		glVertex3f(-width/2, height+1, -width/2);
		glColor3f(1, 1, 1);				glVertex3f(-width/2, -height, -width/2);
		glColor3f(0.95, 0.95, 0.95);	glVertex3f(-width/2, -height, width/2);
		glColor3f(.85, 0.85, 0.85);		glVertex3f(-width/2, height+1, width/2);
		
		// front wall
		glColor3f(0.95, 0.95, 0.95);	glVertex3f(width/2, -height, width/2);
		glColor3f(.85, 0.85, 0.85);		glVertex3f(width/2, height+1, width/2);
		glColor3f(.9, 0.9, 0.9);		glVertex3f(-width/2, height+1, width/2);
		glColor3f(1, 1, 1);				glVertex3f(-width/2, -height, width/2);
		
		// floor
		glColor3f(.8, 0.8, 0.8);
		glVertex3f(width/2, height+1, width/2);
		glVertex3f(width/2, height+1, -width/2);
		glVertex3f(-width/2, height+1, -width/2);
		glVertex3f(-width/2, height+1, width/2);
		glEnd();
		
//		glEnable(GL_LIGHTING);
		
		// draw springs
		glColor4f(0.5, 0.5, 0.5, 0.5);
		for(int i=0; i<physics.numberOfSprings(); i++) {
			ofxMSASpring *spring = (ofxMSASpring *) physics.getSpring(i);
			ofxMSAParticle *a = spring->getOneEnd();
			ofxMSAParticle *b = spring->getTheOtherEnd();
			ofPoint vec = b->getPosition() - a->getPosition();
			float dist = msaLength(vec);
			float angle = acos( vec.z / dist ) * RAD_TO_DEG;
			if(vec.z <= 0 ) angle = -angle;
			float rx = -vec.y * vec.z;
			float ry =  vec.x * vec.z;
			
			glPushMatrix();
			glTranslatef(a->getX(), a->getY(), a->getZ());
			glRotatef(angle, rx, ry, 0.0);
			float size  = ofMap(spring->strength, SPRING_MIN_STRENGTH, SPRING_MAX_STRENGTH, SPRING_MIN_WIDTH, SPRING_MAX_WIDTH);
			
			glScalef(size, size, dist);
			glTranslatef(0, 0, 0.5);
			glutSolidCube(1);
			glPopMatrix();
		}
		

		
		// draw particles
		glAlphaFunc(GL_GREATER, 0.5);
		
		ofEnableNormalizedTexCoords();
		ballImage.getTextureReference().bind();
		for(int i=0; i<physics.numberOfParticles(); i++) {
			ofxMSAParticle *p = physics.getParticle(i);
			if(p->isFixed()) glColor4f(1, 0, 0, 1);
			else glColor4f(1, 1, 1, 1);

			glEnable(GL_ALPHA_TEST);
			
			// draw ball
			glPushMatrix();
			glTranslatef(p->getX(), p->getY(), p->getZ());
			glRotatef(180-rot, 0, 1, 0);
//			glutSolidSphere(p->getRadius(), 2, 2);
//			ofCircle(0, 0, p->getRadius());
//			ballImage.draw(0, 0, p->getRadius()*2, p->getRadius()*2);
			glBegin(GL_QUADS);
			glTexCoord2f(0, 0); glVertex2f(-p->getRadius(), -p->getRadius());
			glTexCoord2f(1, 0); glVertex2f(p->getRadius(), -p->getRadius());
			glTexCoord2f(1, 1); glVertex2f(p->getRadius(), p->getRadius());
			glTexCoord2f(0, 1); glVertex2f(-p->getRadius(), p->getRadius());
			glEnd();
			glPopMatrix();
			
			glDisable(GL_ALPHA_TEST);
			
			float alpha = ofMap(p->getY(), -height * 1.5, height, 0, 1);
			if(alpha>0) {
				glPushMatrix();
				glTranslatef(p->getX(), height, p->getZ());
				glRotatef(-90, 1, 0, 0);
				glColor4f(0, 0, 0, alpha * alpha * alpha * alpha);
//				ofCircle(0, 0, p->getRadius());
				float r = p->getRadius() * alpha;
				glBegin(GL_QUADS);
				glTexCoord2f(0, 0); glVertex2f(-r, -r);
				glTexCoord2f(1, 0); glVertex2f(r, -r);
				glTexCoord2f(1, 1); glVertex2f(r, r);
				glTexCoord2f(0, 1); glVertex2f(-r, r);
				glEnd();
				glPopMatrix();
			}
			
		}
		ballImage.getTextureReference().unbind();
		ofDisableNormalizedTexCoords();
		
		
		glPopMatrix();
	}
	
	glDisable(GL_BLEND);
	glDisable(GL_DEPTH_TEST);
	glDisable(GL_LIGHTING);
	glColor4f(0, 0, 0, 1);
	ofDrawBitmapString( " FPS: " + ofToString(ofGetFrameRate(), 2)
					   + " | Number of particles: " + ofToString(physics.numberOfParticles(), 2)
					   + " | Number of springs: " + ofToString(physics.numberOfSprings(), 2)
					   + " | Mouse Mass: " + ofToString(mouseNode.getMass(), 2)
					   , 20, 15);
	
	
	
	
}