Пример #1
0
float App::exploredPercent() {
    bool explored[100][100];

    for(int i = 0; i < 100; i ++) {
        for(int j = 0; j < 100; j ++) {
            explored[i][j] = false;
        }
    }

    for(int i = 1; i < session->getSize(); i ++) {
        float y = ofAngleDifferenceDegrees(rotations[X].data[i], heatmap.rot_x->ref);
        float x = ofAngleDifferenceDegrees(rotations[Y].data[i], heatmap.rot_y->ref);
        x = ofMap(x, -180, 180, 0, 100, true);
        y = ofMap(x, -180, 180, 0, 100, true);
        explored[(int) x][(int) y] = true;

    }

    int e = 0;

    for(int i = 0; i < 100; i ++) {
        for(int j = 0; j < 100; j ++) {
            if(explored[i][j]) e += 1;
        }
    }

    return  e / float(100*100);

}
void RotationRestrictor::restrict(BasicScreenObject *_object) {
  ofQuaternion orientation = _object->getOrientationQuat();
  ofVec3f norm(1, 0, 0);
  norm = norm * orientation;
  norm.z = 0;
  ofVec2f norm2d;
  norm2d.set(norm);
  float angle = norm2d.angle(ofVec2f(1, 0));
  if (angle > 0) {
    angle = 360 - angle;
  }
  if (angle < 0) {
    angle = angle * -1;
  }

  // cout << angle <<endl;

  if (!MathHelper::isAnlgeBetween(angle, minRotation, maxRotation)) {
    // angle is not within range, so find which is closer, min or max
    float minDiff = fabs(ofAngleDifferenceDegrees(minRotation, angle));
    float maxDiff = fabs(ofAngleDifferenceDegrees(maxRotation, angle));
    if (minDiff < maxDiff) {
      angle = minRotation;
    } else {
      angle = maxRotation;
    }
    _object->setOrientation(ofVec3f(norm.x, norm.y, angle));
  }
};
Пример #3
0
 void  drawGraph(){
     
     ofSetColor(0);
     ofLine(0, 0, N, 0);
     
     ofSetColor(color);
     
     if(data.size() > 1){
         
         int s = data.size();
         if(s > N)
             s = N;
         
         for(int i = 1; i < s; i ++){
             float v0 = data[ data.size() - (i + 1)];
             float v1 = data[data.size()  - i];
             
             float d0 = ofAngleDifferenceDegrees(v0, ref) / 4;
             float d1 = ofAngleDifferenceDegrees(v1, ref) / 4;
             
             ofLine(i, d0, i + 1, d1);
         }
         
     }
 };
Пример #4
0
 float lookingUp(){
     float upper = 0;
     for(int i = 0; i < data.size(); i ++){
         if(ofAngleDifferenceDegrees(data[i], ref) <= 0)
             upper += 1;
     }
     return upper / data.size() * 100;
 }
