示例#1
0
  void DrawGame::drawScaledStringByFont( 
    string Txt, 
    ofTrueTypeFont* pFont, 
    ofRectangle Rect )
  {
    // debug    
    float sh = pFont->stringHeight(Txt);
    float sw = pFont->stringWidth(Txt);

    ofRectangle R0(0,0,sw,-sh);   
   
    ofVec2f Trans = Rect.getCenter()-R0.getCenter();
    float sx,sy;
    sx = Rect.getWidth()/R0.getWidth();
    sy = -Rect.getHeight()/R0.getHeight();
        
    ofMatrix4x4 Mat;
    Mat.translate(-R0.getCenter());
    Mat.scale(sx,sy,1.0f);
   // Mat.translate(Rect.getCenter()/ofVec2f(sx,sy));
    Mat.translate(Rect.getCenter());
    ofMultMatrix(Mat);
    pFont->drawString(Txt,0,0); 
    ofMatrix4x4 MatI;
    MatI = Mat.getInverse();
    ofMultMatrix(MatI);

  }
void Communitas::init(ofRectangle _space){
    ofPoint center = ofPoint(_space.getCenter().x * width,_space.getCenter().y * height);
    
    space.setFromCenter(center, MIN(width, height), MIN(width, height));
    
    //  Allocate the fbo and clean it
    //
    fbo.allocate(width, height);
    fbo.begin();
    ofClear(0,0);
    fbo.end();
    
    fade    =    1.0f;
    blur.allocate(width, height);
    blur.setFade(fade);
	blur.setPasses(5);
    
    universe.set(space);
    nucle.set(space);
    
	universe.mass           = 0.75f;
	universe.vortex         = space.height*0.1f;
	universe.maxDistance	= space.height*0.4f;
    
	//universe.density		= 0.4f;
	universe.ph				= 6.5f;
	universe.joinParticles	= true;
	universe.correctOrbits	= true;
	universe.proportional	= true;
	universe.clockwise      = true;
    
	//universe.impulse		= 0.4f;
	universe.angle			= 0.0f;
    
	nucle.mass				= 10.0f;
	nucle.vortex			= space.height*0.1;
	nucle.maxDistance		= space.height*0.1;
    
	nucle.density			= 1.0f;	//= 0.05;
	nucle.ph	       		= 7.0f;	//= 6.9;
	nucle.joinParticles		= true;
    
	nucle.correctOrbits		= false;// = true;
	nucle.proportional		= false;
	nucle.clockwise			= false;
	nucle.impulse			= 0.19f;
	nucle.angle		       	= 0.0f;	//= -25;
    
	reset();
}
void defense::PlotEllipExternal(vector<TheEllipse> ElliVec,ofRectangle RectLimits,int AMode){
    TheEllipse CurrentEllipse(320,10,10,10,0,0);   
    
    if (AMode==0){
        glPushMatrix();
        ofTranslate(RectLimits.getCenter());
        ofScale(RectLimits.width/Nx, RectLimits.height/Ny);
        int Nsides = 128;
        for (int k=0; k < ElliVec.size();k++){
            CurrentEllipse = ElliVec[k];
            ofSetColor(CurrentEllipse.TheGray,CurrentEllipse.TheGray,CurrentEllipse.TheGray);
            glPushMatrix();  
            ofTranslate(CurrentEllipse.x-Nx/2.0, CurrentEllipse.y-Ny/2.0);
            ofRotate(CurrentEllipse.angle);
            glBegin(GL_POLYGON);
            for (int s =0; s<Nsides; s++) {
                glVertex2f(CurrentEllipse.a/2.0*cos(CV_PI/Nsides+s*2*CV_PI/Nsides)*(1+
                           5*CurrentEnergy*cos(s*2*CV_PI/8.0)),
                       CurrentEllipse.b/2.0*sin(CV_PI/Nsides+s*2*CV_PI/Nsides)*(1+
                          5*CurrentEnergy*cos(s*2*CV_PI/8.0)) );
            }
            glEnd();
            glPopMatrix();  
        }
        glPopMatrix(); 
    }
    
    
}
void Pong::init(ofRectangle _space) {
    ofPoint center = ofPoint(_space.getCenter().x * width,_space.getCenter().y * height);
    space.setFromCenter(center,
                        _space.width* width * 0.85,
                        _space.height * height * 0.85);

    fbo.allocate(width, height);
    fbo.begin();
    ofClear(0);
    fbo.end();

    ball = Ball(&space, &player1, &player2);
    ofAddListener( ball.goal , this, &Pong::point);
    pixel = space.width/40;

    reset();
}
void Oca::init(ofRectangle _space){
    ofPoint center = ofPoint(_space.getCenter().x * width,_space.getCenter().y * height);
    scaleFactor = _space.height;// * 0.85;

    space.setFromCenter(center,
                        scaleFactor * height,
                        scaleFactor * height);

    fbo.allocate(width,height);
    fbo.begin();
    ofClear(0,255);
    fbo.end();

    mask.loadImage("Oca/mask.png");
    background.loadImage("Oca/background.jpg");

    reset();
}
void Shadows::init(ofRectangle _space){
    
    background.loadImage("shadows/fondo.jpg");
    
    //  Screen resolution
    //
    //width = background.getWidth();
    //height = background.getHeight();
    
    //  Asign a space (surface area)
    //
    ofPoint center = ofPoint(_space.getCenter().x * width,_space.getCenter().y * height);
    space.setFromCenter(center, _space.width*width, _space.height*height);
    
    //  Allocate the fbo and clean it
    //
    fbo.allocate(width, height);
    fbo.begin();
    ofClear(0,0);
    fbo.end();
    
    blur.allocate(width,height);
    
    text.loadSequence("shadows/texto.xml");
    text.set(0,0,space.width*0.8, space.height*0.8);
    ofRectangle area;
    area.setFromCenter(space.x+space.width*0.5, 
                       space.y+space.height*0.5,
                       text.width,
                       text.height);
    
    textAnimation.set(area);
    
    //  Clean the variables and the start
    //
    reset();
}
示例#7
0
void BaseGame :: setup(ofRectangle rect, LaserManager * lm) {
	
	laserManager = lm;

	gameRect = rect; 
	
	centre = rect.getCenter();
	name = "";
	
	shotsPerGame = 6;
	
	pew.loadSound("../../../Sounds/RetroLaunch.1.wav");
	pew.setSpeed(0.7);

}
示例#8
0
DrawGame::GUIDataSlot::GUIDataSlot(  
  ofParameter<float>& p,
  ofParameter<float>& pmax,
  string tag,
  string title, 
  ofRectangle R,
  float TitleWdRatio,
  ofTrueTypeFont* font,
  float MaxValue,  
  float BarEdgeWidth,  
  ofColor CrTxt,
  ofColor CrBarEmpty,
  ofColor CrBarFill,
  ofColor CrBarEdge):
