Пример #1
0
//--------------------------------------------------------------
void ofApp::mouseDragged(int x, int y, int button){
	if (selectedOscilator>-1) {//when an oscillator is clicked and dragged it's speed (freq) and amplitude are changed.
		//the following lines do so.
		if(bSelectedOscHor==true){
			horizontalOscilators[selectedOscilator].freq += 0.1f * (ofGetPreviousMouseX() - ofGetMouseX())/ float(ofGetWidth());
			horizontalOscilators[selectedOscilator].amplitude += ofGetMouseY() - ofGetPreviousMouseY();	
		}else if (bSelectedOscVert==true) {
			verticalOscilators[selectedOscilator].freq += 0.1f * (ofGetPreviousMouseY() - ofGetMouseY())/ float(ofGetHeight());
			verticalOscilators[selectedOscilator].amplitude += ofGetMouseX() - ofGetPreviousMouseX(); 
		}
	}else if (bScaleMouse) {
		scale += float(ofGetMouseY()-ofGetPreviousMouseY())/ofGetHeight();
	}
}
Пример #2
0
//--------------------------------------------------------------
void testApp::mouseDragged(int x, int y, int button){
    if (button==0){
        ofQuaternion qy((x-ofGetPreviousMouseX()), ofVec3f(0,1,0));
        ofQuaternion qx((y-ofGetPreviousMouseY()), ofVec3f(1,0,0));
        qrot *= qx*qy;
    }
    
    if (button==2){
        ofQuaternion qz((x-ofGetPreviousMouseX()), ofVec3f(0,0,1));
        qrot *= qz;
        
        scale += (float)(ofGetPreviousMouseY()-y)/(ofGetWindowHeight()/2);
        if (scale<0) scale = 0.0001;
    }
}
Пример #3
0
//--------------------------------------------------------------
void testApp::update() {
	ofVec2f mouse(ofGetMouseX(), ofGetMouseY());
	ofVec2f mouseVec(ofGetPreviousMouseX()-ofGetMouseX(), ofGetPreviousMouseY()-ofGetMouseY());
	mouseVec.limit(10.0);
	
	for (int i=0; i<NUM_BILLBOARDS; i++) {
		ofSeedRandom(i);
		if(mouse.distance(pos[i]) < ofRandom(100, 200)) {
			vel[i] -= mouseVec; 
		}
		
		pos[i] += vel[i];
		vel[i] *= 0.84f;
		
		if(pos[i].x < 0) pos[i].x = ofGetWidth();
		if(pos[i].x > ofGetWidth()) pos[i].x = 0;
		if(pos[i].y < 0) pos[i].y = ofGetHeight();
		if(pos[i].y > ofGetHeight()) pos[i].y = 0;
		
		ofVec2f center(ofGetWidth()/2, ofGetHeight()/2);
		ofVec2f frc = home[i] - pos[i];
		if(frc.length() > 20.0) {
			frc.normalize();
			frc *= 0.84;
			vel[i] += frc;
		}
		
		// get the 2d heading
		float angle = (float)atan2(-vel[i].y, vel[i].x) + PI;
		rotations[i] = (angle * -1.0);
	}
}
Пример #4
0
void scrollBar::mouseDragged(ofMouseEventArgs &e){
    mousePositionX = e.x;
    mousePositionY = e.y;
    
    ofVec3f mouse = ofVec3f(e.x, e.y,0);
    ofVec3f mouseLast = ofVec3f(ofGetPreviousMouseX(),ofGetPreviousMouseY(),0);
    
    ofVec3f diffVec = ofVec3f(0,0,0);
    
    if (isScrollBarVisible && composer->isDraggingGrip()) {
        diffVec.y = mouseLast.y - mouse.y;
        
        // Move the grip according to the mouse displacement
        int dy = e.y - mousePreviousY;
        mousePreviousY = e.y;
        gripRectangle.y += dy;
        
    }
    if(isHScrollBarVisible && composer->isDraggingHGrip()){
        diffVec.x = mouseLast.x - mouse.x;
        
        // Move the grip according to the mouse displacement
        int dx = e.x - mousePreviousX;
        mousePreviousX = e.x;
        hGripRectangle.x += dx;
    }

    updateScrollBar(diffVec);
    updateHScrollBar(diffVec);

}
Пример #5
0
 void resetDrawSettings()
 {
     m_inSetup = false;
     fill(m_defaultFillColor.getHex());
     stroke(m_defaultStrokeColor.getHex());
     strokeWeight(m_defaultStrokeWeight);
     m_hasFill = m_defaultHasFill;
     m_hasStroke = m_defaultHasStroke;
     ofEnableBlendMode(OF_BLENDMODE_ALPHA);
     smooth(2);
     width = ofGetWidth();
     height = ofGetHeight();
     pmouseX = ofGetPreviousMouseX();
     pmouseY = ofGetPreviousMouseY();
     keyPressed = ofGetKeyPressed();
     mousePressed = ofGetMousePressed();
     mouseButton = NONE;
     if( ofGetMousePressed(0) )
         mouseButton = LEFT;
     else if(ofGetMousePressed(1))
         mouseButton = RIGHT;
     
     
     ofSetCircleResolution(100);
     ofSetCurveResolution(100);
 }