void CircularPB::update(){
	currentPos = int(ofGetElapsedTimeMillis()*10*0.001)%bigcircle.size();

	for(int i=0;i<(int)bigcircle.size();i++){
		float currentAngle = 360.f/float(bigcircle.size())*float(currentPos);
		float iAngle = 360.f/float(bigcircle.size())*float(i);
		float diff = abs(ofAngleDifferenceDegrees(iAngle,currentAngle));
		//if(diff<0) diff=255;

		alphas[i] = 255-diff*(255.f/(360.f/3.f));
	}
}
Пример #6
0
//--------------------------------------------------
float ofLerpDegrees(float currentAngle, float targetAngle, float pct) {
    return currentAngle + ofAngleDifferenceDegrees(currentAngle,targetAngle) * pct;
}
Пример #7
0
//--------------------------------------------------------------
void camApp::update(){

	updateAppInfo();

	if( title.state == NODE_ACTIVE && title.introAllDone() ){
		title.setState(NODE_DEACTIVATING);
		state = CAM_APP_NORMAL;
		durationSameDirection = 0.0;
	}
	
	if( title.state != NODE_INACTIVE ){
		titleUpdate();
	}

	if( howTo.state != NODE_INACTIVE ){
		if( howTo.timeActive < 1.0 ){
			magRotZStartHowTo = mag.angleZ;
		}
		
		howTo.update();
		if( fabs( ofAngleDifferenceDegrees(magRotZStartHowTo, mag.angleZ) ) > 120 ){
			howTo.playMovie();
		}
		
	}
		
	if( state == CAM_APP_TITLE && title.holdPerson() ){
		//camMan.setTargetPosX(currentNode->pos.x); 
		camMan.setTargetPosY(title.pos.y);
	}else{

		riseFallUpdate();	
		
		camShiftAmntY = ofLerp(camShiftAmntY, ofMap(riseFallPct, 0, 1, -(float)ofGetHeight() * 0.175, (float)ofGetHeight() * 0.175, true), 0.03);
		
		if( state == CAM_APP_NORMAL ){

			float endGraphicOffset = 210.0;
			percentOver = ofMap( fabs(myPerson.pos.y - (endGraphic.pos.y+endGraphicOffset) ), 1000, endGraphicOffset*0.5, 0.0, 1.0, true);
			
			if( percentOver >= 0.7 ){
				
				float pct	= ofMap(percentOver, 0.7, 1.0, 0.0, 1.0, true);
				float ipct	= 1.0-pct;
				
				myPerson.vel *= 0.7 + 0.3*ipct;
				myPerson.pos.x = ofLerp(myPerson.pos.x, endGraphic.pos.x, 0.01 + pct * 0.02);
				myPerson.pos.y = ofLerp(myPerson.pos.y, endGraphic.pos.y+endGraphicOffset, 0.01 + pct * 0.02);
				
				camMan.setTargetPosY(endGraphic.pos.y * pct + (myPerson.pos.y+camShiftAmntY) * ipct);			
			}else{
				camMan.setTargetPosY(myPerson.pos.y+camShiftAmntY);
			}
						
		}
		
		if( howTo.pct > 0.2 ){
			camMan.setTargetPosY(howToStorePos.y);
		}
			
		if( makeNewNode( ofGetHeight() ) ){

			if( state == CAM_APP_NORMAL && howTo.state == NODE_INACTIVE && ofGetElapsedTimef() - nodeCreatedTime > 1.2 ){

				if( myPerson.vel.y > 0.2 ){
					nextNode(true);
				}else if( myPerson.vel.y < -0.2 ){
					nextNode(false);		
				}
				
				nodeCreatedTime = ofGetElapsedTimef();
			}
		}
		
		if( state == CAM_APP_NORMAL && nodes.size() > 0 ){
			nodes.erase(nodes.begin(), partition(nodes.begin(), nodes.end(), killNodesAndDelete)); 		
		}

	}

	if( state == CAM_APP_HOWTO ){
		limitPersonMovement(howToStorePos, -ofGetWidth()/2, ofGetWidth()/2, -(float)ofGetHeight()*0.4, (float)ofGetHeight()*0.4);
	}	

	soundMan.update(riseFallPct);
	handleRiseFall();	
	
	camMan.update(0.1, 0.04);
	world.camPos = camMan.getPosition();
	world.camRot = camMan.getRotation();
	
	camPos = world.camPos;

	if( state != CAM_APP_TITLE && !( state == CAM_APP_HOWTO && howTo.state == NODE_ACTIVE ) ){
		for(int i = 0; i < nodes.size(); i++){
			nodes[i]->update();
		}
	}
	
	sceneGraph.clearElements();
	sceneGraph.addElement(&myPerson);
	sceneGraph.addElement(&weather);
	
	if( title.state != NODE_INACTIVE ){
		sceneGraph.addElement(&title);
	}
	
	for(int i = 0; i < nodes.size(); i++){
		sceneGraph.addElement(nodes[i]);
	}
	
	//MANUAL NODEs
	weather.update();
	hand.update();
}
Пример #8
0
void App::dumpHeatmap() {

    static const size_t size = 1000;
    heatmap_t* hm = heatmap_new(size, size);

    int M = 21;
    float hist[M][M];

//    for(int i = 0; i < M; i ++){
//        for(int j = 0; j < M; j ++){
//            hist[i][j] = 0;
//        }
//    }

    for(int i = 1; i < session->getSize(); i ++) {
        float y = ofAngleDifferenceDegrees(rotations[X].data[i], heatmap.rot_x->ref);
        float x = ofAngleDifferenceDegrees(rotations[Y].data[i], heatmap.rot_y->ref);
        x = ofMap(x, 120, -120, 0, size);
        y = ofMap(y, -120, 120, 0, size);
        heatmap_add_point(hm, x, y);


        x = ofMap(x, 0, size, 0, M - 1, true);
        y = ofMap(y, 0, size, 0, M - 1, true);

        hist[(int) x][(int) y] += 1;
    }





//    string str = "1;2;3;4;5;6;7;8;9;10;11;12;13;14;15;16;17;18;19;20;21";
//    str += "\n";
//    for(int j = 0; j < M; j ++){
//        for(int i = 0; i < M; i ++){
//            hist[i][j] = hist[i][j] / (float) session->getSize();
//            hist[i][j] *= 100;
//            str += ofToString(round(hist[i][j] * 100) / 100.0);
//            if( i != M - 1)
//                str += ";";
//        }
//        if( j != M - 1)
//            str += "\n";
//    }
//
//
//    ofFile file( Assets::getInstance()->dataPath() + ofToString(metadata.name)+ "-" + session->timestamp + ".csv", ofFile::WriteOnly);
//    file << str;




    unsigned char * pixels = new unsigned char[size*size*4];
    heatmap_render_default_to(hm, pixels);

    ofImage img;
    img.allocate(size, size, OF_IMAGE_COLOR_ALPHA);
    img.setFromPixels(pixels, size, size, OF_IMAGE_COLOR_ALPHA);
    string filename = Assets::getInstance()->dataPath() +  session->timestamp + "_" + ofToString(metadata.name)  + ".png";
    cout << filename << endl;
    img.saveImage( filename);

}
Пример #9
0
 float dist(int i){
     return ofAngleDifferenceDegrees(data[i], ref);
 }
Пример #10
0
 float lastDist(){
     return ofAngleDifferenceDegrees(last, ref);
 };