Ejemplo n.º 1
0
Bool fxShatterInit(CompWindow * w)
{
    CompScreen *s = w->screen;
    ANIMPLUS_DISPLAY (s->display);
    ANIMPLUS_WINDOW (w);

    if (!ad->animAddonFunc->polygonsAnimInit(w))
        return FALSE;

   // CompScreen *s = w->screen;
    int i,static_polygon;
    int screen_height = s->outputDev[outputDeviceForWindow(w)].height;

    ad->animAddonFunc->tessellateIntoGlass( w,
                animGetI( w, ANIMPLUS_SCREEN_OPTION_SHATTER_NUM_SPOKES),
                animGetI( w, ANIMPLUS_SCREEN_OPTION_SHATTER_NUM_TIERS),
                             1); //can't really see how thick it is...

    PolygonSet *pset = aw->eng->polygonSet;
    PolygonObject *p = pset->polygons;

    for (i = 0; i < pset->nPolygons; i++, p++)
    {
        p->rotAxis.x = 0;
        p->rotAxis.y = 0;
        p->rotAxis.z = 1;

        static_polygon = 1;

        p->finalRelPos.x = 0;
        p->finalRelPos.y = static_polygon *
                            (-p->centerPosStart.y + screen_height);
        p->finalRelPos.z = 0;
        if (p->finalRelPos.y)
            p->finalRotAng = RAND_FLOAT() * 120 * ( RAND_FLOAT() < 0.5 ? -1 : 1 );
    }

    pset->allFadeDuration = 0.4f;
    pset->backAndSidesFadeDur = 0.2f;
    pset->doDepthTest = TRUE;
    pset->doLighting = TRUE;
    pset->correctPerspective = CorrectPerspectivePolygon;

    aw->com->animTotalTime /= EXPLODE_PERCEIVED_T;
    aw->com->animRemainingTime = aw->com->animTotalTime;

    return TRUE;
}
Ejemplo n.º 2
0
Archivo: skewer.c Proyecto: Elive/ecomp
static void
getDirection(int *dir, int *c, int direction)
{
   switch (direction)
     {
      case 0:
        // left
        dir[(*c)++] = 0;
        break;

      case 1:
        // right
        dir[(*c)++] = 1;
        break;

      case 2:
        // left-right
        dir[(*c)++] = 0;
        dir[(*c)++] = 1;
        break;

      case 3:
        // up
        dir[(*c)++] = 2;
        break;

      case 4:
        // downs
        dir[(*c)++] = 3;
        break;

      case 5:
        // up-down
        dir[(*c)++] = 2;
        dir[(*c)++] = 3;
        break;

      case 6:
        // in
        dir[(*c)++] = 4;
        break;

      case 7:
        // out
        dir[(*c)++] = 5;
        break;

      case 8:
        // in-out
        dir[(*c)++] = 4;
        dir[(*c)++] = 5;
        break;

      case 9:
        // random
        getDirection (dir, c, floor (RAND_FLOAT () * 8));
        break;
     }
}
Ejemplo n.º 3
0
void
LeafSpreadAnim::init ()
{
    if (!tessellateIntoRectangles (20, 14, 15.0f))
	return;

    CompRect outRect (mAWindow->savedRectsValid () ?
		      mAWindow->savedOutRect () :
		      mWindow->outputRect ());

    float fadeDuration = 0.26;
    float life = 0.4;
    float spreadFac = 3.5;
    float randYMax = 0.07;
    float winFacX = outRect.width () / 800.0;
    float winFacY = outRect.height () / 800.0;
    float winFacZ = (outRect.height () + outRect.width ()) / 2.0 / 800.0;

    float screenSizeFactor = (0.8 * DEFAULT_Z_CAMERA * ::screen->width ());

    foreach (PolygonObject *p, mPolygons)
    {
	p->rotAxis.set (RAND_FLOAT (), RAND_FLOAT (), RAND_FLOAT ());

	float speed = screenSizeFactor / 10 * (0.2 + RAND_FLOAT ());

	float xx = 2 * (p->centerRelPos.x () - 0.5);
	float yy = 2 * (p->centerRelPos.y () - 0.5);

	float x = speed * winFacX * spreadFac * (xx +
						 0.5 * (RAND_FLOAT () - 0.5));
	float y = speed * winFacY * spreadFac * (yy +
						 0.5 * (RAND_FLOAT () - 0.5));
	float z = speed * winFacZ * 7 * ((RAND_FLOAT () - 0.5) / 0.5);

	p->finalRelPos.set (x, y, z);

	p->moveStartTime =
	    p->centerRelPos.y () * (1 - fadeDuration - randYMax) +
	    randYMax * RAND_FLOAT ();
	p->moveDuration = 1;

	p->fadeStartTime = p->moveStartTime + life;
	if (p->fadeStartTime > 1 - fadeDuration)
	    p->fadeStartTime = 1 - fadeDuration;
	p->fadeDuration = fadeDuration;

	p->finalRotAng = 150;
    }
Ejemplo n.º 4
0
/** Stepping **/
void step_cutoff(Annealing *search, int wmindex, float temperature) {
  float ratio = temperature / search->start_temp;
  float interval = ratio * CUT_INT;
  float ra = RAND_FLOAT(1.0); 
  float res = interval * ra - (interval/2.0);
  search->cut[wmindex] += res;
  
  if (search->cut[wmindex] > CUT_MAX) {
    search->cut[wmindex] = CUT_MAX;
  } else if (search->cut[wmindex] < CUT_MIN) {
    search->cut[wmindex] = CUT_MIN;
  }
}
Ejemplo n.º 5
0
PSSM random_pssm(unsigned char order,  const unsigned char min_length, const unsigned char max_length, unsigned char alphlen, int seq) {
  PSSM pssm = initMatrix(order, max_length, alphlen);
  int i;

  pssm->max_length = max_length;

  i = pssm->max_length * pssm->alphabetSize;
  while (i--) pssm->counts[i] = 0 + RAND_INT(seq);

  normalize_pssm(pssm, seq);

  pssm->min_length = min_length;
  pssm->length = min_length + RAND_INT(max_length - min_length);
  
  calcAndSetThresholds(pssm, RAND_FLOAT((2.0 * pssm->length)));
  
  return pssm;
}
Ejemplo n.º 6
0
Bool
fxSkewerInit (CompWindow *w)
{
	if (!polygonsAnimInit (w))
		return FALSE;

	CompScreen *s = w->screen;

	ANIM_WINDOW (w);

	aw->com.animTotalTime /= SKEWER_PERCEIVED_T;
	aw->com.animRemainingTime = aw->com.animTotalTime;

	const BananaValue *
	option_skewer_direction = bananaGetOption (bananaIndex,
	                                           "skewer_direction",
	                                           s->screenNum);

	const BananaValue *
	option_skewer_tessellation = bananaGetOption (bananaIndex,
	                                              "skewer_tessellation",
	                                              s->screenNum);

	const BananaValue *
	option_skewer_thickness = bananaGetOption (bananaIndex,
	                                           "skewer_thickness",
	                                           s->screenNum);

	const BananaValue *
	option_skewer_rotation = bananaGetOption (bananaIndex,
	                                          "skewer_rotation",
	                                          s->screenNum);

	const BananaValue *
	option_skewer_gridx = bananaGetOption (bananaIndex,
	                                       "skewer_gridx",
	                                       s->screenNum);

	const BananaValue *
	option_skewer_gridy = bananaGetOption (bananaIndex,
	                                       "skewer_gridy",
	                                       s->screenNum);

	float thickness = option_skewer_thickness->f;
	int rotation = option_skewer_rotation->i;
	int gridSizeX = option_skewer_gridx->i;
	int gridSizeY = option_skewer_gridy->i;

	int dir[2];             // directions array
	int c = 0;              // number of directions

	getDirection (dir, &c, option_skewer_direction->i);

	if (option_skewer_tessellation->i == PolygonTessHex)
	{
		if (!tessellateIntoHexagons (w, gridSizeX, gridSizeY, thickness))
			return FALSE;
	}
	else
	{
		if (!tessellateIntoRectangles (w, gridSizeX, gridSizeY, thickness))
			return FALSE;
	}

	PolygonSet *pset = aw->eng.polygonSet;
	PolygonObject *p = pset->polygons;

	int times[pset->nPolygons];
	int last_time = pset->nPolygons - 1;

	int i;
	for (i = 0; i < pset->nPolygons; i++)
		times[i] = i;

	for (i = 0; i < pset->nPolygons; i++, p++)
	{
		if (c > 0)
		{
			switch (dir[(int)floor (RAND_FLOAT () * c)]) {
			case 0:
				// left
				p->finalRelPos.x = -s->width;
				p->rotAxis.x = rotation;
				break;

			case 1:
				// right
				p->finalRelPos.x = s->width;
				p->rotAxis.x = rotation;
				break;

			case 2:
				// up
				p->finalRelPos.y = -s->height;
				p->rotAxis.y = rotation;
				break;

			case 3:
				// down
				p->finalRelPos.y = s->height;
				p->rotAxis.y = rotation;
				break;

			case 4:
				// in
				p->finalRelPos.z = -.8 * DEFAULT_Z_CAMERA * s->width;
				p->rotAxis.x = rotation;
				p->rotAxis.y = rotation;
				break;

			case 5:
				// out
				p->finalRelPos.z = .8 * DEFAULT_Z_CAMERA * s->width;
				p->rotAxis.x = rotation;
				p->rotAxis.y = rotation;
				break;
			}

			p->finalRotAng = rotation;
		}
		// if no direction is set - just fade

		// choose random start_time
		int rand_time = floor (RAND_FLOAT () * last_time);

		p->moveStartTime = 0.8 / (float)pset->nPolygons * times[rand_time];
		p->moveDuration = 1 - p->moveStartTime;

		p->fadeStartTime = p->moveStartTime + 0.2;
		p->fadeDuration = 1 - p->fadeStartTime;

		times[rand_time] = times[last_time]; // copy last one over times[rand_time]
		last_time--;    //descrease last_time
	}

	pset->doDepthTest = TRUE;
	pset->doLighting = TRUE;
	pset->correctPerspective = CorrectPerspectiveWindow;

	return TRUE;
}
Ejemplo n.º 7
0
Bool
fxLeafSpreadInit (CompWindow *w)
{
	if (!polygonsAnimInit (w))
		return FALSE;

	CompScreen *s = w->screen;
	ANIM_WINDOW (w);

	if (!tessellateIntoRectangles (w, 20, 14, 15.0f))
		return FALSE;

	PolygonSet *pset = aw->eng.polygonSet;
	PolygonObject *p = pset->polygons;
	float fadeDuration = 0.26;
	float life = 0.4;
	float spreadFac = 3.5;
	float randYMax = 0.07;
	float winFacX = WIN_W (w) / 800.0;
	float winFacY = WIN_H (w) / 800.0;
	float winFacZ = (WIN_H (w) + WIN_W (w)) / 2.0 / 800.0;

	int i;

	for (i = 0; i < pset->nPolygons; i++, p++)
	{
		p->rotAxis.x = RAND_FLOAT ();
		p->rotAxis.y = RAND_FLOAT ();
		p->rotAxis.z = RAND_FLOAT ();

		float screenSizeFactor = (0.8 * DEFAULT_Z_CAMERA * s->width);
		float speed = screenSizeFactor / 10 * (0.2 + RAND_FLOAT ());

		float xx = 2 * (p->centerRelPos.x - 0.5);
		float yy = 2 * (p->centerRelPos.y - 0.5);

		float x =
		        speed * winFacX * spreadFac * (xx +
		                                       0.5 * (RAND_FLOAT () - 0.5));
		float y =
		        speed * winFacY * spreadFac * (yy +
		                                       0.5 * (RAND_FLOAT () - 0.5));
		float z = speed * winFacZ * 7 * ((RAND_FLOAT () - 0.5) / 0.5);

		p->finalRelPos.x = x;
		p->finalRelPos.y = y;
		p->finalRelPos.z = z;

		p->moveStartTime =
		        p->centerRelPos.y * (1 - fadeDuration - randYMax) +
		        randYMax * RAND_FLOAT ();
		p->moveDuration = 1;

		p->fadeStartTime = p->moveStartTime + life;
		if (p->fadeStartTime > 1 - fadeDuration)
			p->fadeStartTime = 1 - fadeDuration;
		p->fadeDuration = fadeDuration;

		p->finalRotAng = 150;
	}
	pset->doDepthTest = TRUE;
	pset->doLighting = TRUE;
	pset->correctPerspective = CorrectPerspectivePolygon;

	aw->com.animTotalTime /= LEAFSPREAD_PERCEIVED_T;
	aw->com.animRemainingTime = aw->com.animTotalTime;

	return TRUE;
}
Bool
fxDominoInit (CompWindow * w)
{
    if (!polygonsAnimInit (w))
	return FALSE;

    ANIMADDON_DISPLAY (w->screen->display);
    ANIMADDON_WINDOW (w);

    Bool isRazr = (aw->com->curAnimEffect == AnimEffectRazr);

    int fallDir;

    if (isRazr)
	fallDir = ad->animBaseFunctions->getActualAnimDirection
	    (w, animGetI (w, ANIMADDON_SCREEN_OPTION_RAZR_DIRECTION), TRUE);
    else
	fallDir = ad->animBaseFunctions->getActualAnimDirection
	    (w, animGetI (w, ANIMADDON_SCREEN_OPTION_DOMINO_DIRECTION), TRUE);

    int defaultGridSize = 20;
    float minCellSize = 30;
    int gridSizeX;
    int gridSizeY;
    int fallDirGridSize;
    float minDistStartEdge;		// half piece size in [0,1] range
    float gridCellW;
    float gridCellH;
    float cellAspectRatio = 1.25;

    if (isRazr)
	cellAspectRatio = 1;

    // Determine sensible domino piece sizes
    if (fallDir == AnimDirectionDown || fallDir == AnimDirectionUp)
    {
	if (minCellSize > BORDER_W(w))
	    minCellSize = BORDER_W(w);
	if (BORDER_W(w) / defaultGridSize < minCellSize)
	    gridSizeX = (int)(BORDER_W(w) / minCellSize);
	else
	    gridSizeX = defaultGridSize;
	gridCellW = BORDER_W(w) / gridSizeX;
	gridSizeY = (int)(BORDER_H(w) / (gridCellW * cellAspectRatio));
	if (gridSizeY == 0)
	    gridSizeY = 1;
	gridCellH = BORDER_H(w) / gridSizeY;
	fallDirGridSize = gridSizeY;
    }
    else
    {
	if (minCellSize > BORDER_H(w))
	    minCellSize = BORDER_H(w);
	if (BORDER_H(w) / defaultGridSize < minCellSize)
	    gridSizeY = (int)(BORDER_H(w) / minCellSize);
	else
	    gridSizeY = defaultGridSize;
	gridCellH = BORDER_H(w) / gridSizeY;
	gridSizeX = (int)(BORDER_W(w) / (gridCellH * cellAspectRatio));
	if (gridSizeX == 0)
	    gridSizeX = 1;
	gridCellW = BORDER_W(w) / gridSizeX;
	fallDirGridSize = gridSizeX;
    }
    minDistStartEdge = (1.0 / fallDirGridSize) / 2;

    float thickness = MIN(gridCellW, gridCellH) / 3.5;

    if (!tessellateIntoRectangles(w, gridSizeX, gridSizeY, thickness))
	return FALSE;

    float rotAxisX = 0;
    float rotAxisY = 0;
    Point3d rotAxisOff = { 0, 0, thickness / 2 };
    float posX = 0;				// position of standing piece
    float posY = 0;
    float posZ = 0;
    int nFallingColumns = gridSizeX;
    float gridCellHalfW = gridCellW / 2;
    float gridCellHalfH = gridCellH / 2;

    switch (fallDir)
    {
    case AnimDirectionDown:
	rotAxisX = -1;
	if (isRazr)
	    rotAxisOff.y = -gridCellHalfH;
	else
	{
	    posY = -(gridCellHalfH + thickness);
	    posZ = gridCellHalfH - thickness / 2;
	}
	break;
    case AnimDirectionLeft:
	rotAxisY = -1;
	if (isRazr)
	    rotAxisOff.x = gridCellHalfW;
	else
	{
	    posX = gridCellHalfW + thickness;
	    posZ = gridCellHalfW - thickness / 2;
	}
	nFallingColumns = gridSizeY;
	break;
    case AnimDirectionUp:
	rotAxisX = 1;
	if (isRazr)
	    rotAxisOff.y = gridCellHalfH;
	else
	{
	    posY = gridCellHalfH + thickness;
	    posZ = gridCellHalfH - thickness / 2;
	}
	break;
    case AnimDirectionRight:
	rotAxisY = 1;
	if (isRazr)
	    rotAxisOff.x = -gridCellHalfW;
	else
	{
	    posX = -(gridCellHalfW + thickness);
	    posZ = gridCellHalfW - thickness / 2;
	}
	nFallingColumns = gridSizeY;
	break;
    }

    float fadeDuration;
    float riseDuration;
    float riseTimeRandMax = 0.2;

    if (isRazr)
    {
	riseDuration = (1 - riseTimeRandMax) / fallDirGridSize;
	fadeDuration = riseDuration / 2;
    }
    else
    {
	fadeDuration = 0.18;
	riseDuration = 0.2;
    }
    float *riseTimeRandSeed = calloc(nFallingColumns, sizeof(float));

    if (!riseTimeRandSeed)
	// TODO: log error here
	return FALSE;
    int i;

    for (i = 0; i < nFallingColumns; i++)
	riseTimeRandSeed[i] = RAND_FLOAT();

    PolygonSet *pset = aw->eng.polygonSet;
    PolygonObject *p = pset->polygons;

    for (i = 0; i < pset->nPolygons; i++, p++)
    {
	p->rotAxis.x = rotAxisX;
	p->rotAxis.y = rotAxisY;
	p->rotAxis.z = 0;

	p->finalRelPos.x = posX;
	p->finalRelPos.y = posY;
	p->finalRelPos.z = posZ;

	// dist. from rise-start / fall-end edge in window ([0,1] range)
	float distStartEdge = 0;

	// dist. from edge perpendicular to movement (for move start time)
	// so that same the blocks in same row/col. appear to knock down
	// the next one
	float distPerpEdge = 0;

	switch (fallDir)
	{
	case AnimDirectionUp:
	    distStartEdge = p->centerRelPos.y;
	    distPerpEdge = p->centerRelPos.x;
	    break;
	case AnimDirectionRight:
	    distStartEdge = 1 - p->centerRelPos.x;
	    distPerpEdge = p->centerRelPos.y;
	    break;
	case AnimDirectionDown:
	    distStartEdge = 1 - p->centerRelPos.y;
	    distPerpEdge = p->centerRelPos.x;
	    break;
	case AnimDirectionLeft:
	    distStartEdge = p->centerRelPos.x;
	    distPerpEdge = p->centerRelPos.y;
	    break;
	}

	float riseTimeRand =
	    riseTimeRandSeed[(int)(distPerpEdge * nFallingColumns)] *
	    riseTimeRandMax;

	p->moveDuration = riseDuration;

	float mult = 1;
	if (fallDirGridSize > 1)
	    mult = ((distStartEdge - minDistStartEdge) /
		    (1 - 2 * minDistStartEdge));
	if (isRazr)
	{
	    p->moveStartTime =
		mult *
		(1 - riseDuration - riseTimeRandMax) + riseTimeRand;
	    p->fadeStartTime = p->moveStartTime + riseDuration / 2;
	    p->finalRotAng = -180;

	    p->rotAxisOffset.x = rotAxisOff.x;
	    p->rotAxisOffset.y = rotAxisOff.y;
	    p->rotAxisOffset.z = rotAxisOff.z;
	}
	else
	{
	    p->moveStartTime =
		mult *
		(1 - riseDuration - riseTimeRandMax) +
		riseTimeRand;
	    p->fadeStartTime =
		p->moveStartTime + riseDuration - riseTimeRand + 0.03;
	    p->finalRotAng = -90;
	}
	if (p->fadeStartTime > 1 - fadeDuration)
	    p->fadeStartTime = 1 - fadeDuration;
	p->fadeDuration = fadeDuration;
    }
    free(riseTimeRandSeed);
    pset->doDepthTest = TRUE;
    pset->doLighting = TRUE;
    pset->correctPerspective = CorrectPerspectivePolygon;

    aw->com->animTotalTime /= DOMINO_PERCEIVED_T;
    aw->com->animRemainingTime = aw->com->animTotalTime;

    return TRUE;
}
Ejemplo n.º 9
0
float anneal_step_wm(Annealing *search, float temperature, float score, int wm_index) {
  float ra = RAND_FLOAT(1.0); 
  float newscore;
  PSSM pssm = WM(wm_index);

  search->last_step[wm_index] = -1;
    /* Modify the WM */

  do {
    ra = RAND_FLOAT(1.0);

    if (ra < PROB_INC_L) {
      if (pssm->length < pssm->max_length) {
	increase_left(search, wm_index, TOTAL, INCLEN);
	search->last_step[wm_index] = INC_L;
      }
    } else if (ra < PROB_INC_R) {
      if (pssm->length < pssm->max_length) {
	increase_right(search, wm_index, TOTAL, INCLEN);
	search->last_step[wm_index] = INC_R;
      }
    } else if (ra < PROB_DEC_L) {
      if (pssm->length > pssm->min_length) {
	decrease_left(search, wm_index, DECLEN);
	search->last_step[wm_index] = DEC_L;
      }
    } else if (ra < PROB_DEC_R) {
      if (pssm->length > pssm->min_length) {
	decrease_right(search, wm_index, DECLEN);
	search->last_step[wm_index] = DEC_R;
      }
    } else if (ra < PROB_MOV_L) {
      if (search->pos_matches > 0) {
	search->last_step[wm_index] = MOV_L;
	move_left(search, wm_index, TOTAL, MOVLEN);
      }
    } else if (ra < PROB_MOV_R) {
      if (search->pos_matches > 0) {
	search->last_step[wm_index] = MOV_R;
	move_right(search, wm_index, TOTAL, MOVLEN);
      }
    } else if (ra < PROB_CUT && search->ctype == ANNEALED) {
      step_cutoff(search, wm_index, temperature);
      search->last_step[wm_index] = CUT;
    } else {
      (*search->stepfunc)(search, wm_index, temperature);
      search->last_step[wm_index] = MOD;
    }
  } while (search->last_step[wm_index] == -1);

  pssm =  WM(wm_index);
  calcAndSetThresholds(pssm, search->cut[wm_index] * (float)pssm->length);  
  newscore = anneal_search(search, wm_index);

  double prob = exp(-(score - newscore)/temperature);

  if (RAND_FLOAT(1.0) < prob) {      /* Accept */   
    save_wm(search, wm_index);
    acc = WGT + MWGT * acc;
    return newscore;
  } else {              /* Reject */
    backroll_wm(search, wm_index);
    acc *= MWGT;
    return score;
  }

}
Ejemplo n.º 10
0
void
DominoAnim::init ()
{
    bool isRazr = (typeid (*this) == typeid (RazrAnim));
    int fallDir;

    if (isRazr)
	fallDir = getActualAnimDirection
	    ((AnimDirection) optValI (AnimationaddonOptions::RazrDirection),
	     true);
    else
	fallDir = getActualAnimDirection
	    ((AnimDirection) optValI (AnimationaddonOptions::DominoDirection),
	     true);

    int defaultGridSize = 20;
    float minCellSize = 30;
    int gridSizeX;
    int gridSizeY;
    int fallDirGridSize;
    float minDistStartEdge;		// half piece size in [0,1] range
    float gridCellW;
    float gridCellH;
    float cellAspectRatio = 1.25;

    if (isRazr)
	cellAspectRatio = 1;

    CompRect outRect (mAWindow->savedRectsValid () ?
		      mAWindow->savedOutRect () :
		      mWindow->outputRect ());

    // Determine sensible domino piece sizes
    if (fallDir == AnimDirectionDown || fallDir == AnimDirectionUp)
    {
	if (minCellSize > outRect.width ())
	    minCellSize = outRect.width ();
	if (outRect.width () / defaultGridSize < minCellSize)
	    gridSizeX = (int)(outRect.width () / minCellSize);
	else
	    gridSizeX = defaultGridSize;
	gridCellW = outRect.width () / gridSizeX;
	gridSizeY = (int)(outRect.height () / (gridCellW * cellAspectRatio));
	if (gridSizeY == 0)
	    gridSizeY = 1;
	gridCellH = outRect.height () / gridSizeY;
	fallDirGridSize = gridSizeY;
    }
    else
    {
	if (minCellSize > outRect.height ())
	    minCellSize = outRect.height ();
	if (outRect.height () / defaultGridSize < minCellSize)
	    gridSizeY = (int)(outRect.height () / minCellSize);
	else
	    gridSizeY = defaultGridSize;
	gridCellH = outRect.height () / gridSizeY;
	gridSizeX = (int)(outRect.width () / (gridCellH * cellAspectRatio));
	if (gridSizeX == 0)
	    gridSizeX = 1;
	gridCellW = outRect.width () / gridSizeX;
	fallDirGridSize = gridSizeX;
    }
    minDistStartEdge = (1.0 / fallDirGridSize) / 2;

    float thickness = MIN (gridCellW, gridCellH) / 3.5;

    if (!tessellateIntoRectangles (gridSizeX, gridSizeY, thickness))
	return;

    float rotAxisX = 0;
    float rotAxisY = 0;
    Point3d rotAxisOff (0, 0, thickness / 2);
    float posX = 0;				// position of standing piece
    float posY = 0;
    float posZ = 0;
    int nFallingColumns = gridSizeX;
    float gridCellHalfW = gridCellW / 2;
    float gridCellHalfH = gridCellH / 2;

    switch (fallDir)
    {
    case AnimDirectionDown:
	rotAxisX = -1;
	if (isRazr)
	    rotAxisOff.setY (-gridCellHalfH);
	else
	{
	    posY = -(gridCellHalfH + thickness);
	    posZ = gridCellHalfH - thickness / 2;
	}
	break;
    case AnimDirectionLeft:
	rotAxisY = -1;
	if (isRazr)
	    rotAxisOff.setX (gridCellHalfW);
	else
	{
	    posX = gridCellHalfW + thickness;
	    posZ = gridCellHalfW - thickness / 2;
	}
	nFallingColumns = gridSizeY;
	break;
    case AnimDirectionUp:
	rotAxisX = 1;
	if (isRazr)
	    rotAxisOff.setY (gridCellHalfH);
	else
	{
	    posY = gridCellHalfH + thickness;
	    posZ = gridCellHalfH - thickness / 2;
	}
	break;
    case AnimDirectionRight:
	rotAxisY = 1;
	if (isRazr)
	    rotAxisOff.setX (-gridCellHalfW);
	else
	{
	    posX = -(gridCellHalfW + thickness);
	    posZ = gridCellHalfW - thickness / 2;
	}
	nFallingColumns = gridSizeY;
	break;
    }

    float fadeDuration;
    float riseDuration;
    float riseTimeRandMax = 0.2;

    if (isRazr)
    {
	riseDuration = (1 - riseTimeRandMax) / fallDirGridSize;
	fadeDuration = riseDuration / 2;
    }
    else
    {
	fadeDuration = 0.18;
	riseDuration = 0.2;
    }

    float riseTimeRandSeed[nFallingColumns];

    for (int i = 0; i < nFallingColumns; i++)
	riseTimeRandSeed[i] = RAND_FLOAT ();

    foreach (PolygonObject *p, mPolygons)
    {
	p->rotAxis.set (rotAxisX, rotAxisY, 0);
	p->finalRelPos.set (posX, posY, posZ);

	// dist. from rise-start / fall-end edge in window ([0,1] range)
	float distStartEdge = 0;

	// dist. from edge perpendicular to movement (for move start time)
	// so that same the blocks in same row/col. appear to knock down
	// the next one
	float distPerpEdge = 0;

	switch (fallDir)
	{
	case AnimDirectionUp:
	    distStartEdge = p->centerRelPos.y ();
	    distPerpEdge = p->centerRelPos.x ();
	    break;
	case AnimDirectionRight:
	    distStartEdge = 1 - p->centerRelPos.x ();
	    distPerpEdge = p->centerRelPos.y ();
	    break;
	case AnimDirectionDown:
	    distStartEdge = 1 - p->centerRelPos.y ();
	    distPerpEdge = p->centerRelPos.x ();
	    break;
	case AnimDirectionLeft:
	    distStartEdge = p->centerRelPos.x ();
	    distPerpEdge = p->centerRelPos.y ();
	    break;
	}

	float riseTimeRand =
	    riseTimeRandSeed[(int)(distPerpEdge * nFallingColumns)] *
	    riseTimeRandMax;

	p->moveDuration = riseDuration;

	float mult = 1;
	if (fallDirGridSize > 1)
	    mult = ((distStartEdge - minDistStartEdge) /
		    (1 - 2 * minDistStartEdge));
	if (isRazr)
	{
	    p->moveStartTime = mult *
		(1 - riseDuration - riseTimeRandMax) + riseTimeRand;
	    p->fadeStartTime = p->moveStartTime + riseDuration / 2;
	    p->finalRotAng = -180;

	    p->rotAxisOffset = rotAxisOff;
	}
	else
	{
	    p->moveStartTime =
		mult *
		(1 - riseDuration - riseTimeRandMax) +
		riseTimeRand;
	    p->fadeStartTime =
		p->moveStartTime + riseDuration - riseTimeRand + 0.03;
	    p->finalRotAng = -90;
	}
	if (p->fadeStartTime > 1 - fadeDuration)
	    p->fadeStartTime = 1 - fadeDuration;
	p->fadeDuration = fadeDuration;
    }
Ejemplo n.º 11
0
Bool
fxExplodeInit (CompWindow *w)
{
	if (!polygonsAnimInit (w))
		return FALSE;

	CompScreen *s = w->screen;
	ANIM_WINDOW (w);

	const BananaValue *
	option_explode_gridx = bananaGetOption (bananaIndex,
	                                        "explode_gridx",
	                                        s->screenNum);

	const BananaValue *
	option_explode_gridy = bananaGetOption (bananaIndex,
	                                        "explode_gridy",
	                                        s->screenNum);

	const BananaValue *
	option_explode_spokes = bananaGetOption (bananaIndex,
	                                         "explode_spokes",
	                                         s->screenNum);

	const BananaValue *
	option_explode_tiers = bananaGetOption (bananaIndex,
	                                        "explode_tiers",
	                                        s->screenNum);

	const BananaValue *
	option_explode_thickness = bananaGetOption (bananaIndex,
	                                            "explode_thickness",
	                                            s->screenNum);

	const BananaValue *
	option_explode_tessellation = bananaGetOption (bananaIndex,
	                                               "explode_tessellation",
	                                               s->screenNum);

	switch (option_explode_tessellation->i)
	{
	case PolygonTessRect:
		if (!tessellateIntoRectangles (w,
		                               option_explode_gridx->i,
		                               option_explode_gridy->i,
		                               option_explode_thickness->f))
			return FALSE;
		break;
	case PolygonTessHex:
		if (!tessellateIntoHexagons (w,
		                             option_explode_gridx->i,
		                             option_explode_gridy->i,
		                             option_explode_thickness->f))
			return FALSE;
		break;
	case PolygonTessGlass:
		if (!tessellateIntoGlass (w,
		                          option_explode_spokes->i,
		                          option_explode_tiers->i,
		                          option_explode_thickness->f))
			return FALSE;
		break;
	default:
		return FALSE;
	}

	PolygonSet *pset = aw->eng.polygonSet;
	PolygonObject *p = pset->polygons;
	double sqrt2 = sqrt (2);

	int i;

	for (i = 0; i < pset->nPolygons; i++, p++)
	{
		p->rotAxis.x = RAND_FLOAT ();
		p->rotAxis.y = RAND_FLOAT ();
		p->rotAxis.z = RAND_FLOAT ();

		float screenSizeFactor = (0.8 * DEFAULT_Z_CAMERA * s->width);
		float speed = screenSizeFactor / 10 * (0.2 + RAND_FLOAT ());

		float xx = 2 * (p->centerRelPos.x - 0.5);
		float yy = 2 * (p->centerRelPos.y - 0.5);

		float x = speed * 2 * (xx + 0.5 * (RAND_FLOAT () - 0.5));
		float y = speed * 2 * (yy + 0.5 * (RAND_FLOAT () - 0.5));

		float distToCenter = sqrt (xx * xx + yy * yy) / sqrt2;
		float moveMult = 1 - distToCenter;
		moveMult = moveMult < 0 ? 0 : moveMult;
		float zbias = 0.1;
		float z = speed * 10 *
		          (zbias + RAND_FLOAT () *
		           pow (moveMult, 0.5));

		p->finalRelPos.x = x;
		p->finalRelPos.y = y;
		p->finalRelPos.z = z;
		p->finalRotAng = RAND_FLOAT () * 540 - 270;
	}
	pset->allFadeDuration = 0.3f;
	pset->doDepthTest = TRUE;
	pset->doLighting = TRUE;
	pset->correctPerspective = CorrectPerspectivePolygon;
	pset->backAndSidesFadeDur = 0.2f;

	aw->com.animTotalTime /= EXPLODE_PERCEIVED_T;
	aw->com.animRemainingTime = aw->com.animTotalTime;

	return TRUE;
}
Ejemplo n.º 12
0
Archivo: skewer.c Proyecto: Elive/ecomp
void
fxSkewerInit(CompScreen *s, CompWindow *w)
{
   ANIM_SCREEN (s);
   ANIM_WINDOW (w);

   aw->animTotalTime /= SKEWER_PERCEIVED_T;
   aw->animRemainingTime = aw->animTotalTime;

   float thickness = animGetF (as, aw, ANIM_SCREEN_OPTION_SKEWER_THICKNESS);
   int rotation = animGetI (as, aw, ANIM_SCREEN_OPTION_SKEWER_ROTATION);
   int gridSizeX = animGetI (as, aw, ANIM_SCREEN_OPTION_SKEWER_GRIDSIZE_X);
   int gridSizeY = animGetI (as, aw, ANIM_SCREEN_OPTION_SKEWER_GRIDSIZE_Y);

   int dir[2]; // directions array
   int c = 0; // number of directions

   getDirection (dir, &c,
                 animGetI (as, aw, ANIM_SCREEN_OPTION_SKEWER_DIRECTION));

   if (animGetI (as, aw, ANIM_SCREEN_OPTION_SKEWER_TESS) == PolygonTessHex)
     {
        if (!tessellateIntoHexagons (w, gridSizeX, gridSizeY, thickness))
          return;
     }
   else
     {
        if (!tessellateIntoRectangles (w, gridSizeX, gridSizeY, thickness))
          return;
     }

   PolygonSet *pset = aw->polygonSet;
   PolygonObject *p = pset->polygons;

   int times[pset->nPolygons];
   int last_time = pset->nPolygons - 1;

   int i;
   for (i = 0; i < pset->nPolygons; i++)
     times[i] = i;

   for (i = 0; i < pset->nPolygons; i++, p++)
     {
        if (c > 0)
          {
             switch (dir[(int)floor (RAND_FLOAT () * c)])
               {
                case 0:
     // left
                  p->finalRelPos.x = -s->width;
                  p->rotAxis.x = rotation;
                  break;

                case 1:
     // right
                  p->finalRelPos.x = s->width;
                  p->rotAxis.x = rotation;
                  break;

                case 2:
     // up
                  p->finalRelPos.y = -s->height;
                  p->rotAxis.y = rotation;
                  break;

                case 3:
     // down
                  p->finalRelPos.y = s->height;
                  p->rotAxis.y = rotation;
                  break;

                case 4:
     // in
                  p->finalRelPos.z = -.8 * DEFAULT_Z_CAMERA * s->width;
                  p->rotAxis.x = rotation;
                  p->rotAxis.y = rotation;
                  break;

                case 5:
     // out
                  p->finalRelPos.z = .8 * DEFAULT_Z_CAMERA * s->width;
                  p->rotAxis.x = rotation;
                  p->rotAxis.y = rotation;
                  break;
               }

             p->finalRotAng = rotation;
          }
        // if no direction is set - just fade

        // choose random start_time
        int rand_time = floor (RAND_FLOAT () * last_time);

        p->moveStartTime = 0.8 / (float)pset->nPolygons * times[rand_time];
        p->moveDuration = 1 - p->moveStartTime;

        p->fadeStartTime = p->moveStartTime + 0.2;
        p->fadeDuration = 1 - p->fadeStartTime;

        times[rand_time] = times[last_time];    // copy last one over times[rand_time]
        last_time--; //descrease last_time
     }

   pset->doDepthTest = TRUE;
   pset->doLighting = TRUE;
   pset->correctPerspective = CorrectPerspectiveWindow;
}