dataSrc(&p),
dataMaxSrc(&pmax),
GUIBase(tag),
pFont(font),
Title(title),
maxVal(MaxValue),
titleWdRatio(TitleWdRatio),
edgeWd(BarEdgeWidth),
CrText(CrTxt),
CrBG(CrBarEmpty),
CrFill(CrBarFill),
CrEdge(CrBarEdge)
{
  if(Crs.size()==0)
  {
    ofColor defCrs[10] = {
      ofColor::yellow,
      ofColor::green, 
      ofColor::darkGreen,
      ofColor::skyBlue,
      ofColor::cyan, 
      ofColor::blue, 
      ofColor::blueViolet,
      ofColor::violet,
      ofColor::chocolate,
      ofColor::black};
    for(int i=0;i<10;i++)
    {
      Crs.push_back(defCrs[i]);
    }
  }
  Rect.setFromCenter(ofVec2f(0,0),R.getWidth(),R.getHeight());
  ofNode::setPosition(R.getCenter());
}
void ofApp::PlotEllipses(vector<TheEllipse> ElliVec,ofRectangle RectLimits){
    TheEllipse CurrentEllipse(320,10,10,10,0,0);
    glPushMatrix();
    ofTranslate(RectLimits.getCenter());
    ofScale(RectLimits.width/Nx, RectLimits.height/Ny);
    for (int k=0; k < ElliVec.size();k++){
        CurrentEllipse = ElliVec[k];
        ofSetColor(CurrentEllipse.TheGray,CurrentEllipse.TheGray,CurrentEllipse.TheGray);
        glPushMatrix();
        ofTranslate(CurrentEllipse.x-Nx/2.0, CurrentEllipse.y-Ny/2.0);
        ofRotate(CurrentEllipse.angle);
        ofEllipse(0.0,0.0 , CurrentEllipse.a, CurrentEllipse.b);
        glPopMatrix();
    }
    glPopMatrix();
}
示例#10
0
文件: rift.cpp 项目: noio/move
void Rift::setup(const ofRectangle& bbox)
{
    const int num_points = ceil(bbox.height / (0.5f * max_point_dist));
    const float step = 1.0f / (num_points - 1);
    const float x_mid = bbox.getCenter().x;
    ofPolyline initial;
    for (int i = 0; i < num_points; i ++)
    {
        const float r = i * step;
        const float scale = r * (1 - r) * 4;
        float x = x_mid + ofRandomf() * bbox.width * .2 * scale;
        float y = bbox.y + r * bbox.height;
        initial.addVertex(ofPoint(x, y));
    }
    setup(initial);
}
void defense::PlotEllipNoFill(vector<TheEllipse> ElliVec,ofRectangle RectLimits){
    TheEllipse CurrentEllipse(320,10,10,10,0,0);    
    ofNoFill();
    ofSetLineWidth(1.0);
    glPushMatrix();
    ofTranslate(RectLimits.getCenter());
    ofScale(RectLimits.width/Nx, RectLimits.height/Ny);

    for (int k=0; k < ElliVec.size();k++){
        CurrentEllipse = ElliVec[k];
        
        glPushMatrix();  
        ofTranslate(CurrentEllipse.x-Nx/2.0, CurrentEllipse.y-Ny/2.0);
        ofRotate(CurrentEllipse.angle);
        ofEllipse(0.0,0.0 , CurrentEllipse.a, CurrentEllipse.b);
        glPopMatrix();  
    }
    glPopMatrix(); 
    ofFill();
}
示例#12
0
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 defense::PlotEllipsesTextureNew(vector<TheEllipse> ElliVec,ofRectangle RectLimits){
    TheEllipse CurrentEllipse(320,10,10,10,0,0);   
    ofImage TheTextu;
    TheTextu.loadImage("Blocks/transparentFishBR.png");
    glPushMatrix();
    ofTranslate(RectLimits.getCenter());
    ofScale(RectLimits.width/Nx, RectLimits.height/Ny);
    glEnable(GL_BLEND);
    glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    for (int k=0; k < ElliVec.size();k++){
        CurrentEllipse = ElliVec[k];
        ofSetColor(2*CurrentEllipse.TheGray,2*CurrentEllipse.TheGray,2*CurrentEllipse.TheGray);
        glPushMatrix();  
        ofTranslate(CurrentEllipse.x-Nx/2.0, CurrentEllipse.y-Ny/2.0);
        ofRotate(90+CurrentEllipse.angle);
        TheTextu.draw(-CurrentEllipse.b/2.0,-CurrentEllipse.a/2.0 , CurrentEllipse.b, CurrentEllipse.a);
        glPopMatrix();  
    }
    glPopMatrix(); 
     glDisable(GL_BLEND);
}
void defense::PlotEllipPolligon(vector<TheEllipse> ElliVec,ofRectangle RectLimits){
    TheEllipse CurrentEllipse(320,10,10,10,0,0);    
    glPushMatrix();
    ofTranslate(RectLimits.getCenter());
    ofScale(RectLimits.width/Nx, RectLimits.height/Ny);
    int Nsides = (127-Slider1)*12/127 +4;
    for (int k=0; k < ElliVec.size();k++){
        CurrentEllipse = ElliVec[k];
        ofSetColor(CurrentEllipse.TheGray,CurrentEllipse.TheGray,CurrentEllipse.TheGray);
        glPushMatrix();  
        ofTranslate(CurrentEllipse.x-Nx/2.0, CurrentEllipse.y-Ny/2.0);
        ofRotate(CurrentEllipse.angle);
        
        glBegin(GL_POLYGON);
        for (int s =0; s<Nsides; s++) {
            glVertex2f(CurrentEllipse.a/2.0*cos(CV_PI/Nsides+s*2*CV_PI/Nsides),
                       CurrentEllipse.b/2.0*sin(CV_PI/Nsides+s*2*CV_PI/Nsides));
        }
        glEnd();
        glPopMatrix();  
    }
    glPopMatrix(); 
}
示例#15
0
void ForbiddenPlanet::drawBoothScreen(ofxCvColorImage webCamImg, ofRectangle faceBoundingBox)
{
    // increase top and bottom of facebounding box by 35%
    float newHeight = faceBoundingBox.height * 1.35f;
    float heightDiff = newHeight - faceBoundingBox.height;
    
    float newY = faceBoundingBox.y - heightDiff/2.0;
    
    faceBoundingBox.y = newY;
    faceBoundingBox.height = newHeight;
    
    
    fboBuffer.begin();
    ofClear(0,0,0);
    
    float sizeMultX = 1.5f;//(float)BOOTH_SCREEN_SIZE_X / (float)webCamImg.width;
    float sizeMultY = 1.5f;//(float)BOOTH_SCREEN_SIZE_Y / (float)webCamImg.height;
    
    
    
    ofSetColor(255,255,255);
    ofSetLineWidth(2.5f);
    
    ofSetColor(255,255,255);
    _backdropImg.draw(BOOTH_SCREEN_POS_X,0,BOOTH_SCREEN_SIZE_X,BOOTH_SCREEN_SIZE_Y);
    ofNoFill();
    ofSetColor(255,0,50);
    
    // Find position of face
    ofPoint faceCentre = faceBoundingBox.getCenter();
    
    float faceCentreDiffY = BOOTH_SCREEN_SIZE_Y/2.0-25.0f-faceCentre.y;
    float faceCentreDiffX = BOOTH_SCREEN_SIZE_X/2.0-faceCentre.x;
    
    float faceSizeDiff = 384.000000 / faceBoundingBox.width;
    
    float w = faceSizeDiff * (float)BOOTH_SCREEN_SIZE_X;
    float h = faceSizeDiff * (float)BOOTH_SCREEN_SIZE_Y * 1.25f;
    
    float xPos = (BOOTH_SCREEN_SIZE_X/2) - FACE_TARGET_POS_X + faceCentreDiffX;
    float yPos = (BOOTH_SCREEN_SIZE_Y/2) - FACE_TARGET_POS_Y + faceCentreDiffY;
    
    ofRectangle faceBounds;
    
    float currentMult = 0.25f;
    float prevMult = 0.75f;
    if(_lastBounds->x != 0 &&_lastBounds->y != 0 &&_lastBounds->width != 0 &&_lastBounds->height != 0)
    {
        if(_lastBounds->x !=NULL && _lastBounds->y != NULL && _lastBounds->width !=NULL && _lastBounds->height != NULL)
        {
            printf("%f %f %f %f\n",_lastBounds->x,_lastBounds->y,_lastBounds->width,_lastBounds->height);
            faceBounds = ofRectangle(xPos* currentMult + _lastBounds->x*prevMult,yPos * currentMult + _lastBounds->y * prevMult,w * currentMult + _lastBounds->width * prevMult,h * currentMult + _lastBounds->height*prevMult );
        }
    }else
        faceBounds = ofRectangle(xPos,yPos,w,h);
    

    // Use face bounds to chop out contour image
    //printf("roi: %f %f %f %f\n",faceBoundingBox.x,faceBoundingBox.y,faceBoundingBox.width,faceBoundingBox.height);
    if(faceBoundingBox.width > 0 && faceBoundingBox.height > 0 && faceBoundingBox.width>0 && faceBoundingBox.height > 0)
    {
        ofxCvGrayscaleImage grayConvert;
        grayConvert = webCamImg;
        
        
        ofImage img;
        img.setFromPixels(grayConvert.getPixels(), grayConvert.width, grayConvert.height, OF_IMAGE_GRAYSCALE);
        img.resize(1280,720);
        img.crop(faceBoundingBox.x,faceBoundingBox.y,faceBoundingBox.width,faceBoundingBox.height);
   
        
        //grayConvert.resize(640,480);
        ofPushMatrix();
        ofTranslate(15,0);
        ofSetColor(200,0,75);
        drawContours(0.4 + abs(sin(_contrast))*0.6f,img,sizeMultX,sizeMultY,faceBoundingBox);
        
        ofTranslate(5,7);
        drawContours(1.0f-0.4 + abs(sin(_contrast))*0.6f,img,sizeMultX,sizeMultY,faceBoundingBox);
        ofPopMatrix();
        
    }
    _contrast += 0.025f;
    
    ofFill();
    ofSetColor(255,255,255);
    //glBlendFunc(GL_SRC_ALPHA, GL_ONE);
    _laserVideo.draw(BOOTH_SCREEN_POS_X,0,BOOTH_SCREEN_SIZE_X,BOOTH_SCREEN_SIZE_Y);
    //glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    
    fboBuffer.end();
    fboBuffer.draw(BOOTH_SCREEN_POS_X,0,BOOTH_SCREEN_SIZE_X,BOOTH_SCREEN_SIZE_Y);
    
    /*
    if(isShowBoothOnProjector())
        fboBuffer.draw(BOOTH_SCREEN_SIZE_X - BOOTH_SCREEN_SIZE_X/4,BOOTH_SCREEN_SIZE_Y   - BOOTH_SCREEN_SIZE_Y/4,BOOTH_SCREEN_SIZE_X/4,BOOTH_SCREEN_SIZE_Y/4);
    else
        _mainVideo.draw(BOOTH_SCREEN_SIZE_X - BOOTH_SCREEN_SIZE_X/4,BOOTH_SCREEN_SIZE_Y   - BOOTH_SCREEN_SIZE_Y/4,BOOTH_SCREEN_SIZE_X/4,BOOTH_SCREEN_SIZE_Y/4);
    */
    
    
    _font.drawString("Outside Feed:", OUTSIDE_FEED_TEXT_POS_X, OUTSIDE_FEED_TEXT_POS_Y);
    
    _font2.drawString("LIVE",LIVE_TEXT_POS_X,LIVE_TEXT_POS_Y);
    
    printf("show booth on projector: %i\n",isShowBoothOnProjector());
    if(isShowBoothOnProjector() >= 0)
    {
        ofSetColor(0,0,0);
        ofRect(LIVE_ICON_POS_X,LIVE_ICON_POS_Y,_liveIcon.getWidth()/4,_liveIcon.getHeight()/4);
        ofSetColor(255,255,255);
        _liveIcon.draw(LIVE_ICON_POS_X,LIVE_ICON_POS_Y,_liveIcon.getWidth(),_liveIcon.getHeight());
        fboBuffer.draw(BOOTH_PREVIEW_WINDOW_POS_X,BOOTH_PREVIEW_WINDOW_POS_Y,BOOTH_PREVIEW_WINDOW_SIZE_X,BOOTH_PREVIEW_WINDOW_SIZE_Y);
    }else
    {
        _notLiveIcon.draw(LIVE_ICON_POS_X,LIVE_ICON_POS_Y);
        _mainVideo.draw(BOOTH_PREVIEW_WINDOW_POS_X,BOOTH_PREVIEW_WINDOW_POS_Y,BOOTH_PREVIEW_WINDOW_SIZE_X,BOOTH_PREVIEW_WINDOW_SIZE_Y);
    }
    drawEmotionGuideLineText();
}