Exemplo n.º 1
0
//--------------------------------------------------------------
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.";
        }
    }
}
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;
    
}
Exemplo n.º 4
0
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;
}
Exemplo n.º 5
0
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;
}
Exemplo n.º 6
0
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;
}