示例#1
0
void APerlinNoise2D::GetValue(float x, float y, float * pvValue, int nNumValue)
{
  int      i, k;
  float    vx, sx, vy, sy;
  int      x1, x2, y1, y2;
  float    value1[3], value2[3];
  float    valueX1[3], valueX2[3];
  float    value[3];
  float    vFinal[3];

  memset(vFinal, 0, sizeof(float) * nNumValue);
  for(i=0; i<m_nOctaveNum; i++)
  {
    if( m_nActiveOctave != -1 && m_nActiveOctave != i )
      continue;

    // Get Horizon interpolated value;
    vx = m_nStartPos[i] % m_nBufferWidth + x / m_nWaveLength[i];
    x1 = int(vx);
    sx = vx - x1;
    sx = S_CURVE(sx);
    x2 = x1 + 1;

    vy = m_nStartPos[i] / m_nBufferWidth + y / m_nWaveLength[i];
    y1 = int(vy);
    sy = vy - y1;
    sy = S_CURVE(sy);
    y2 = y1 + 1;
    
    GetRandValues(x1, y1, value1, nNumValue);
    GetRandValues(x2, y1, value2, nNumValue);
    for(k=0; k<nNumValue; k++)
      valueX1[k] = LERP(sx, value1[k], value2[k]);

    GetRandValues(x1, y2, value1, nNumValue);
    GetRandValues(x2, y2, value2, nNumValue);
    for(k=0; k<nNumValue; k++)
      valueX2[k] = LERP(sx, value1[k], value2[k]);

    if( m_bTurbulence )
    {
      for(k=0; k<nNumValue; k++)
      {
        value[k] = (float)fabs(LERP(sy, valueX1[k], valueX2[k]));
        vFinal[k] += m_vAmplitude[i] * value[k];
      }
    }
    else
    {
      for(k=0; k<nNumValue; k++)
      {
        value[k] = LERP(sy, valueX1[k], valueX2[k]);
        vFinal[k] += m_vAmplitude[i] * value[k];
      }
    }
  }

  for(k=0; k<nNumValue; k++)
    pvValue[k] = vFinal[k];
}
示例#2
0
void TBWidgetAnimationRect::OnAnimationUpdate(float progress)
{
    if (m_mode == MODE_DELTA_IN || m_mode == MODE_DELTA_OUT)
    {
        m_dst_rect = m_src_rect = m_widget->GetRect();
        if (m_dst_rect.Equals(TBRect()))
        {
            // Widget hasn't been laid out yet,
            // the animation was started too soon.
            TBAnimationManager::AbortAnimation(this, true);
            return;
        }
        if (m_mode == MODE_DELTA_IN)
        {
            m_dst_rect.x += m_delta_rect.x;
            m_dst_rect.y += m_delta_rect.y;
            m_dst_rect.w += m_delta_rect.w;
            m_dst_rect.h += m_delta_rect.h;
        }
        else
        {
            m_src_rect.x += m_delta_rect.x;
            m_src_rect.y += m_delta_rect.y;
            m_src_rect.w += m_delta_rect.w;
            m_src_rect.h += m_delta_rect.h;
        }
        m_mode = MODE_SRC_TO_DST;
    }
    TBRect rect;
    rect.x = (int) LERP(m_src_rect.x, m_dst_rect.x, progress);
    rect.y = (int) LERP(m_src_rect.y, m_dst_rect.y, progress);
    rect.w = (int) LERP(m_src_rect.w, m_dst_rect.w, progress);
    rect.h = (int) LERP(m_src_rect.h, m_dst_rect.h, progress);
    m_widget->SetRect(rect);
}
示例#3
0
template <class T>	T  pnoise(T x,T y, int px, int py,const unsigned char *perm) {
    int ix0, iy0, ix1, iy1;
    T	fx0, fy0, fx1, fy1;
    T	s, t, nx0, nx1, n0, n1;

	px	=	max(px,1);
	py	=	max(py,1);

    ix0 = FASTFLOOR( x );
    iy0 = FASTFLOOR( y );
    fx0 = x - ix0;
    fy0 = y - iy0;
    fx1 = fx0 - 1.0f;
    fy1 = fy0 - 1.0f;
    ix1 = (( ix0 + 1 ) % px) & 0xff;
    iy1 = (( iy0 + 1 ) % py) & 0xff;
    ix0 = ( ix0 % px ) & 0xff;
    iy0 = ( iy0 % py ) & 0xff;
    
    t = FADE( fy0 );
    s = FADE( fx0 );

    nx0 = grad(perm[ix0 + perm[iy0]], fx0, fy0);
    nx1 = grad(perm[ix0 + perm[iy1]], fx0, fy1);
    n0 = LERP( t, nx0, nx1 );

    nx0 = grad(perm[ix1 + perm[iy0]], fx1, fy0);
    nx1 = grad(perm[ix1 + perm[iy1]], fx1, fy1);
    n1 = LERP(t, nx0, nx1);

    return 0.5f * (1.0f + 0.507f * ( LERP( s, n0, n1 ) ) );
}
示例#4
0
void	EffectScene::Object::Primitive::SetLayerMaterials( Texture2D& _LayeredTextures, int _Mat0, int _Mat1, int _Mat2, int _Mat3 )
{
	const MaterialBank::Material::DynamicParameters*	ppMats[4] =
	{
		&m_Owner.m_Owner.m_pMaterials->GetMaterialAt( _Mat0 ).GetDynamic(),
		&m_Owner.m_Owner.m_pMaterials->GetMaterialAt( _Mat1 ).GetDynamic(),
		&m_Owner.m_Owner.m_pMaterials->GetMaterialAt( _Mat2 ).GetDynamic(),
		&m_Owner.m_Owner.m_pMaterials->GetMaterialAt( _Mat3 ).GetDynamic(),
	};

	m_pTextures = &_LayeredTextures;

	m_pCB_Primitive->m.MatIDs[0] = _Mat0;
	m_pCB_Primitive->m.MatIDs[1] = _Mat1;
	m_pCB_Primitive->m.MatIDs[2] = _Mat2;
	m_pCB_Primitive->m.MatIDs[3] = _Mat3;

	m_pCB_Primitive->m.Thickness.Set( MAX( 1e-6f, ppMats[0]->Thickness ), MAX( 1e-6f, ppMats[1]->Thickness ), MAX( 1e-6f, ppMats[2]->Thickness ), MAX( 1e-6f, ppMats[3]->Thickness ) );
	m_pCB_Primitive->m.IOR.Set( ppMats[1]->IOR, ppMats[2]->IOR, ppMats[3]->IOR );
	m_pCB_Primitive->m.Frosting.Set( ppMats[1]->Frosting, ppMats[2]->Frosting, ppMats[3]->Frosting );
	m_pCB_Primitive->m.NoDiffuse.Set( ppMats[0]->NoDiffuse, ppMats[1]->NoDiffuse, ppMats[2]->NoDiffuse, ppMats[3]->NoDiffuse );

	// Extinctions are given as [0,1] numbers from totally transparent to completely opaque
	// We need to convert them into actual extinction values to be used in the classical exp( -Sigma_t * Distance(millimeters) ) formula
	// We simply assume the opacity of the layer below should be a very low value for extinction=1 when the ray of light travels the layer's whole thickness:
	const float	LOW_OPACITY_VALUE = 1e-3;
	NjFloat3	TargetValueAtThickness(
		logf( LERP( LOW_OPACITY_VALUE, 1.0f, ppMats[1]->Opacity ) ) / m_pCB_Primitive->m.Thickness.y,
		logf( LERP( LOW_OPACITY_VALUE, 1.0f, ppMats[2]->Opacity ) ) / m_pCB_Primitive->m.Thickness.z,
		logf( LERP( LOW_OPACITY_VALUE, 1.0f, ppMats[3]->Opacity ) ) / m_pCB_Primitive->m.Thickness.w
		);

	m_pCB_Primitive->m.Extinction = TargetValueAtThickness;
}
示例#5
0
/** 2D float Perlin noise.
 */
