//-------------------------------------------------------------- void testApp::drawVertAlignMark(const ofRectangle& rect, const ofColor& color, ofAlignVert vAlign) { if(vAlign != OF_ALIGN_VERT_IGNORE) { float vAnchor = rect.getVertAnchor(vAlign); ofSetColor(color,120); ofLine(rect.getLeft() - 13, vAnchor, rect.getLeft() - 3, vAnchor); ofLine(rect.getRight() + 13, vAnchor, rect.getRight() + 3, vAnchor); } }
void RectangleUtils::distributeHorz(RectanglePointers& rects, const ofRectangle& boundingRect, ofAlignHorz horzAnchor) { if(rects.size() >= 3 && horzAnchor != OF_ALIGN_HORZ_IGNORE) { sortByHorzAnchor(rects,horzAnchor); float nPos = rects.size() - 1; // adjust to bounding bounding rect. if bounding rect is based on the group, nothing will change rects[0]->translateX(boundingRect.getLeft() - rects[0]->getLeft()); rects[nPos]->translateX(boundingRect.getRight() - rects[nPos]->getRight()); float leftX = rects[0]->getHorzAnchor(horzAnchor); float rightX = rects[nPos]->getHorzAnchor(horzAnchor); float span = ( rightX - leftX ) / ( nPos ); for(size_t i = 1; i < nPos; i++) { rects[i]->translateX((leftX - rects[i]->getHorzAnchor(horzAnchor)) + i * span); } } else { if(horzAnchor == OF_ALIGN_HORZ_IGNORE) { ofLogVerbose("ofDistributeHorizontal") << "OF_ALIGN_HORZ_IGNORE distribute requested, ignoring."; } else { ofLogWarning("ofDistributeHorizontal") << "Not enough rectangles to distribute."; } } }
void LaserManager::renderLaserPath(ofRectangle previewRectangle, bool overrideSettings) { ofPushStyle(); if((showLaserPath)||(overrideSettings)) { ofPushMatrix(); ofTranslate(previewRectangle.getTopLeft()); float scale = previewRectangle.width / appWidth; ofScale(scale, scale); //ofDisableBlendMode(); ofNoFill(); ofSetLineWidth(1); ofSetColor(0,0,255); pathMesh.setMode(OF_PRIMITIVE_LINE_LOOP); pathMesh.draw(); ofSetColor(255,255,255); pathMesh.setMode(OF_PRIMITIVE_POINTS); pathMesh.draw(); ofPopMatrix(); if(ildaPoints.size()>0) { int pointindex = floor(ofMap(ofGetMouseX(), previewRectangle.x, previewRectangle.getRight(), 0, (int)ildaPoints.size(), true)); if(pointindex>=ildaPoints.size()) pointindex =ildaPoints.size(); ofPoint p = ildaPointToOfPoint(ildaPoints[pointindex]); ofSetColor(0,255,0); ofCircle(ofMap(p.x, 0, appWidth, previewRectangle.x, previewRectangle.getRight()), ofMap(p.y, 0, appHeight, previewRectangle.y, previewRectangle.getBottom()), 5); } } // TODO - this needs to go somewhere else! warp.visible = showWarpPoints || (overrideSettings); warp.draw(); ofPopStyle(); }
ClipperLib::IntRect Clipper::toClipper(const ofRectangle& rectangle, ClipperLib::cInt scale) { ClipperLib::IntRect rect; rect.left = rectangle.getLeft() * scale; rect.right = rectangle.getRight() * scale; rect.top = rectangle.getTop() * scale; rect.bottom = rectangle.getBottom() * scale; return rect; }
bool ofApp::setRandomVehicleLocation(ofRectangle area, bool liveInWater, ofVec2f & location){ bool okwater = false; int count = 0; int maxCount = 100; while (!okwater && count < maxCount) { count++; float x = ofRandom(area.getLeft(),area.getRight()); float y = ofRandom(area.getTop(),area.getBottom()); bool insideWater = kinectProjector->elevationAtKinectCoord(x, y) < 0; if ((insideWater && liveInWater) || (!insideWater && !liveInWater)){ location = ofVec2f(x, y); okwater = true; } } return okwater; }
bool Trigger::update(float deltaTime, ofRectangle& triggerArea) { this->deltaTime = deltaTime; elapsedTime+=deltaTime; if((moving) || ( (elapsedTime-lastTriggerTime > 4) && (rechargeSettings->restoreSpeed>0) && !disabled && (unitPower>=rechargeSettings->triggerPower) )) { sampleBrightness += deltaTime; } else { sampleBrightness-=deltaTime*2; } sampleBrightness = ofClamp(sampleBrightness, 0, 1); moving = false; if(lastSettings!=NULL) { lastScale-=deltaTime*5; if(lastScale<=0.0) { lastScale = 0; lastSettings = NULL; } } // scale up / down on start stop if(stopping) { scale-=deltaTime*5; if(scale<=0.0) { scale = 0; active = false; return false; } return active; } else if(scale<1){ scale+= deltaTime*5; // (1-scale)*0.2; if(scale>1) scale = 1; } if((settings!=NULL) &&(!settings->rotateOnFire)) { angle = 0; if(settings->rotationSpeed>0) { float sinoffset = settings->rotateOscillationOffset * ofMap(pos.x, triggerArea.getLeft(), triggerArea.getRight(), -1, 1); angle = (sin((elapsedTime + sinoffset)*settings->rotationSpeed )*settings->rotationExtent); } if(settings->rotateMirrorOffset!=0) { angle+= ofMap(pos.x, triggerArea.getLeft(), triggerArea.getRight(), 1, -1) * settings->rotateMirrorOffset; } } if(showDebugData) { if((elapsedTime-lastUpdate>0.032)||(motionValues.size()==0)) { motionValues.push_back(motionLevel); lastUpdate = elapsedTime; } else { float lastlevel = 0; lastlevel = motionValues[motionValues.size()-1]; motionValues[motionValues.size()-1] = (motionLevel>lastlevel) ? motionLevel : lastlevel; } if(motionValues.size()>motionValueCount) { motionValues.pop_front(); } } unitPower+=rechargeSettings->restoreSpeed * deltaTime; if(unitPower>1) unitPower = 1; if((rechargeSettings->restoreSpeed==0) && (unitPower<=0)) { stopping = true; } // we need to have sensed motion, // AND we need to have enough unitPower to trigger if( (!disabled) && (!stopping) && (scale>0.95) && (motionLevel >= rechargeSettings->motionTriggerLevel) && (unitPower>=rechargeSettings->triggerPower) && (elapsedTime - lastTriggerTime > rechargeSettings->minTriggerInterval) ) { if(doTrigger()) { motionLevel = 0; unitPower-=rechargeSettings->triggerPower; lastTriggerTime = elapsedTime; } } motionLevel -= rechargeSettings->motionDecay*deltaTime; if(motionLevel<0) motionLevel = 0; return active; }