//-------------------------------------------------------------- void testApp::drawHorzAlignMark(const ofRectangle& rect, const ofColor& color, ofAlignHorz hAlign) { if(hAlign != OF_ALIGN_HORZ_IGNORE) { float hAnchor = rect.getHorzAnchor(hAlign); ofSetColor(color,120); ofLine(hAnchor, rect.getTop() - 13, hAnchor, rect.getTop() - 3); ofLine(hAnchor, rect.getBottom() + 13, hAnchor, rect.getBottom() + 3); } }
void RectangleUtils::distributeVert(RectanglePointers& rects, const ofRectangle& boundingRect, ofAlignVert vertAnchor) { if(rects.size() >= 3 && vertAnchor != OF_ALIGN_VERT_IGNORE) { sortByVertAnchor(rects,vertAnchor); float nPos = rects.size() - 1; // adjust to bounding bounding rect. if bounding rect is based on the group, nothing will change rects[0]->translateY(boundingRect.getTop() - rects[0]->getTop()); rects[nPos]->translateY(boundingRect.getBottom() - rects[nPos]->getBottom()); float topY = rects[0]->getVertAnchor(vertAnchor); float bottomY = rects[nPos]->getVertAnchor(vertAnchor); float span = ( bottomY - topY ) / ( nPos ); for(size_t i = 1; i < nPos; i++) { rects[i]->translateY((topY - rects[i]->getVertAnchor(vertAnchor)) + i * span); } } else { if(vertAnchor == OF_ALIGN_VERT_IGNORE) { ofLogVerbose("ofDistributeVertical") << "OF_ALIGN_VERT_IGNORE distribute requested, ignoring."; } else { ofLogWarning("ofDistributeVertical") << "Not enough rectangles to distribute."; } } }
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; }
void hlct::Helmet::update(const ofRectangle& stageRect, const ofRectangle& hitRect, const float& scale){ this->stageRect.set(stageRect); this->scale = scale; float imgW = img.getWidth() * scale; float imgH = img.getHeight() * scale; if (alive && position.y <= stageRect.getBottom() - imgH/2) { if (!win) { position.y -= gravity * 1.2; } else { position.x = hitRect.getCenter().x - imgW * 0.5; position.y = hitRect.getTop() - imgH * 1.5; } } else { alive = false; } intersectRect.set(position, imgW, imgH); }
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(); }
void Trigger :: draw(ofRectangle area, int motionTargetThreshold) { if(settings!=NULL) { settings->update(deltaTime, values); settings->draw(elapsedTime, pos, unitPower, active, scale, angle); if(elapsedTime-lastTriggerTime<0.15) { ofPushMatrix(); ofPushStyle(); ofTranslate(pos.x, pos.y); float size = ofMap(elapsedTime - lastTriggerTime, 0, 0.15, 1, 0); size*=size; size*=settings->radius*5; ofScale(size, size); ofSetColor(settings->getColour()); flashImage.draw(-0.5, -0.5, 1,1); ofScale(0.5,0.5); flashImage.draw(-0.5, -0.5, 1,1); ofPopStyle(); ofPopMatrix(); } } if(lastSettings!=NULL) { lastSettings->update(deltaTime, values); lastSettings->draw(elapsedTime, pos, unitPower, active, lastScale, angle); } if(!active) return; if(showDebugData) { ofPushMatrix(); ofPushStyle(); ofTranslate(pos); ofSetColor(100,0,0); ofNoFill(); ofRect(-triggerSampleSize/2, -triggerSampleSize/2, triggerSampleSize, triggerSampleSize); ofTranslate(0, motionValueCount*-2); ofFill(); for(float i = -0.5; i<=0.5 ; i++){ ofPushMatrix(); ofBeginShape(); ofScale(i,1); ofVertex(-1,0); float lastvalue = -1; for(int i = 0; i<motionValues.size(); i++) { float value = ofClamp(motionValues[i]*20, 0, 50); if(value!=lastvalue) { ofVertex(lastvalue,(i*2)-1); ofVertex(value,i*2); ofVertex(value,(i*2)+1); } lastvalue = value; } ofVertex(0,motionValues.size()*2); ofVertex(-1,motionValues.size()*2); ofEndShape(); ofPopMatrix(); } ofPopMatrix(); for(int i = 0; i<vertMotionSamples.size(); i++) { float sample = vertMotionSamples[i]; ofSetColor(ofMap(sample, 0, 255,0,255,true)); if(sample<motionTargetThreshold) ofSetColor(50,0,0); ofNoFill(); float ypos = ofMap(i, 0, vertMotionSamples.size(), area.getTop(), area.getBottom()); ofCircle(pos.x, ypos, 3); ofRect(pos.x - (multiSampleSize/2), ypos-(multiSampleSize/2), multiSampleSize, multiSampleSize); } ofPopStyle(); } else if(sampleBrightness>0) { ofPushStyle(); for(int i = 0; i<vertMotionSamples.size(); i++) { // ofSetColor(ofMap(sample, 0, 255,0,255,true)); //if(sample<motionTargetThreshold) ofSetColor(50,0,0); ofNoFill(); float ypos = ofMap(i, 0, vertMotionSamples.size(), area.getTop(), area.getBottom()); if(ypos > pos.y) { float sample = vertMotionSamples[i]; ofSetColor(sampleBrightness * 100 ); ofSetLineWidth(1* scale); ofCircle(pos.x, ypos, 3* scale); if(i<vertMotionSamples.size()-1) { ofLine(pos.x, ypos+(3* scale), pos.x, ofMap(i+1, 0, vertMotionSamples.size(), area.getTop(), area.getBottom())-(3* scale)); } ofSetColor(ofMap(sample, 0, 255,0,80,true) * sampleBrightness); ofFill(); ofCircle(pos.x, ypos, 2* scale); } } ofPopStyle(); } }