float noise2( float x, float y )
{
    int ix0, iy0, ix1, iy1;
    float fx0, fy0, fx1, fy1;
    float s, t, nx0, nx1, n0, n1;

    ix0 = FASTFLOOR( x ); // Integer part of x
    iy0 = FASTFLOOR( y ); // Integer part of y
    fx0 = x - ix0;        // Fractional part of x
    fy0 = y - iy0;        // Fractional part of y
    fx1 = fx0 - 1.0f;
    fy1 = fy0 - 1.0f;
    ix1 = (ix0 + 1) & 0xff;  // Wrap to 0..255
    iy1 = (iy0 + 1) & 0xff;
    ix0 = ix0 & 0xff;
    iy0 = iy0 & 0xff;
    
    t = FADE( fy0 );
    s = FADE( fx0 );

    nx0 = noise_grad2(noise_perm[ix0 + noise_perm[iy0]], fx0, fy0);
    nx1 = noise_grad2(noise_perm[ix0 + noise_perm[iy1]], fx0, fy1);
    n0 = LERP( t, nx0, nx1 );

    nx0 = noise_grad2(noise_perm[ix1 + noise_perm[iy0]], fx1, fy0);
    nx1 = noise_grad2(noise_perm[ix1 + noise_perm[iy1]], fx1, fy1);
    n1 = LERP(t, nx0, nx1);

    return 0.507f * ( LERP( s, n0, n1 ) );
}
示例#6
0
/** 2D float Perlin periodic noise.
 */