Пример #6
0
void testApp::mouseDragged(int x, int y, int button){
    if(hagoZoom){
        ofVec3f mouse = ofVec3f(x, y,0);
        ofVec3f mouseLast = ofVec3f(ofGetPreviousMouseX(),ofGetPreviousMouseY(),0);
        float dify = mouse.y - mouseLast.y;
        scale += dify*SCALE_SENSITIVITY;
        cam.setScale(scale);
    }
}
Пример #7
0
//--------------------------------------------------------------
void ofApp::mouseDragged(int x, int y, int button){
    
    ofVec2f vel;
    vel.x = x - ofGetPreviousMouseX();
    vel.y = y - ofGetPreviousMouseY();
    Particle particle(ofVec2f(x, y), vel*0.3);
    particleList.push_back(particle);

}
Пример #8
0
//--------------------------------------------------------------
void testApp::draw(){
	ofBackground(0);
	
	string s = string("") + 
	"\n" + 
	"Purple boxes (4 of them) are generic nodes with simple circular motion, linked in a hierarchy (with ofNode::setParent).\n" + 
	"Yellow boxes (2 of them) are cameras. You are looking through one of them so can only see one box on screen.\n" + 
	"\n" + 
	"KEYS:\n" + 
	"\n" + 
	"z reset transforms\n" + 
	"\n" + 
	"v switch camera to view: " + ofToString(camToView) + "\n" +
	"\n" + 
	
	"o toggle mouse orbit for cam\n" + 
	
	"\n" + 
	"c switch camera to configure: " + ofToString(camToConfigure) + "\n" +
	" t cycle lookat\n" + 
	" p cycle parent\n" +
	" LEFT pan left\n" + 
	" RIGHT pan right\n" + 
	" UP tilt up\n" + 
	" DOWN tilt down\n" + 
	" , roll left\n" + 
	" . roll right\n" + 
	" a truck left\n" + 
	" d truck right\n" + 
	" w dolly forward\n" + 
	" s dolly backward\n" + 
	" r boom up\n" + 
	" f boom down\n";
	glDisable(GL_CULL_FACE);
	ofSetColor(255);
	ofDisableLighting();
	ofDrawBitmapString(s, ofPoint(20, 20));
	
	glEnable(GL_CULL_FACE);
	ofEnableLighting();
	// update camera transforms
	for(int i=0; i<kNumCameras; i++) {
		
		// lookat node if it has one
		if(lookatIndex[i] >= 0) cam[i].lookAt(testNodes[lookatIndex[i]]);
		
		// mouse orbit camera
		if(doMouseOrbit[i] && ofGetMousePressed(0)) {
			static float lon = 0;
			static float lat = 0;
			
			lon = ofClamp(lon + mouseX - ofGetPreviousMouseX(), -180, 180);
			lat = ofClamp(lat + mouseY - ofGetPreviousMouseY(), -90, 90);
			
			if(lookatIndex[i] < 0) {
				cam[i].orbit(lon, lat, orbitRadius);
			} else {
				cam[i].orbit(lon, lat, orbitRadius, testNodes[lookatIndex[1]]);
			}
		}
		
	} 
	
	// activate camera
	cam[camToView].begin();
	
	
	// draw world axis
	ofDrawAxis(100);
	
	// draw testNodes
	for(int i=0; i<kNumTestNodes; i++) {
		ofSetColor(255, 128, 255);
		testNodes[i].draw();
	}
	
	// draw cameras
	for(int i=0; i<kNumCameras; i++) {
		ofSetColor(255, 255, 0);
		cam[i].draw();
		
		// draw line from cam to its lookat
		if(lookatIndex[i] >= 0) {
			ofSetColor(0, 255, 255);
			glBegin(GL_LINES);
			ofVec3f v1 = cam[i].getGlobalPosition();
			ofVec3f v2 = testNodes[lookatIndex[i]].getGlobalPosition();
			glVertex3f(v1.x, v1.y, v1.z);
			glVertex3f(v2.x, v2.y, v2.z);
			glEnd();
		}
		
		// draw line from cam to its parent
		if(parentIndex[i] >= 0) {
			ofSetColor(255, 255, 0);
			glBegin(GL_LINES);
			ofVec3f v1 = cam[i].getGlobalPosition();
			ofVec3f v2 = testNodes[parentIndex[i]].getGlobalPosition();
			glVertex3f(v1.x, v1.y, v1.z);
			glVertex3f(v2.x, v2.y, v2.z);
			glEnd();
		}
	}
	
	// restore view to previous state (default openFrameworks view)
	cam[camToView].end();
}
Пример #9
0
//--------------------------------------------------------------
void ofApp::mouseDragged(int x, int y, int button){
    float mouseDist = ofGetPreviousMouseX() - x;
    float deltaDegrees = ofMap(mouseDist, 0, 10, 0, 1);
    degrees += deltaDegrees;
}
Пример #10
0
void ofxMPMFluid::update(){
	// Important: can't exceed maxNParticles!

	numParticles = MIN(numParticles, maxNumParticles);
	
	//-------------------------
	// Clear the grid. Necessary to begin the simulation.
	for (int i=0; i<gridSizeX; i++) {
		for (int j=0; j<gridSizeY; j++) {
			grid[i][j]->clear();
		}
	}
	
	numActiveNodes = 0; 
		
	long t0 = ofGetElapsedTimeMillis();
	//-------------------------
	// Particles pass 1
	float phi;
	int pcxTmp, pcyTmp;
	for (int ip=0; ip<numParticles; ip++) {
		
		ofxMPMParticle *p = particles[ip];
		
		int pcx = p->cx = (int)(p->x - 0.5F);
		int pcy = p->cy = (int)(p->y - 0.5F);
		
		float *px = p->px;
		float *py = p->py;
		float *gx = p->gx;
		float *gy = p->gy;
		float pu  = p->u;
		float pv  = p->v;
		p->pu = pu;
		p->pv = pv;
		
		
		// N.B.: The constants below are not playthings.
		float x = (float) p->cx - p->x;
		px[0] = (0.5F * x * x + 1.5F * x) + 1.125f;
		gx[0] = x + 1.5F;
		x++;
		px[1] = -x * x + 0.75F;
		gx[1] = -2.0F * x;
		x++;
		px[2] = (0.5F * x * x - 1.5F * x) + 1.125f;
		gx[2] = x - 1.5F;
		
		float y = (float) p->cy - p->y;
		py[0] = (0.5F * y * y + 1.5F * y) + 1.125f;
		gy[0] = y + 1.5F;
		y++;
		py[1] = -y * y + 0.75F;
		gy[1] = -2.0F * y;
		y++;
		py[2] = (0.5F * y * y - 1.5F * y) + 1.125f;
		gy[2] = y - 1.5F;
		
		
		int pcxi, pcyj;
		for (int i=0; i<3; i++) {
			pcxi = pcx+i;
			
			if ((pcxi >= 0) && (pcxi < gridSizeX)){ 
				vector<ofxMPMNode*>& nrow = grid[pcxi]; // potential for array index out of bounds here if simulation explodes.
				float pxi = px[i];
				float gxi = gx[i];
				
				for (int j=0; j<3; j++) {
					pcyj = pcy+j;
					
					if ((pcyj >= 0) && (pcyj < gridSizeY)){
						ofxMPMNode *n = nrow[pcyj]; // potential for array index out of bounds here if simulation explodes.
						
						if (!n->active) {
							n->active = true;
							activeNodes[numActiveNodes] = n;
							numActiveNodes++;
						}
						phi    = pxi * py[j];
						n->m  += phi;
						n->gx += gxi * py[j];
						n->gy += pxi * gy[j];
						n->u  += phi * pu;
						n->v  += phi * pv;
					}
				}
			}
		}
	}
	
	
	for (int ni=0; ni<numActiveNodes; ni++) {
		ofxMPMNode *n = activeNodes[ni]; 
		if (n->m > 0.0) {
			n->u /= n->m;
			n->v /= n->m;
		}
	}
	
	
	long t1 = ofGetElapsedTimeMillis();
	//-------------------------
	// Particles pass 2
	float stiffnessBulk  = stiffness * bulkViscosity;	
	int nBounced = 0; 
	
	for (int ip=0; ip<numParticles; ip++) {
		ofxMPMParticle *p = particles[ip];
		float *px = p->px;
		float *py = p->py;
		float *gx = p->gx;
		float *gy = p->gy;
		int   pcy = p->cy;
		int   pcx = p->cx;
		
		float dudx = 0.0F;
		float dudy = 0.0F;
		float dvdx = 0.0F;
		float dvdy = 0.0F;
		
		float gxi, pxi;
		float gxf, gyf;
		
		int pcxi;
		for (int i=0; i<3; i++) {
			
			vector<ofxMPMNode*>& nrow = grid[pcx+i];
			gxi = gx[i];
			pxi = px[i];
			
			for (int j=0; j<3; j++){
				ofxMPMNode *nj = nrow[pcy + j]; 
				gxf   =   gxi * py[j];
				gyf   =   pxi * gy[j];
				dudx += nj->u * gxf;
				dudy += nj->u * gyf;
				dvdx += nj->v * gxf;
				dvdy += nj->v * gyf;
			}
		} 

		float w1  = dudy - dvdx;
		float wT0 = w1 * p->T01;
		float wT1 = 0.5F * w1 * (p->T00 - p->T11);
		float D00 = dudx;
		float D01 = 0.5F * (dudy + dvdx);
		float D11 = dvdy;
		float trace = 0.5F * (D00 + D11);
		D00 -= trace;
		D11 -= trace;
		
		p->T00 += (-wT0 + D00) - yieldRate * p->T00;
		p->T01 += ( wT1 + D01) - yieldRate * p->T01;
		p->T11 += ( wT0 + D11) - yieldRate * p->T11;
		
		// here's our protection against exploding simulations...
		float norma = p->T00 * p->T00 + 2.0F * p->T01 * p->T01 + p->T11 * p->T11;
		if (norma > 10.0F) {
			p->T00 = p->T01 = p->T11 = 0.0F;
		}
		
		int cx0 = (int) p->x;
		int cy0 = (int) p->y;
		int cx1 = cx0 + 1;
		int cy1 = cy0 + 1;
		ofxMPMNode *n00  = grid[cx0][cy0];
		ofxMPMNode *n01  = grid[cx0][cy1];
		ofxMPMNode *n10  = grid[cx1][cy0];
		ofxMPMNode *n11  = grid[cx1][cy1];
		
		float p00 = n00->m;
		float x00 = n00->gx;
		float y00 = n00->gy;
		float p01 = n01->m;
		float x01 = n01->gx;
		float y01 = n01->gy;
		float p10 = n10->m;
		float x10 = n10->gx;
		float y10 = n10->gy;
		float p11 = n11->m;
		float x11 = n11->gx;
		float y11 = n11->gy;
		
		float pdx =  p10 - p00;
		float pdy =  p01 - p00;
		float C20 =  3.0F * pdx - x10 - 2.0F * x00;
		float C02 =  3.0F * pdy - y01 - 2.0F * y00;
		float C30 = -2.0F * pdx + x10 + x00;
		float C03 = -2.0F * pdy + y01 + y00;
		float csum1 = p00 + y00 + C02 + C03;
		float csum2 = p00 + x00 + C20 + C30;
		float C21 =   3.0F * p11 - 2.0F * x01 - x11 - 3.0F * csum1  - C20;
		float C31 = (-2.0F * p11 +        x01 + x11 + 2.0F * csum1) - C30;
		float C12 =   3.0F * p11 - 2.0F * y10 - y11 - 3.0F * csum2  - C02;
		float C13 = (-2.0F * p11 +        y10 + y11 + 2.0F * csum2) - C03;
		float C11 = x01 - C13 - C12 - x00;
		
		float u1 = p->x - (float)cx0;
		float u2 = u1 * u1;
		float u3 = u1 * u2;
		float v1 = p->y - (float)cy0;
		float v2 = v1 * v1;
		float v3 = v1 * v2;
		float density = 
		p00 + 
		x00 * u1 + 
		y00 * v1 + 
		C20 * u2 + 
		C02 * v2 + 
		C30 * u3 + 
		C03 * v3 + 
		C21 * u2 * v1 + 
		C31 * u3 * v1 +
		C12 * u1 * v2 + 
		C13 * u1 * v3 + 
		C11 * u1 * v1 ;
		
		
		float DS = densitySetting; 
		if (bGradient){
			// Just for yuks, a spatially varying density function
			DS = densitySetting * ( powf(p->x / (float) gridSizeX, 4.0) );
		} 
		
		float pressure = (stiffness / max (1.0F, DS)) * (density - DS);
		if (pressure > 2.0F) { 
			pressure = 2.0F;
		}
		
		p->d = 1.0/MAX(0.001, density);
		
		// COLLISIONS-1
		// Determine if there has been a collision with the wall. 
		float fx = 0.0F;
		float fy = 0.0F;
		bool bounced = false;
		
		if (p->x < 3.0F) {
			fx += 3.0F - p->x;
			bounced = true;
		} else if (p->x > (float)(gridSizeX - 3)) {
			fx += (gridSizeX - 3.0) - p->x;
			bounced = true;
		}
		
		if (p->y < 3.0F) {
			fy += 3.0F - p->y;
			bounced = true;
		} else if (p->y > (float)(gridSizeY - 3)) {
			fy += (gridSizeY - 3.0) - p->y;
			bounced = true;
		}
		

		// Interact with a simple demonstration obstacle.
		// Note: an accurate obstacle implementation would also need to implement
		// some velocity fiddling as in the section labeled "COLLISIONS-2" below.
		// Otherwise, this obstacle is "soft"; particles can enter it slightly. 
		if (bDoObstacles && obstacles.size() > 0){
			for ( int i = 0; i<obstacles.size(); i++){
			// circular obstacle
			float oR  = obstacles[i]->radius;
			float oR2 = obstacles[i]->radius2;
			float odx = obstacles[i]->cx - p->x;
			float ody = obstacles[i]->cy - p->y;
			float oD2 = odx*odx + ody*ody;
			if (oD2 < oR2){
				float oD = sqrtf(oD2);
				float dR = oR-oD;
				fx -= dR * (odx/oD); 
				fy -= dR * (ody/oD); 
				bounced = true;
			}
            }
		}
		
		trace *= stiffnessBulk;
		float T00 = elasticity * p->T00 + viscosity * D00 + pressure + trace;
		float T01 = elasticity * p->T01 + viscosity * D01;
		float T11 = elasticity * p->T11 + viscosity * D11 + pressure + trace;
		float dx, dy;
		
		if (bounced){
			for (int i=0; i<3; i++) {
				vector<ofxMPMNode*>& nrow = grid[pcx + i];
				float ppxi = px[i];
				float pgxi = gx[i];
				
				for (int j=0; j<3; j++){
					ofxMPMNode *nj = nrow[pcy + j ];
					phi = ppxi * py[j];
					dx  = pgxi * py[j];
					dy  = ppxi * gy[j];
					nj->ax += fx * phi -(dx * T00 + dy * T01);
					nj->ay += fy * phi -(dx * T01 + dy * T11);
				}
			}
			
		} else {
			
			float *pppxi = &px[0];
			float *ppgxi = &gx[0];
			
			for (int i=0; i<3; i++) {
				vector<ofxMPMNode*>& nrow = grid[pcx + i];

				float ppxi = *(pppxi++); //px[i]; 
				float pgxi = *(ppgxi++); //gx[i];
				for (int j=0; j<3; j++){
					ofxMPMNode *nj = nrow[pcy+j];
					dx  = pgxi * py[j];
					dy  = ppxi * gy[j];
					nj->ax -= (dx * T00 + dy * T01);
					nj->ay -= (dx * T01 + dy * T11);
				}
				
			}
		}
	}
	
	
	for (int ni=0; ni<numActiveNodes; ni++) {
		ofxMPMNode *n = activeNodes[ni]; 
		if (n->m > 0.0F) {
			n->ax /= n->m;
			n->ay /= n->m;
			n->u = 0.0; 
			n->v = 0.0;
		}
	}
	
	
	long t2 = ofGetElapsedTimeMillis();
	//-------------------------
	// Particles pass 3
	const float rightEdge  = gridSizeX - 3.0;
	const float bottomEdge = gridSizeY - 3.0;
	
	for (int ip=0; ip<numParticles; ip++) {
		ofxMPMParticle *p = particles[ip];
		
		float *px = p->px;
		float *py = p->py;
		int pcy = p->cy;
		int pcx = p->cx;
		for (int i=0; i<3; i++) {
			vector<ofxMPMNode*>& nrow = grid[pcx + i];
			float ppxi = px[i];
			for (int j=0; j<3; j++){
				ofxMPMNode *nj = nrow[pcy + j];
				phi   = ppxi * py[j];
				p->u += phi * nj->ax;
				p->v += phi * nj->ay;
			}
		}
		
		p->v += gravity;
		//if (isMouseDragging) {
		if (ofGetMousePressed(0)) {
			float vx = abs(p->x - ofGetMouseX()/scaleFactor);
			float vy = abs(p->y - ofGetMouseY()/scaleFactor);
			float mdx = (ofGetMouseX() - ofGetPreviousMouseX())/scaleFactor;
			float mdy = (ofGetMouseY() - ofGetPreviousMouseY())/scaleFactor;
			if (vx < 10.0F && vy < 10.0F) {
				float weight = (1.0F - vx / 10.0F) * (1.0F - vy / 10.0F);
				p->u += weight * (mdx - p->u);
				p->v += weight * (mdy - p->v);
			}
		}
		
		// COLLISIONS-2
		// Plus, an opportunity to add randomness when accounting for wall collisions. 
		float xf = p->x + p->u;
		float yf = p->y + p->v;
		float wallBounceMaxRandomness = 0.03;
		if (xf < 2.0F) {
			p->u +=     (2.0F - xf) + ofRandom(wallBounceMaxRandomness);
		} else if (xf > rightEdge) { 
			p->u +=  rightEdge - xf - ofRandom(wallBounceMaxRandomness);
		} 
		if (yf < 2.0F) {
			p->v +=     (2.0F - yf) + ofRandom(wallBounceMaxRandomness);
		} else if (yf > bottomEdge) {
			p->v += bottomEdge - yf - ofRandom(wallBounceMaxRandomness);
		} 
		
		
		float pu = p->u;
		float pv = p->v;
		for (int i=0; i<3; i++) {
			vector<ofxMPMNode*>& nrow = grid[pcx + i];
			float ppxi = px[i];
			for (int j=0; j<3; j++){
				ofxMPMNode *nj = nrow[pcy + j];
				phi = ppxi * py[j];
				nj->u += phi * pu;
				nj->v += phi * pv;
			}
		}
	}
	
	for (int ni=0; ni<numActiveNodes; ni++) { 
		ofxMPMNode *n = activeNodes[ni]; 
		if (n->m > 0.0F) {
			n->u /= n->m;
			n->v /= n->m;
		}
	}
	
	
	long t3 = ofGetElapsedTimeMillis();
	//-------------------------
	// Particles pass 4
	float gu, gv;
	for (int ip=0; ip<numParticles; ip++) {
		ofxMPMParticle *p = particles[ip];
		
		gu = 0.0F;
		gv = 0.0F;
		
		float *px = p->px;
		float *py = p->py;
		int pcy = p->cy;
		int pcx = p->cx;
		for (int i=0; i<3; i++) {
			vector<ofxMPMNode*>& nrow = grid[pcx + i];
			float ppxi = px[i]; 
			for (int j=0; j<3; j++){
				ofxMPMNode *nj = nrow[pcy + j];
				phi = ppxi * py[j];
				gu += phi * nj->u;
				gv += phi * nj->v;
			}
		}
		
		p->x += (p->gu = gu);
		p->y += (p->gv = gv);
		p->u += smoothing * (gu - p->u);
		p->v += smoothing * (gv - p->v);
	}
	
	
	//----------------------------------
	long t4 = ofGetElapsedTimeMillis();
	
	long dt0 = t1-t0;
	long dt1 = t2-t1;
	long dt2 = t3-t2;
	long dt3 = t4-t3;
	long dt =  t4 - t0;
	elapsed = 0.95*elapsed + 0.05*(dt);
	// Timing: in case you're curious about CPU consumption, uncomment this:
	// printf("Elapsed = %d	%d	%d	%d	%f\n", dt0, dt1, dt2, dt3, elapsed); 
	
}
Пример #11
0
//--------------------------------------------------------------
void ofApp::mouseMoved(int x, int y ){
    ofVec2f dir = ofVec2f(x, y) - ofVec2f(ofGetPreviousMouseX(), ofGetPreviousMouseY());
    myField.setDirection(dir);
}
Пример #12
0
ofPoint ofxGetPreviousMouse() {
    return ofPoint(ofGetPreviousMouseX(), ofGetPreviousMouseY());
}
Пример #13
0
//--------------------------------------------------------------
void testApp::draw() {
	
	ofSetColor(255, 255, 255);

    //dataLoggerARM-----------------------------------_
    if (isGuiDataLoggerARM == true) {
        glDisable(GL_CULL_FACE);
        //velSmoothStateXY--------------------------------_
        //velSmoothStateMouseMoved.draw(mouseX, mouseY);
        //-----------------velSmoothStateXY---------------_
        dataLoggerARM_0.draw();
        glEnable(GL_CULL_FACE);
    }
    //-----------------dataLoggerARM------------------_
	
    if (isDrawOpenCV == true) {
        bDrawPointCloud = false;
        glDisable(GL_CULL_FACE);
		// draw from the live kinect
		kinect.drawDepth(10, 10, 400, 300);
		kinect.draw(420, 10, 400, 300);
		
		grayImage.draw(10, 320, 400, 300);
		//contourFinder.draw(10, 320, 400, 300);
        
        ofSetColor(255, 255, 255);
        stringstream reportStream;
        reportStream << "Rotate the point cloud with the mouse" << endl
        << "Press 'f' to switch to full screen" << endl
        << "Press 'h' to switch mirror horizontal for participant" << endl
        << "accel is: " << ofToString(kinect.getMksAccel().x, 2) << " / "
        << ofToString(kinect.getMksAccel().y, 2) << " / "
        << ofToString(kinect.getMksAccel().z, 2) << endl
        << "using opencv threshold = " << bThreshWithOpenCV <<" (press spacebar)" << endl
        << "set near threshold " << nearThreshold << " (press: + -)" << endl
        << "set far threshold " << farThreshold << " (press: < >) num blobs found " << contourFinder.nBlobs
        << ", fps: " << ofGetFrameRate() << endl
        << "press 'c' to close the connection and o to open it again, connection is: " << kinect.isConnected() << endl
        << "press 'UP' and 'DOWN' to change the tilt angle: " << angle << " degrees" << endl;
        ofDrawBitmapString(reportStream.str(), 425, 420);
        glEnable(GL_CULL_FACE);
    }
    
    if (isGuiDataLoggerARM == true) {
        //ofBackground(0);
        //bFullscreen
        string s = string("") +
        "\n" +
        "KEYS:\n" +
        "\n" +
        "Press 'f' to switch to full screen\n"+
        "Press 'h' to switch mirror horizontal for participant\n"+
        "\n" +
        "Out Form Field\n" +
        "\n" +
        " 'R' Makes A New Session\n" +
        " 'UP' / 'DOWN' Cycle Sessions\n" +
        " 'LEFT' / 'RIGHT' Cycle Data Logged\n" +
        " '<' , '>' or 'TAB' Cycle the Form Field\n" +
        "\n" +
        "In Form Field\n" +
        "\n" +
        " If No File Found It Will Make File After 'Enter' is Pressed.\n" +
        " 'Del', Key, 'Enter' or 'LEFT' / 'RIGHT'\n" +
        "\n" +
        "Audio\n" +
        "\n" +
        " 'p' Play\n" +
        " 'q' Paused\n" +
        "\n" +
        "Data Logging\n" +
        "\n" +
        " 1-9 Num Pad Pain Score\n" +
        " MousePressed Notable Difference\n";
        
        glDisable(GL_CULL_FACE);
        ofSetColor(255);
        //ofDisableLighting();
        ofDrawBitmapString(s, ofPoint(670, 20));
        glEnable(GL_CULL_FACE);
    }

    //ofCamera----------------------------------------_
    if (isGuiCamera == true) {
        //ofBackground(0);
        
        string s = string("") + 
        "\n" +
        "Press 'f' to switch to full screen\n"+
        "Press 'h' to switch mirror horizontal for participant\n"+
        "\n" +
        //"Purple boxes (4 of them) are generic nodes with simple circular motion, linked in a hierarchy (with ofNode::setParent).\n" +
        //"Yellow boxes (2 of them) are cameras. You are looking through one of them so can only see one box on screen.\n" +
        //"\n" +
        "KEYS:\n" +
        "\n" + 
        "'z' reset transforms\n" + 
        "\n" + 
        "'v' switch camera to view: " + ofToString(camToView) + "\n" +
        "\n" + 
        
        "\n" + 
        "'c' switch camera to configure: " + ofToString(camToConfigure) + "\n" +
        " 't' cycle lookat\n" + 
        " 'p' cycle parent\n";
        
        //" LEFT pan left\n"+ 
        //" RIGHT pan right\n" + 
        //" UP tilt up\n" + 
        //" DOWN tilt down\n" + 
        //" , roll left\n" + 
        //" . roll right\n" + 
        //" a truck left\n" + 
        //" d truck right\n" + 
        
        //" w dolly forward\n" +
        //" s dolly backward\n" + 
        
        //" r boom up\n" +
        //" f boom down\n";
        glDisable(GL_CULL_FACE);
        ofSetColor(255);
        //ofDisableLighting();
        ofDrawBitmapString(s, ofPoint(20, 20));
        glEnable(GL_CULL_FACE);
        //ofEnableLighting();
    }
    // update camera transforms
    for(int i=0; i<kNumCameras; i++) {
        
        // lookat node if it has one
        if(lookatIndex[i] >= 0) cam[i].lookAt(testNodes[lookatIndex[i]]);
        
        // mouse orbit camera
        if(doMouseOrbit[i] && velSmoothStateMouseMoved.bStoppedX == false && velSmoothStateMouseMoved.bStoppedY == false) {// was ofGetMousePressed(0)
            static float lon = 0;
            static float lat = 0;
            
            setLon = lon = ofClamp(lon + mouseX - ofGetPreviousMouseX(), -180, 180);
            setLat = lat = ofClamp(lat + mouseY - ofGetPreviousMouseY(), -90, 90);
            
            if(lookatIndex[i] < 0) {
                cam[i].orbit(lon, lat, orbitRadius);
            } else {
                cam[i].orbit(lon, lat, orbitRadius, testNodes[lookatIndex[1]]);
            }
        }
    }

    // activate camera
    cam[camToView].begin();
    if(bDrawPointCloud == true) {
        drawPointCloud();
    }

    if (isGuiCamera == true) {
        // draw world axis
        ofDrawAxis(100);
        // draw testNodes
        for(int i=0; i<kNumTestNodes; i++) {
            ofSetColor(255, 128, 255);
            testNodes[i].draw();
        }
        
        // draw cameras
        for(int i=0; i<kNumCameras; i++) {
            ofSetColor(255, 255, 0);
            cam[i].draw();
            
            // draw line from cam to its lookat
            if(lookatIndex[i] >= 0) {
                ofSetColor(0, 255, 255);
                glBegin(GL_LINES);
                ofVec3f v1 = cam[i].getGlobalPosition();
                ofVec3f v2 = testNodes[lookatIndex[i]].getGlobalPosition();
                glVertex3f(v1.x, v1.y, v1.z);
                glVertex3f(v2.x, v2.y, v2.z);
                glEnd();
            }
            
            // draw line from cam to its parent
            if(parentIndex[i] >= 0) {
                ofSetColor(255, 255, 0);
                glBegin(GL_LINES);
                ofVec3f v1 = cam[i].getGlobalPosition();
                ofVec3f v2 = testNodes[parentIndex[i]].getGlobalPosition();
                glVertex3f(v1.x, v1.y, v1.z);
                glVertex3f(v2.x, v2.y, v2.z);
                glEnd();
            }
        }
    }
    
    // restore view to previous state (default openFrameworks view)
    cam[camToView].end();
    
    //---------------------ofCamera-------------------_
    
    
    if (isSession == true) {
        if ((isMouseMovTop == true || isMouseMovBott == true) && isDrPLayHitAreaImage == true) {
            string s = string("") +
            "\n" +
            "Press 'f' to switch to full screen\n"+
            "Press 'h' to switch mirror horizontal for participant\n"+
            "\n" +
            "Configure camera:\n" +
            " 'w' dolly forward\n" +
            " 's' dolly backward\n";
            
            //" LEFT pan left\n"+
            //" RIGHT pan right\n" +
            //" UP tilt up\n" +
            //" DOWN tilt down\n" +
            //" , roll left\n" +
            //" . roll right\n" +
            //" a truck left\n" +
            //" d truck right\n" +
            
            //" r boom up\n" +
            //" f boom down\n";
            glDisable(GL_CULL_FACE);
            ofSetColor(255);
            //ofDisableLighting();
            ofDrawBitmapString(s, ofPoint(20, 20));
            glEnable(GL_CULL_FACE);
            //ofEnableLighting();
        }
    }
    
    glDisable(GL_CULL_FACE);
    ofEnableAlphaBlending();
    
    //drHitAreaImage----------------------------------_
    if (isMouseMovBott == true || isMouseMovTop == true || isDrHitAreaImage == true) {
        drHitAreaImage_0.draw();
    }
    //-----------------drHitAreaImage-----------------_
    
    ofDrawBitmapString(ofToString((int) ofGetFrameRate()), 10, 20);

    //drPLayHitAreaImage------------------------------_
    if ((isMouseMovTop == true || isMouseMovBott == true) && isDrPLayHitAreaImage == true) {
        drPLayHitAreaImage_0.draw();
    }
    //-----------------drPLayHitAreaImage-------------_
    
    //timer------------_
    //playbackCamTimer_0.draw(65, 65);
    //------timer------_
    
    ofDisableAlphaBlending();
    glEnable(GL_CULL_FACE);
    
}
Пример #14
0
//--------------------------------------------------------------
void testApp::draw()
{
	
	ofBackgroundGradient(60, 0);
	ofSetLineWidth(2);

	//PXC
	if (camFixed)
	{
		glDisable(GL_CULL_FACE);
		ofDisableLighting();
		glDisable(GL_DEPTH_TEST);
		ofSetColor(255);
		mLabelTexture.draw(0,0,640,480);

		ofPushStyle();

		ofFill();
		//for(vector<ofPoint>::iterator vit=mPositions.begin();vit!=mPositions.end();++vit){

			for(int i = 0; i<mPositions.size();i++){
				if(mPositions[i].node == PXCGesture::GeoNode::LABEL_FINGER_THUMB){
					ofSetColor(ofColor::red);
					ofCircle(mPositions[i].imagePos.x,mPositions[i].imagePos.y, 15);
				
				}
				else if(mPositions[i].node == PXCGesture::GeoNode::LABEL_FINGER_INDEX){
					ofSetColor(ofColor::yellow);
					ofCircle(mPositions[i].imagePos.x,mPositions[i].imagePos.y, 15);
				}
				else if(mPositions[i].node == PXCGesture::GeoNode::LABEL_FINGER_MIDDLE){
					ofSetColor(ofColor::blue);
					ofCircle(mPositions[i].imagePos.x,mPositions[i].imagePos.y, 15);
				 }

				else if(mPositions[i].node == PXCGesture::GeoNode::LABEL_FINGER_PINKY){
					 ofSetColor(ofColor::green);
					 ofCircle(mPositions[i].imagePos.x,mPositions[i].imagePos.y, 15);
				 }

				else if(mPositions[i].node == PXCGesture::GeoNode::LABEL_FINGER_RING){
					ofSetColor(ofColor::pink);
					ofCircle(mPositions[i].imagePos.x,mPositions[i].imagePos.y, 15);
					
				 }
				else if(mPositions[i].node == PXCGesture::GeoNode::LABEL_BODY_HAND_LEFT){
					ofSetColor(ofColor::white);
					float z = ofMap(mPositions[i].worldPos.z,0,0.1,0,40,true);
					ofCircle(mPositions[i].imagePos.x,mPositions[i].imagePos.y, 40-z);
					ofSetColor(60,60,60);
					ofDrawBitmapString(ofToString(z)+"   "+ofToString(mPositions[i].worldPos.z),100,100);
				}
				else if(mPositions[i].node == PXCGesture::GeoNode::LABEL_BODY_HAND_RIGHT){
					ofSetColor(ofColor::burlyWood);
					float z = ofMap(mPositions[i].worldPos.z,0,0.1,0,40,true);
					ofCircle(mPositions[i].imagePos.x,mPositions[i].imagePos.y, 40-z);
					ofSetColor(60,60,60);
					ofDrawBitmapString(ofToString(z)+"   "+ofToString(mPositions[i].worldPos.z),100,130);
				}

				

		}
		ofPopStyle();


		mRGBTexture.draw(0+640,0,320,240);
		mLabelTexture.draw(640+320,0,320,240);
		mDepthTexture.draw(640,240,320,240);
		mIRTexture.draw(640+320,240,320,240);
	}else{

		if(ofGetMousePressed(0)) {
			static float lon = 0;
			static float lat = 0;

			lon = ofClamp(lon + mouseX - ofGetPreviousMouseX(), -180, 180);
			lat = ofClamp(lat + mouseY - ofGetPreviousMouseY(), -90, 90);

			cam.orbit(lon, lat, 100, hero);
			
		}

		glEnable(GL_CULL_FACE);
		ofEnableLighting();

		if (!camSwith)
		{cam.lookAt(hero);
		cam.begin();
		ofDrawAxis(5000);
		hero.draw();
		for (int i =0; i<nodes.size(); i++)
		{
			nodes[i].draw();
		}
		cam.end();
		}else{
			hero.begin();
			for (int i =0; i<nodes.size(); i++)
			{
				nodes[i].draw();
			}
			
			ofDrawAxis(5000);
			hero.end();
		}
		
		
	}
	
}