コード例 #1
0
ファイル: testApp.cpp プロジェクト: 3snail/openFrameworks
//--------------------------------------------------------------
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);
    }
}
コード例 #2
0
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.";
        }
    }
}
コード例 #3
0
OMX_ERRORTYPE ofxRPiCameraVideoGrabber::setSensorCrop(ofRectangle& rectangle)
{


    sensorCropConfig.xLeft   = ((uint32_t)rectangle.getLeft()   << 16)/100;
    sensorCropConfig.xTop    = ((uint32_t)rectangle.getTop()    << 16)/100;
    sensorCropConfig.xWidth  = ((uint32_t)rectangle.getWidth()  << 16)/100;
    sensorCropConfig.xHeight = ((uint32_t)rectangle.getHeight() << 16)/100;
    
    OMX_ERRORTYPE error = OMX_SetConfig(camera, OMX_IndexConfigInputCropPercentages, &sensorCropConfig);
    OMX_TRACE(error);
    if(error != OMX_ErrorNone)
    {
        ofLogError(__func__) << omxErrorToString(error);
        if(error == OMX_ErrorBadParameter)
        {
            ofLogWarning(__func__) << "resetting cropRectangle to known good params (0, 0, 100, 100)";
            cropRectangle.set(0, 0, 100, 100);
            return updateSensorCrop(); 
        }
        
    }
    return error;
    
}
コード例 #4
0
ファイル: Clipper.cpp プロジェクト: bakercp/ofxClipper
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;
}
コード例 #5
0
ファイル: ofApp.cpp プロジェクト: bowserm/Magic-Sand
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;
}
コード例 #6
0
ファイル: Helmet.cpp プロジェクト: serkansokmen/hlct
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);
}
コード例 #7
0
ファイル: Trigger.cpp プロジェクト: sebleedelisle/PixelPyros
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();
	}
}