float pnoise2( float x, float y, int px, int py )
{
    int ix0, iy0, ix1, iy1;
    float fx0, fy0, fx1, fy1;
    float s, t, nx0, nx1, n0, n1;

    ix0 = FASTFLOOR( x ); // Integer part of x
    iy0 = FASTFLOOR( y ); // Integer part of y
    fx0 = x - ix0;        // Fractional part of x
    fy0 = y - iy0;        // Fractional part of y
    fx1 = fx0 - 1.0f;
    fy1 = fy0 - 1.0f;
    ix1 = (( ix0 + 1 ) % px) & 0xff;  // Wrap to 0..px-1 and wrap to 0..255
    iy1 = (( iy0 + 1 ) % py) & 0xff;  // Wrap to 0..py-1 and wrap to 0..255
    ix0 = ( ix0 % px ) & 0xff;
    iy0 = ( iy0 % py ) & 0xff;
    
    t = FADE( fy0 );
    s = FADE( fx0 );

    nx0 = grad2(perm[ix0 + perm[iy0]], fx0, fy0);
    nx1 = grad2(perm[ix0 + perm[iy1]], fx0, fy1);
    n0 = LERP( t, nx0, nx1 );

    nx0 = grad2(perm[ix1 + perm[iy0]], fx1, fy0);
    nx1 = grad2(perm[ix1 + perm[iy1]], fx1, fy1);
    n1 = LERP(t, nx0, nx1);

    return 0.507f * ( LERP( s, n0, n1 ) );
}
示例#7
0
文件: lerp_vec4.c 项目: jgan42/rt
t_vec4		lerp_vec4(t_vec4 a, t_vec4 b, t_vec4 x, t_vec4 max)
{
    a.x = LERP(a.x, b.x, x.x, max.x);
    a.y = LERP(a.y, b.y, x.y, max.y);
    a.z = LERP(a.z, b.z, x.z, max.z);
    a.w = LERP(a.w, b.w, x.w, max.w);
    return (a);
}
示例#8
0
文件: lerp_vec4.c 项目: jgan42/rt
t_vec4		lerp_vec4_1(t_vec4 a, t_vec4 b, t_float x, t_float max)
{
    a.x = LERP(a.x, b.x, x, max);
    a.y = LERP(a.y, b.y, x, max);
    a.z = LERP(a.z, b.z, x, max);
    a.w = LERP(a.w, b.w, x, max);
    return (a);
}
示例#9
0
文件: s_blit.c 项目: nikai3d/mesa
static INLINE GLfloat
lerp_2d(GLfloat a, GLfloat b,
        GLfloat v00, GLfloat v10, GLfloat v01, GLfloat v11)
{
   const GLfloat temp0 = LERP(a, v00, v10);
   const GLfloat temp1 = LERP(a, v01, v11);
   return LERP(b, temp0, temp1);
}
示例#10
0
文件: exeval.c 项目: oleavitt/gem
void eval_vlerp(Expr *expr)
{
	expr->l->l->fn(expr->l->l);
	expr->l->r->fn(expr->l->r);
	expr->r->fn(expr->r);
	expr->v.x = LERP(expr->l->l->v.x, expr->l->r->v.x, expr->r->v.x);
	expr->v.y = LERP(expr->l->l->v.x, expr->l->r->v.y, expr->r->v.y);
	expr->v.z = LERP(expr->l->l->v.x, expr->l->r->v.z, expr->r->v.z);
}
示例#11
0
long check_point(Point3 p1, Point3 p2, float alpha, long mask)
{
Point3 plane_point;

   plane_point.x = LERP(alpha, p1.x, p2.x);
   plane_point.y = LERP(alpha, p1.y, p2.y);
   plane_point.z = LERP(alpha, p1.z, p2.z);
   return(face_plane(plane_point) & mask);
}
示例#12
0
///
//	CheckPoint()
//
//	Test the point "alpha" of the way from P1 to P2 
//  See if it is on a face of the cube   
//	Consider only faces in "mask"                   
static
int CheckPoint(const vector3& p1, const vector3& p2, number alpha, long mask)
{
	vector3 plane_point;

	plane_point.x() = LERP(alpha, p1.x(), p2.x());
	plane_point.y() = LERP(alpha, p1.y(), p2.y());
	plane_point.z() = LERP(alpha, p1.z(), p2.z());
	return(FacePlane(plane_point) & mask);
}
示例#13
0
void render(uchar* image,
            uint width, uint height,
            uint max_iterations,
            float x_scale,
            float y_scale,
            float x_adjust,
            float y_adjust)
{
    for (uint x_dim = 0; x_dim < width; x_dim++) {
        for (uint y_dim = 0; y_dim < height; y_dim++) {
            uint index = BYTES_PER_PIXEL * (width * y_dim + x_dim);
            float x_origin = ((float) x_dim/width)*x_scale - x_adjust;
            float y_origin = ((float) y_dim/width)*y_scale - y_adjust;

            float x = 0.0;
            float y = 0.0;
            uint iteration = 0;

            // Escape time algorithm
            while(x*x + y*y < LIMIT && iteration < max_iterations) {
                float xtemp = x*x - y*y + x_origin;
                y = 2*x*y + y_origin;
                x = xtemp;
                iteration++;
            }

            if (iteration == max_iterations) {
                image[index    ] = 0;
                image[index + 1] = 0;
                image[index + 2] = 0;
                image[index + 3] = 0;
            }
            else {
                // Continous coloring
                // Computes the color as a linear interpolation of surrounding points
                // smoothing the color transition.
                float zn  = sqrt(x*x + y*y);
                float nu  = log10f(log10f(zn) / log10f(2)) / log10f(2);
                float itr = ((float) iteration) + 1 - nu;
                float t   = fmodf(itr, 1.0);
                iteration = (uint) itr;
                uint color1 = iteration;
                uint color2 = iteration+1;

                // Assign RGB values by multiplying the iteration count by a even multiples.
                // Should replace this with a predefined colormap.
                image[index    ] = 1;
                image[index + 1] = ((uint) LERP(color1, color2, t)*2) % max_iterations;
                image[index + 2] = ((uint) LERP(color1, color2, t)*4) % max_iterations;
                image[index + 3] = ((uint) LERP(color1, color2, t)*6) % max_iterations;
            }
        }
    }
}
static void
apply_vbr_preset(lame_global_flags * gfp, int a, int enforce)
{
    vbr_presets_t const *vbr_preset = lame_get_VBR(gfp) == vbr_rh ? &vbr_old_switch_map[0]
        : &vbr_psy_switch_map[0];
    float   x = gfp->VBR_q_frac;
    vbr_presets_t p = vbr_preset[a];
    vbr_presets_t q = vbr_preset[a + 1];
    vbr_presets_t const *set = &p;

    NOOP(vbr_q);
    NOOP(quant_comp);
    NOOP(quant_comp_s);
    NOOP(expY);
    LERP(st_lrm);
    LERP(st_s);
    LERP(masking_adj);
    LERP(masking_adj_short);
    LERP(ath_lower);
    LERP(ath_curve);
    LERP(ath_sensitivity);
    LERP(interch);
    NOOP(safejoint);
    NOOP(sfb21mod);
    LERP(msfix);

    (void) lame_set_VBR_q(gfp, set->vbr_q);
    SET_OPTION(quant_comp, set->quant_comp, -1);
    SET_OPTION(quant_comp_short, set->quant_comp_s, -1);
    if (set->expY) {
        (void) lame_set_experimentalY(gfp, set->expY);
    }
    SET_OPTION(short_threshold_lrm, set->st_lrm, -1);
    SET_OPTION(short_threshold_s, set->st_s, -1);
    SET_OPTION(maskingadjust, set->masking_adj, 0);
    SET_OPTION(maskingadjust_short, set->masking_adj_short, 0);
    SET_OPTION(ATHlower, set->ath_lower, 0);
    SET_OPTION(ATHcurve, set->ath_curve, -1);
    SET_OPTION(athaa_sensitivity, set->ath_sensitivity, 0);
    if (set->interch > 0) {
        SET_OPTION(interChRatio, set->interch, -1);
    }

    /* parameters for which there is no proper set/get interface */
    if (set->safejoint > 0) {
        (void) lame_set_exp_nspsytune(gfp, lame_get_exp_nspsytune(gfp) | set->safejoint);
    }
    if (set->sfb21mod > 0) {
        (void) lame_set_exp_nspsytune(gfp, lame_get_exp_nspsytune(gfp) | (set->sfb21mod << 20));
    }
    SET_OPTION(msfix, set->msfix, -1);

    if (enforce == 0) {
        gfp->VBR_q = a;
        gfp->VBR_q_frac = x;
    }
}
double
SVGFETurbulenceElement::Noise2(int aColorChannel, double aVec[2],
                               StitchInfo *aStitchInfo)
{
  int bx0, bx1, by0, by1, b00, b10, b01, b11;
  double rx0, rx1, ry0, ry1, *q, sx, sy, a, b, t, u, v;
  long i, j;
  t = aVec[0] + sPerlinN;
  bx0 = (int) t;
  bx1 = bx0 + 1;
  rx0 = t - (int) t;
  rx1 = rx0 - 1.0f;
  t = aVec[1] + sPerlinN;
  by0 = (int) t;
  by1 = by0 + 1;
  ry0 = t - (int) t;
  ry1 = ry0 - 1.0f;
  // If stitching, adjust lattice points accordingly.
  if (aStitchInfo != NULL) {
    if (bx0 >= aStitchInfo->mWrapX)
      bx0 -= aStitchInfo->mWidth;
    if (bx1 >= aStitchInfo->mWrapX)
      bx1 -= aStitchInfo->mWidth;
    if (by0 >= aStitchInfo->mWrapY)
      by0 -= aStitchInfo->mHeight;
    if (by1 >= aStitchInfo->mWrapY)
      by1 -= aStitchInfo->mHeight;
  }
  bx0 &= sBM;
  bx1 &= sBM;
  by0 &= sBM;
  by1 &= sBM;
  i = mLatticeSelector[bx0];
  j = mLatticeSelector[bx1];
  b00 = mLatticeSelector[i + by0];
  b10 = mLatticeSelector[j + by0];
  b01 = mLatticeSelector[i + by1];
  b11 = mLatticeSelector[j + by1];
  sx = double (S_CURVE(rx0));
  sy = double (S_CURVE(ry0));
  q = mGradient[aColorChannel][b00];
  u = rx0 * q[0] + ry0 * q[1];
  q = mGradient[aColorChannel][b10];
  v = rx1 * q[0] + ry0 * q[1];
  a = LERP(sx, u, v);
  q = mGradient[aColorChannel][b01];
  u = rx0 * q[0] + ry1 * q[1];
  q = mGradient[aColorChannel][b11];
  v = rx1 * q[0] + ry1 * q[1];
  b = LERP(sx, u, v);
  return LERP(sy, a, b);
}
示例#16
0
void	Scene_LerpFaceVert(float amt, scenefacevert_t *v1, scenefacevert_t *v2, scenefacevert_t *out)
{	
	out->vtx[0] = LERP(amt, v1->vtx[0], v2->vtx[0]);
	out->vtx[1] = LERP(amt, v1->vtx[1], v2->vtx[1]);
	out->vtx[2] = LERP(amt, v1->vtx[2], v2->vtx[2]);	
	out->tex[0] = LERP(amt, v1->tex[0], v2->tex[0]);
	out->tex[1] = LERP(amt, v1->tex[1], v2->tex[1]);
	out->col[0] = LERP(amt, (float)v1->col[0], (float)v2->col[0]);
	out->col[1] = LERP(amt, (float)v1->col[1], (float)v2->col[1]);
	out->col[2] = LERP(amt, (float)v1->col[2], (float)v2->col[2]);
	out->col[3] = LERP(amt, (float)v1->col[3], (float)v2->col[3]);
}
示例#17
0
文件: exeval.c 项目: oleavitt/gem
void eval_lerp(Expr *expr)
{
	expr->l->l->fn(expr->l->l);
	expr->l->r->fn(expr->l->r);
	expr->r->fn(expr->r);
	expr->v.x = LERP(expr->l->l->v.x, expr->l->r->v.x, expr->r->v.x);
}
示例#18
0
void CBoidBird::ClampSpeed(SBoidContext& bc,float dt)
{
	if(m_status == Bird::ON_GROUND)
	{
		if(m_onGroundStatus == Bird::OGS_WALKING)
		{
			m_speed = m_walkSpeed;
		}
		else if(m_onGroundStatus == Bird::OGS_SLOWINGDOWN)
		{
			float elapsedTimeNormalized = clamp_tpl(m_elapsedSlowdownTime / bc.fWalkToIdleDuration, 0.0f, 1.0f);
			m_speed = LERP(m_walkSpeed, 0.0f, elapsedTimeNormalized);
		}
		else if(m_onGroundStatus == Bird::OGS_IDLE)
		{
			m_speed = 0.0f;
		}
	}
	else
	{
		if (m_speed > bc.MaxSpeed)
			m_speed = bc.MaxSpeed;
		if (m_speed < bc.MinSpeed)
			m_speed = bc.MinSpeed;
	}
}
示例#19
0
static double noise3(int * p, double x, double y, double z)
{
  int X = (int)FASTFLOOR(x) & 255,                   /* FIND UNIT CUBE THAT */
      Y = (int)FASTFLOOR(y) & 255,                   /* CONTAINS POINT.     */
      Z = (int)FASTFLOOR(z) & 255;

  double u, v, w;

  int A = p[X  ]+Y, AA = p[A]+Z, AB = p[A+1]+Z,      /* HASH COORDINATES OF */
      B = p[X+1]+Y, BA = p[B]+Z, BB = p[B+1]+Z;      /* THE 8 CUBE CORNERS, */

  x -= FASTFLOOR(x);                                  /* FIND RELATIVE X,Y,Z */
  y -= FASTFLOOR(y);                                  /* OF POINT IN CUBE.   */
  z -= FASTFLOOR(z);

  u = FADE(x);                                       /* COMPUTE FADE CURVES */
  v = FADE(y);                                       /* FOR EACH OF X,Y,Z.  */
  w = FADE(z);

  return LERP(w, LERP(v, LERP(u, GRAD(p[AA  ], x    , y    , z     ),  /* AND ADD */
                                 GRAD(p[BA  ], x-1.0, y    , z     )), /* BLENDED */
                         LERP(u, GRAD(p[AB  ], x    , y-1.0, z     ),  /* RESULTS */
                                 GRAD(p[BB  ], x-1.0, y-1.0, z     ))),/* FROM  8 */
                 LERP(v, LERP(u, GRAD(p[AA+1], x    , y    , z-1.0 ),  /* CORNERS */
                                 GRAD(p[BA+1], x-1.0, y    , z-1.0 )), /* OF CUBE */
                         LERP(u, GRAD(p[AB+1], x    , y-1.0, z-1.0 ),
                                 GRAD(p[BB+1], x-1.0, y-1.0, z-1.0 ))));
}
fastf_t
texture_perlin_omega(struct texture_perlin_s *P, vect_t V)
{
    vect_t q;
    fastf_t r0[3], r1[3], sy, sz, a, b, c, d, t, u, v;
    int b0[3], b1[3], b00, b10, b01, b11;
    int i, j;


    for (i = 0; i < 3; i++) {
	t = V[i] + N;
	b0[i] = ((int)t) & BM;
	b1[i] = (b0[i]+1) & BM;
	r0[i] = t - (int)t;
	r1[i] = r0[i] - 1.0;
    }

    i = P->PV[b0[0]];
    j = P->PV[b1[0]];

    b00 = P->PV[i + b0[1]];
    b10 = P->PV[j + b0[1]];
    b01 = P->PV[i + b1[1]];
    b11 = P->PV[j + b1[1]];

    t = S_CURVE(r0[0]);
    sy = S_CURVE(r0[1]);
    sz = S_CURVE(r0[2]);

    VMOVE(q, P->RV[b00 + b0[2]]);
    u = AT3(r0[0], r0[1], r0[2]);
    VMOVE(q, P->RV[b10 + b0[2]]);
    v = AT3(r1[0], r0[1], r0[2]);
    a = LERP(t, u, v);

    VMOVE(q, P->RV[b01 + b0[2]]);
    u = AT3(r0[0], r1[1], r0[2]);
    VMOVE(q, P->RV[b11 + b0[2]]);
    v = AT3(r1[0], r1[1], r0[2]);
    b = LERP(t, u, v);

    c = LERP(sy, a, b);

    VMOVE(q, P->RV[b00 + b1[2]]);
    u = AT3(r0[0], r0[1], r1[2]);
    VMOVE(q, P->RV[b10 + b1[2]]);
    v = AT3(r1[0], r0[1], r1[2]);
    a = LERP(t, u, v);

    VMOVE(q, P->RV[b01 + b1[2]]);
    u = AT3(r0[0], r1[1], r1[2]);
    VMOVE(q, P->RV[b11 + b1[2]]);
    v = AT3(r1[0], r1[1], r1[2]);
    b = LERP(t, u, v);

    d = LERP(sy, a, b);

    return LERP(sz, c, d);
}
//------------------------------------------------------------------------
void CGameRulesHoldObjectiveBase::UpdateEffect(float frameTime)
{
	IEntity *pRingEntity = gEnv->pEntitySystem->GetEntity(m_effectData.ringEntityID);
	
	if(pRingEntity)
	{
		// Update lerps
		m_effectData.materialColorLerp.UpdateLerp(frameTime);
		m_effectData.particleColorLerp.UpdateLerp(frameTime);

		// Update ring cgf
		if(m_effectData.alphaLerp.HasFinishedLerping() == false)
		{
			if(m_effectData.alphaFadeInDelay > 0.0f)
			{
				m_effectData.alphaFadeInDelay -= frameTime;
				if(m_effectData.alphaFadeInDelay <= 0.0f)
				{
					m_effectData.alphaFadeInDelay = 0.0f;
					float alpha = min(m_effectData.alphaLerp.GetValue(),0.99f);
					SetRingAlpha(pRingEntity,alpha);
					pRingEntity->Hide(false);
				}
			}
			else
			{
				m_effectData.alphaLerp.UpdateLerp(frameTime);
				float alpha = min(m_effectData.alphaLerp.GetValue(),0.99f);
				SetRingAlpha(pRingEntity,alpha);
				
				// Fully faded out, so hide
				if(m_effectData.alphaLerp.HasFinishedLerping() && m_effectData.alphaLerp.GetNewValue() == 0.0f)
				{
					pRingEntity->Hide(true);
					SetNewEffectColor(eRPT_Neutral);
				}
			}
		}

		// Update Color
		float lerpValue = m_effectData.materialColorLerp.GetValue();
		Vec3 currentColor = LERP(*m_effectData.pPrevCol,*m_effectData.pDestCol,lerpValue);

		// Set ring color
		IEntityRenderProxy* pRenderProxy = (IEntityRenderProxy*)pRingEntity->GetProxy(ENTITY_PROXY_RENDER);
		if(pRenderProxy)
		{
			IMaterial* pRingMaterial = pRenderProxy->GetRenderMaterial();
			SetMaterialDiffuseColor(pRingMaterial,currentColor);
		}
		
		// Set particle geom material color
		SetMaterialDiffuseColor(m_effectData.pParticleGeomMaterial,currentColor);
	}
}
示例#22
0
void HangingLetterSign::AnimateWind()
{
	unsigned int time = GetTicks();
	unsigned int elapsed = time - mStartTime;
	IvVector3 pos;
	this->GetLocalPosition(pos);
	float t = elapsed/(float)mWindDuration;
	
	if(t > 1.0f)
	{
			//this->ResetLocalTransform();//Start with identity
			//this->Translate(pos);
			IdleAnimate();
			return;
			/*GameMessage msg;
			msg.mEventName = "FINISHED";
			msg.mSender = mID;
			SendOutMessage(msg);
			return;*/
	}

	float noise = 0.2f* Perlin::Noise(time*0.001f,pos.x*0.01f);
	float hiFreqNoise = Perlin::Noise(time*0.007f,pos.x*0.01f);
	//ramp noise based on proximity to start and end animation
	
	//have to start with 1.0f times noise because that is what was driving the position and motion of the sign before
	//this animation... if you didn't start with the regular noise value then you would get a hitch in position.
	float s = 2.0f;
	if(t <= 0.25f)
		s = LERP(t*4.0f,1.0f,2.0f);
	else if( t >= 0.75f)
		s = LERP((t-0.75f)*4.0f,2.0f,1.0f);

	mLastUpdateTime = time;
	
	this->ResetLocalTransform();//Start with identity
	this->Translate(pos);
	
	float negNoise = -(0.5f*noise + 0.5f);
	this->Rotate(s*noise*0.3,s*hiFreqNoise*0.5f,s*negNoise*0.5);
	
}
示例#23
0
void CBattleDust::UpdateParticlesForArea(CBattleEvent* pEvent)
{
	float oldParticleCount = pEvent->m_numParticles;
	float fraction = CLAMP((pEvent->m_radius - m_entitySpawnPower) / (m_maxEventPower - m_entitySpawnPower), 0.0f, 1.0f);
	pEvent->m_numParticles = LERP(m_minParticleCount, m_maxParticleCount, fraction);

	if(pEvent->GetGameObject() && oldParticleCount != pEvent->m_numParticles)
	{
		pEvent->GetGameObject()->ChangedNetworkState(CBattleEvent::PROPERTIES_ASPECT);
	}
}
示例#24
0
float Noise::smoothNoise3(Vec3f &vec)
{
  int bx0, bx1, by0, by1, bz0, bz1, b00, b10, b01, b11;
  float rx0, rx1, ry0, ry1, rz0, rz1, *q, sy, sz, a, b, c, d, t, u, v;
  int i, j;

  SETUP(vec.x(), bx0, bx1, rx0, rx1);
  SETUP(vec.y(), by0, by1, ry0, ry1);
  SETUP(vec.z(), bz0, bz1, rz0, rz1);

  i = p[bx0];
  j = p[bx1];

  b00 = p[i + by0];
  b10 = p[j + by0];
  b01 = p[i + by1];
  b11 = p[j + by1];

  t = SCURVE(rx0);
  sy = SCURVE(ry0);
  sz = SCURVE(rz0);

#define AT3(rx, ry, rz) ((rx)*q[0] + (ry)*q[1] + (rz)*q[2])

  q = g3[b00 + bz0];
  u = AT3(rx0, ry0, rz0);
  q = g3[b10 + bz0];
  v = AT3(rx1, ry0, rz0);
  a = LERP(t, u, v);

  q = g3[b01 + bz0];
  u = AT3(rx0, ry1, rz0);
  q = g3[b11 + bz0];
  v = AT3(rx1, ry1, rz0);
  b = LERP(t, u, v);

  c = LERP(sy, a, b);

  q = g3[b00 + bz1];
  u = AT3(rx0, ry0, rz1);
  q = g3[b10 + bz1];
  v = AT3(rx1, ry0, rz1);
  a = LERP(t, u, v);

  q = g3[b01 + bz1];
  u = AT3(rx0, ry1, rz1);
  q = g3[b11 + bz1];
  v = AT3(rx1, ry1, rz1);
  b = LERP(t, u, v);

  d = LERP(sy, a, b);

#undef AT3

  return LERP(sz, c, d);
}
示例#25
0
//---------------------------------------------------------
void FSMAIControl::UpdatePerceptions(float dt)
{
    if(m_willCollide)
        m_safetyRadius = 30.0f;
    else
        m_safetyRadius = 15.0f;

    //store closest asteroid and powerup
    m_nearestAsteroid = Game.GetClosestGameObj(m_ship,GameObj::OBJ_ASTEROID);
    m_nearestPowerup  = Game.GetClosestGameObj(m_ship,GameObj::OBJ_POWERUP);

    //asteroid collision determination
    m_willCollide = false;
    if(m_nearestAsteroid)
    {
        float speed = m_ship->m_velocity.Length();
        m_nearestAsteroidDist = m_nearestAsteroid->m_position.Distance(m_ship->m_position);
        Point3f normDelta = m_nearestAsteroid->m_position - m_ship->m_position;
        normDelta.Normalize();
        float astSpeed = m_nearestAsteroid->m_velocity.Length();
        float shpSpeedAdj = DOT(m_ship->UnitVectorVelocity(),normDelta)*speed;
        float astSpeedAdj = DOT(m_nearestAsteroid->UnitVectorVelocity(),-normDelta)*astSpeed;
        speed = shpSpeedAdj+astSpeedAdj;

//        if(speed > astSpeed)
//            dotVel  = DOT(m_ship->UnitVectorVelocity(),normDelta);
//        else
//        {
//            speed = astSpeed;
//            dotVel = DOT(m_nearestAsteroid->UnitVectorVelocity(),-normDelta);
//        }
        float spdAdj = LERP(speed/m_maxSpeed,0.0f,90.0f);
        float adjSafetyRadius = m_safetyRadius+spdAdj+m_nearestAsteroid->m_size;

        //if you're too close, and I'm heading somewhat towards you,
        //flag a collision
        if(m_nearestAsteroidDist <= adjSafetyRadius && speed > 0)
            m_willCollide = true;
    }

    //powerup near determination
    m_powerupNear = false;
    if(m_nearestPowerup)
    {
        m_nearestPowerupDist = m_nearestPowerup->m_position.Distance(m_ship->m_position);
        if(m_nearestPowerupDist <= POWERUP_SCAN_DIST)
        {
            m_powerupNear     = true;
        }
    }

}
示例#26
0
float Noise::smoothNoise2(Vec2f &vec)
{
  int bx0, bx1, by0, by1, b00, b10, b01, b11;
  float rx0, rx1, ry0, ry1, *q, sx, sy, a, b, t, u, v;
  int i, j;

  SETUP(vec.x(), bx0, bx1, rx0, rx1);
  SETUP(vec.y(), by0, by1, ry0, ry1);

  i = p[bx0];
  j = p[bx1];

  b00 = p[i + by0];
  b10 = p[j + by0];
  b01 = p[i + by1];
  b11 = p[j + by1];

  sx = SCURVE(rx0);
  sy = SCURVE(ry0);

#define AT2(rx, ry) ((rx)*q[0] + (ry)*q[1])

  q = g2[b00];
  u = AT2(rx0, ry0);
  q = g2[b10];
  v = AT2(rx1, ry0);
  a = LERP(sx, u, v);

  q = g2[b01];
  u = AT2(rx0, ry1);
  q = g2[b11];
  v = AT2(rx1, ry1);
  b = LERP(sx, u, v);

#undef AT2

  return LERP(sy, a, b);
}
//------------------------------------------------------------------------------------
// Adjust the aim dir before we pass it to the torsoAim pose modifier, this allows us
// to have the weapon deviate from the camera in certain circumstances
// Should only be called once per frame as it time-steps internal vars
//------------------------------------------------------------------------------------
void CLocalPlayerComponent::AdjustTorsoAimDir(float fFrameTime, Vec3 &aimDir)
{
	const f32 HALF_PI = gf_PI * 0.5f;
	float newElevLimit = HALF_PI;

	const f32 MIN_FLATTEN_LEVEL		= -0.3f;
	const f32 MAX_FLATTEN_LEVEL		= -0.1f;
	const f32 TARGET_FLATTEN_ELEV	= -0.2f;
	const f32 LIMIT_CHANGE_RATE		= HALF_PI;

	if (g_pGameCVars->pl_swimAlignArmsToSurface && m_rPlayer.IsSwimming() && (m_rPlayer.m_playerStateSwim_WaterTestProxy.GetRelativeWaterLevel() > MIN_FLATTEN_LEVEL))
	{
		newElevLimit = (m_rPlayer.m_playerStateSwim_WaterTestProxy.GetRelativeWaterLevel() - MIN_FLATTEN_LEVEL) / (MAX_FLATTEN_LEVEL - MIN_FLATTEN_LEVEL);
		newElevLimit = LERP(gf_PI * 0.5f, TARGET_FLATTEN_ELEV, clamp_tpl(newElevLimit, 0.0f, 1.0f));
	}

	float limitDelta = LIMIT_CHANGE_RATE * fFrameTime;
	float limitDiff	 = newElevLimit - m_stapElevLimit;
	float smoothedLimit = (float) fsel(fabs_tpl(limitDiff) - limitDelta, m_stapElevLimit + (fsgnf(limitDiff) * limitDelta), newElevLimit);
	m_stapElevLimit = smoothedLimit;

	if (smoothedLimit < HALF_PI)
	{
		//--- Need to limit, convert to yaw & elev, limit & then convert back
		float yaw, elev;
		float xy = aimDir.GetLengthSquared2D();
		if (xy > 0.001f)
		{
			yaw = atan2_tpl(aimDir.y,aimDir.x);
			elev = asin_tpl(clamp_tpl(aimDir.z, -1.f, +1.f));
		}
		else
		{
			yaw = 0.f;
			elev = (float)fsel(aimDir.z, +1.f, -1.f) * (gf_PI*0.5f);
		}

		elev = min(elev, smoothedLimit);

		float sinYaw, cosYaw;
		float sinElev, cosElev;

		sincos_tpl(yaw, &sinYaw, &cosYaw);
		sincos_tpl(elev, &sinElev, &cosElev);

		aimDir.x = cosYaw * cosElev;
		aimDir.y = sinYaw * cosElev;
		aimDir.z = sinElev;
	}
}
示例#28
0
void CSmokeManager::SetBlurredVision( const float blurAmmount, const float frameTime )
{
    float newBlurAmount = clamp(blurAmmount * kBlurStrength, 0.0f, 1.0f);

    if (m_clientBlurAmount == newBlurAmount)
        return;

    if(newBlurAmount > m_clientBlurAmount)
        {
            m_clientBlurAmount = newBlurAmount;
        }
    else
        {
            m_clientBlurAmount = LERP(m_clientBlurAmount, newBlurAmount, frameTime * kClientReduceBlurDelta);
        }

    CSceneBlurGameEffect* pSceneBlurGameEffect = g_pGame->GetSceneBlurGameEffect();
    CRY_ASSERT(pSceneBlurGameEffect != NULL);
    pSceneBlurGameEffect->SetBlurAmount(m_clientBlurAmount, CSceneBlurGameEffect::eGameEffectUsage_SmokeManager);

    gEnv->p3DEngine->SetPostEffectParam("Global_User_Brightness", LERP(1.0f,kBlurBrightness,m_clientBlurAmount));
    gEnv->p3DEngine->SetPostEffectParam("Global_User_Contrast", LERP(1.0f,kBlurContrast,m_clientBlurAmount));
}
示例#29
0
template <class T>	T   pnoise(T x,T y,T z,int px,int py,int pz,const unsigned char *perm) {
    int ix0, iy0, ix1, iy1, iz0, iz1;
    T fx0, fy0, fz0, fx1, fy1, fz1;
    T s, t, r;
    T nxy0, nxy1, nx0, nx1, n0, n1;

	px	=	max(px,1);
	py	=	max(py,1);
	pz	=	max(pz,1);

    ix0 = FASTFLOOR( x );
    iy0 = FASTFLOOR( y );
    iz0 = FASTFLOOR( z );
    fx0 = x - ix0;
    fy0 = y - iy0;
    fz0 = z - iz0;
    fx1 = fx0 - 1.0f;
    fy1 = fy0 - 1.0f;
    fz1 = fz0 - 1.0f;
    ix1 = (( ix0 + 1 ) % px ) & 0xff;
    iy1 = (( iy0 + 1 ) % py ) & 0xff;
    iz1 = (( iz0 + 1 ) % pz ) & 0xff;
    ix0 = ( ix0 % px ) & 0xff;
    iy0 = ( iy0 % py ) & 0xff;
    iz0 = ( iz0 % pz ) & 0xff;
    
    r = FADE( fz0 );
    t = FADE( fy0 );
    s = FADE( fx0 );

    nxy0 = grad(perm[ix0 + perm[iy0 + perm[iz0]]], fx0, fy0, fz0);
    nxy1 = grad(perm[ix0 + perm[iy0 + perm[iz1]]], fx0, fy0, fz1);
    nx0 = LERP( r, nxy0, nxy1 );

    nxy0 = grad(perm[ix0 + perm[iy1 + perm[iz0]]], fx0, fy1, fz0);
    nxy1 = grad(perm[ix0 + perm[iy1 + perm[iz1]]], fx0, fy1, fz1);
    nx1 = LERP( r, nxy0, nxy1 );

    n0 = LERP( t, nx0, nx1 );

    nxy0 = grad(perm[ix1 + perm[iy0 + perm[iz0]]], fx1, fy0, fz0);
    nxy1 = grad(perm[ix1 + perm[iy0 + perm[iz1]]], fx1, fy0, fz1);
    nx0 = LERP( r, nxy0, nxy1 );

    nxy0 = grad(perm[ix1 + perm[iy1 + perm[iz0]]], fx1, fy1, fz0);
    nxy1 = grad(perm[ix1 + perm[iy1 + perm[iz1]]], fx1, fy1, fz1);
    nx1 = LERP( r, nxy0, nxy1 );

    n1 = LERP( t, nx0, nx1 );
    
    return 0.5f * (1.0f + 0.936f * ( LERP( s, n0, n1 ) ) );
}
示例#30
0
// Noise functions over 1, 2, and 3 dimensions
float Noise::smoothNoise1(float arg)
{
  int bx0, bx1;
  float rx0, rx1, sx, t, u, v, vec;

  vec = arg;
  SETUP(vec, bx0, bx1, rx0, rx1);

  sx = SCURVE(rx0);

  u = rx0 * g1[p[bx0]];
  v = rx1 * g1[p[bx1]];

  return LERP(sx, u, v);
}