void nebulaEye::sendOSC(){ ofxOscBundle bundle; for (int i = 0; i < contour.finder.size(); i++ ){ ofxOscMessage m; m.setAddress("/b"); m.addInt32Arg(contour.finder.getLabel(i)); ofVec2f centroid = ofxCv::toOf(contour.finder.getCentroid(i)); centroid.x /= bgSub.m_fgmask.cols; centroid.y /= bgSub.m_fgmask.rows; centroid -= zone.center; ofVec2f centroidPol = nebula::Utils::carToPol(centroid); centroidPol.y -= zone.angleOrigin; centroidPol.y = ofWrapDegrees(centroidPol.y); m.addFloatArg(centroidPol.x); m.addFloatArg(centroidPol.y); m.addFloatArg(contour.finder.getContourArea(i) / (bgSub.m_fgmask.cols * bgSub.m_fgmask.rows)); ofVec2f pt; pt.x = contour.finder.getCentroid(i).x / contour.blurred.cols; pt.y = contour.finder.getCentroid(i).y / contour.blurred.cols; m.addInt32Arg(zone.inside(pt)); bundle.addMessage(m); } ofxOscMessage m; m.setAddress("/f"); flowZone.clear(); for ( int i = 0; i < zone.mask.size() ; i++ ){ double f = flow.getFlowInMask(zone.mask[i], NULL); flowZone.push_back(f); m.addFloatArg(f); } bundle.addMessage(m); sender.sendBundle(bundle); }
void Critter::update(ofVec2f nearestHand) { ofVec2f nh = nearestHand; nextFrame += ofMap(v, 0, 10, 0, 2); currentFrame = floor(nextFrame); if(currentFrame >= numFrames) { currentFrame = 0; nextFrame = 0; } bool draw = true; for (int i = 0; i < previousFrames.size(); ++i) { if(previousFrames[i]) draw = false; } if(!hidden && draw) { p.x += v * cos(d/180*PI); p.y += v * sin(d/180*PI); } float time = ofGetElapsedTimef(); v += ofSignedNoise(time * TIME_SCALE + offsets[0]) * VELOCITY_DISPLACEMENT_SCALE; d += ofSignedNoise(time * TIME_SCALE + offsets[1]) * DIRECTION_DISPLACEMENT_SCALE; v = ofMap(v, MIN_VELOCITY, MAX_VELOCITY, MIN_VELOCITY, MAX_VELOCITY, true); d = ofWrapDegrees(d); if(nh.length() != 0) { ofVec2f vel = ofVec2f(v * cos(d/180*PI), v * sin(d/180*PI)); float fear = ofMap(nh.length(), 500, 0, 0, 1, true); float angle = vel.angle(nh); d += ofMap((abs(angle) - 180) * fear, -180, 0, -30 * (angle)/abs(angle), 0); v += ofMap((abs(angle) - 90) * fear, -90, 90, -0.3, 0.5); } }
void nebulaEye::recordCSVData(){ if (!record) return; int row = csvRecorder.numRows; int idx = 0; csvRecorder.setString(row, 0, getDate()); csvRecorder.setString(row, 1, getHour()); int area(0), biggest(-1); for (int i = 0; i < contour.finder.size(); i++ ){ if ( contour.finder.getContourArea(i) > area ){ biggest = i; area = contour.finder.getContourArea(i); } } if ( biggest != -1 ){ ofVec2f centroid = ofxCv::toOf(contour.finder.getCentroid(biggest)); centroid /= bgSub.m_fgmask.cols; centroid -= zone.center; ofVec2f centroidPol = nebula::Utils::carToPol(centroid); centroidPol.y -= zone.angleOrigin; centroidPol.y = ofWrapDegrees(centroidPol.y); csvRecorder.setFloat(row,2,centroidPol.x); csvRecorder.setFloat(row,3,centroidPol.y); } else { csvRecorder.setString(row,2,"NA"); csvRecorder.setString(row,3,"NA"); } csvRecorder.setFloat(row,4,flowZone[0]); csvRecorder.setFloat(row,5,flowZone[1]); csvRecorder.setFloat(row,6,flowZone[2]); csvRecorder.setFloat(row,7,flowZone[3]); }
//-------------------------------------------------- float ofAngleDifferenceDegrees(float currentAngle, float targetAngle) { return ofWrapDegrees(targetAngle - currentAngle); }
void DrawGame::CircleSprite::setRot( float degrees ) { Rot = degrees; Rot = ofWrapDegrees(Rot); }