示例#1
0
文件: expfuncs.cpp 项目: OpenDAWN/Syd
ssfloat ExpMgr::gnoise(ssfloat x, ssfloat y, ssfloat z)
{
    int ix, iy, iz;
    ssfloat fx0, fx1, fy0, fy1, fz0, fz1;
    ssfloat wx, wy, wz;
    ssfloat vx0, vx1, vy0, vy1, vz0, vz1;
    static int initialized = 0;

    if (!initialized) {
        gradientTabInit(665);
        initialized = 1;
    }

    ix = FLOOR(x);
    fx0 = x - ix;
    fx1 = fx0 - 1;
    wx = SMOOTHSTEP(fx0);

    iy = FLOOR(y);
    fy0 = y - iy;
    fy1 = fy0 - 1;
    wy = SMOOTHSTEP(fy0);

    iz = FLOOR(z);
    fz0 = z - iz;
    fz1 = fz0 - 1;
    wz = SMOOTHSTEP(fz0);

    vx0 = glattice(ix,iy,iz,fx0,fy0,fz0);
    vx1 = glattice(ix+1,iy,iz,fx1,fy0,fz0);
    vy0 = LERP(wx, vx0, vx1);
    vx0 = glattice(ix,iy+1,iz,fx0,fy1,fz0);
    vx1 = glattice(ix+1,iy+1,iz,fx1,fy1,fz0);
    vy1 = LERP(wx, vx0, vx1);
    vz0 = LERP(wy, vy0, vy1);

    vx0 = glattice(ix,iy,iz+1,fx0,fy0,fz1);
    vx1 = glattice(ix+1,iy,iz+1,fx1,fy0,fz1);
    vy0 = LERP(wx, vx0, vx1);
    vx0 = glattice(ix,iy+1,iz+1,fx0,fy1,fz1);
    vx1 = glattice(ix+1,iy+1,iz+1,fx1,fy1,fz1);
    vy1 = LERP(wx, vx0, vx1);
    vz1 = LERP(wy, vy0, vy1);

    return LERP(wz, vz0, vz1);
}
示例#2
0
//static
void TBAnimationManager::Update()
{
	double time_now = TBSystem::GetTimeMS();

	TBLinkListOf<TBAnimationObject>::Iterator iter = animating_objects.IterateForward();
	while (TBAnimationObject *obj = iter.GetAndStep())
	{
		// Adjust the start time if it's the first update time for this object.
		if (obj->adjust_start_time)
		{
			obj->animation_start_time = time_now;
			obj->adjust_start_time = false;
		}

		// Calculate current progress
		// If animation_duration is 0, it should just complete immediately.
		float progress = 1.0f;
		if (obj->animation_duration != 0)
		{
			progress = (float)(time_now - obj->animation_start_time) / (float)obj->animation_duration;
			progress = MIN(progress, 1.0f);
		}

		// Apply animation curve
		float tmp;
		switch (obj->animation_curve)
		{
		case ANIMATION_CURVE_SLOW_DOWN:
			tmp = 1 - progress;
			progress = 1 - tmp * tmp * tmp;
			break;
		case ANIMATION_CURVE_SPEED_UP:
			progress = progress * progress * progress;
			break;
		case ANIMATION_CURVE_BEZIER:
			progress = SMOOTHSTEP(progress);
			break;
		case ANIMATION_CURVE_SMOOTH:
			progress = SmoothCurve(progress, 0.6f);
			break;
		default: // linear (progress is already linear)
			break;
		}

		// Update animation
		obj->InvokeOnAnimationUpdate(progress);

		// Remove completed animations
		if (progress == 1.0f)
		{
			animating_objects.Remove(obj);
			obj->InvokeOnAnimationStop(false);
			delete obj;
		}
	}
}
示例#3
0
CInMapDraw::CInMapDraw(void)
{
	keyPressed = false;
	wantLabel = false;
	drawAll = false;
	allowSpecMapDrawing = true;
	allowLuaMapDrawing = true;
	lastLineTime = 0;
	lastLeftClickTime = 0;
	lastPos = float3(1, 1, 1);

	drawQuadsX = gs->mapx / DRAW_QUAD_SIZE;
	drawQuadsY = gs->mapy / DRAW_QUAD_SIZE;
	numQuads = drawQuadsX * drawQuadsY;
	drawQuads.resize(numQuads);

	unsigned char tex[64][128][4];
	for (int y = 0; y < 64; y++) {
		for (int x = 0; x < 128; x++) {
			tex[y][x][0] = 0;
			tex[y][x][1] = 0;
			tex[y][x][2] = 0;
			tex[y][x][3] = 0;
		}
	}

	#define SMOOTHSTEP(x,y,a) (unsigned char)(x * (1.0f - a) + y * a)

	for (int y = 0; y < 64; y++) {
		// circular thingy
		for (int x = 0; x < 64; x++) {
			float dist = sqrt((float)(x - 32) * (x - 32) + (y - 32) * (y - 32));
			if (dist > 31.0f) {
				// do nothing - leave transparent
			} else if (dist > 30.0f) {
				// interpolate (outline -> nothing)
				float a = (dist - 30.0f);
				tex[y][x][3] = SMOOTHSTEP(255,0,a);
			} else if (dist > 24.0f) {
				// black outline
				tex[y][x][3] = 255;
			} else if (dist > 23.0f) {
				// interpolate (inner -> outline)
				float a = (dist - 23.0f);
				tex[y][x][0] = SMOOTHSTEP(255,0,a);
				tex[y][x][1] = SMOOTHSTEP(255,0,a);
				tex[y][x][2] = SMOOTHSTEP(255,0,a);
				tex[y][x][3] = SMOOTHSTEP(200,255,a);
			} else {
				tex[y][x][0] = 255;
				tex[y][x][1] = 255;
				tex[y][x][2] = 255;
				tex[y][x][3] = 200;
			}
		}
	}
	for (int y = 0; y < 64; y++) {
		// linear falloff
		for (int x = 64; x < 128; x++) {
			float dist = abs(y - 32);
			if (dist > 31.0f) {
				// do nothing - leave transparent
			} else if (dist > 30.0f) {
				// interpolate (outline -> nothing)
				float a = (dist - 30.0f);
				tex[y][x][3] = SMOOTHSTEP(255,0,a);
			} else if (dist > 24.0f) {
				// black outline
				tex[y][x][3] = 255;
			} else if (dist > 23.0f) {
				// interpolate (inner -> outline)
				float a = (dist - 23.0f);
				tex[y][x][0] = SMOOTHSTEP(255,0,a);
				tex[y][x][1] = SMOOTHSTEP(255,0,a);
				tex[y][x][2] = SMOOTHSTEP(255,0,a);
				tex[y][x][3] = SMOOTHSTEP(200,255,a);
			} else {
				tex[y][x][0] = 255;
				tex[y][x][1] = 255;
				tex[y][x][2] = 255;
				tex[y][x][3] = 200;
			}
		}
	}

	glGenTextures(1, &texture);
	glBindTexture(GL_TEXTURE_2D, texture);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
	glBuildMipmaps(GL_TEXTURE_2D, GL_RGBA8, 128, 64, GL_RGBA, GL_UNSIGNED_BYTE, tex[0]);

	blippSound = sound->GetSoundId("MapPoint", false);
}
示例#4
0
文件: noise.c 项目: cciechad/brlcad
/**
 * Vector-valued "Noise"
 */
void
bn_noise_vec(fastf_t *point, fastf_t *result)
{
    register int	jx, jy, jz;
    int ix, iy, iz;		/* lower integer lattice point */
    double x, y, z;		/* corrected point */
    double		px, py, pz, s;
    double		sx, sy, sz, tx, ty, tz;
    short		m;
    point_t p, f;
    int ip[3];


    if ( ! ht.hashTableValid ) bn_noise_init();


    /* sets:
     * x, y, z to range [0..maxval],
     * ix, iy, iz to integer portion,
     * fx, fy, fz to fractional portion
     */
    filter_args( point, p, f, ip);
    ix = ip[X];
    iy = ip[Y];
    iz = ip[Z];

    x = p[X];
    y = p[Y];
    z = p[Z];

    jx = ix+1;   jy = iy + 1;   jz = iz + 1;

    sx = SMOOTHSTEP(x - ix);
    sy = SMOOTHSTEP(y - iy);
    sz = SMOOTHSTEP(z - iz);

    /* the complement values of sx, sy, sz */
    tx = 1.0 - sx;
    ty = 1.0 - sy;
    tz = 1.0 - sz;

    /*
     *  interpolate!
     */
    m = Hash3d( ix, iy, iz ) & 0xFF;
    px = x-ix;
    py = y-iy;
    pz = z-iz;
    s = tx*ty*tz;
    result[0] = INCRSUM(m, s, px, py, pz);
    result[1] = INCRSUM(m+4, s, px, py, pz);
    result[2] = INCRSUM(m+8, s, px, py, pz);

    m = Hash3d( jx, iy, iz ) & 0xFF;
    px = x-jx;
    s = sx*ty*tz;
    result[0] += INCRSUM(m, s, px, py, pz);
    result[1] += INCRSUM(m+4, s, px, py, pz);
    result[2] += INCRSUM(m+8, s, px, py, pz);

    m = Hash3d( jx, jy, iz ) & 0xFF;
    py = y-jy;
    s = sx*sy*tz;
    result[0] += INCRSUM(m, s, px, py, pz);
    result[1] += INCRSUM(m+4, s, px, py, pz);
    result[2] += INCRSUM(m+8, s, px, py, pz);

    m = Hash3d( ix, jy, iz ) & 0xFF;
    px = x-ix;
    s = tx*sy*tz;
    result[0] += INCRSUM(m, s, px, py, pz);
    result[1] += INCRSUM(m+4, s, px, py, pz);
    result[2] += INCRSUM(m+8, s, px, py, pz);

    m = Hash3d( ix, jy, jz ) & 0xFF;
    pz = z-jz;
    s = tx*sy*sz;
    result[0] += INCRSUM(m, s, px, py, pz);
    result[1] += INCRSUM(m+4, s, px, py, pz);
    result[2] += INCRSUM(m+8, s, px, py, pz);

    m = Hash3d( jx, jy, jz ) & 0xFF;
    px = x-jx;
    s = sx*sy*sz;
    result[0] += INCRSUM(m, s, px, py, pz);
    result[1] += INCRSUM(m+4, s, px, py, pz);
    result[2] += INCRSUM(m+8, s, px, py, pz);

    m = Hash3d( jx, iy, jz ) & 0xFF;
    py = y-iy;
    s = sx*ty*sz;
    result[0] += INCRSUM(m, s, px, py, pz);
    result[1] += INCRSUM(m+4, s, px, py, pz);
    result[2] += INCRSUM(m+8, s, px, py, pz);

    m = Hash3d( ix, iy, jz ) & 0xFF;
    px = x-ix;
    s = tx*ty*sz;
    result[0] += INCRSUM(m, s, px, py, pz);
    result[1] += INCRSUM(m+4, s, px, py, pz);
    result[2] += INCRSUM(m+8, s, px, py, pz);
}
示例#5
0
文件: noise.c 项目: cciechad/brlcad
/**
 *@brief
 * Robert Skinner's Perlin-style "Noise" function
 *
 * Results are in the range [-0.5 .. 0.5].  Unlike many implementations,
 * this function provides random noise at the integer lattice values.
 * However this produces much poorer quality and should be avoided if
 * possible.
 *
 * The power distribution of the result has no particular shape, though it
 * isn't as flat as the literature would have one believe.
 */
double
bn_noise_perlin(fastf_t *point)
{
    register int	jx, jy, jz;
    int ix, iy, iz;	/* lower integer lattice point */
    double x, y, z;	/* corrected point */
    double fx, fy, fz;	/* distance above integer lattice point */
    double	sx, sy, sz, tx, ty, tz;
    double	sum;
    short	m;
    point_t p, f;
    int ip[3];

    if (!ht.hashTableValid) bn_noise_init();
    else {
/*		CK_HT(); */
    }

    /* IS: const fastf_t *, point_t, point_t, int[3] */
    /* NE: fastf_t *, fastf_t *, fastf_t *, int *    */
    filter_args( point, p, f, ip);
    ix = ip[X];
    iy = ip[Y];
    iz = ip[Z];

    fx = f[X];
    fy = f[Y];
    fz = f[Z];

    x = p[X];
    y = p[Y];
    z = p[Z];

    jx = ix + 1; /* (jx, jy, jz) = integer lattice point above (ix, iy, iz) */
    jy = iy + 1;
    jz = iz + 1;

    sx = SMOOTHSTEP(fx);
    sy = SMOOTHSTEP(fy);
    sz = SMOOTHSTEP(fz);

    /* the complement values of sx, sy, sz */
    tx = 1.0 - sx;
    ty = 1.0 - sy;
    tz = 1.0 - sz;

    /*
     *  interpolate!
     */
    /* get a repeatable random # 0..4096 & 0xFF*/
    m = Hash3d( ix, iy, iz ) & 0xFF;
    sum = INCRSUM(m, (tx*ty*tz), (x-ix), (y-iy), (z-iz));

    m = Hash3d( jx, iy, iz ) & 0xFF;
    sum += INCRSUM(m, (sx*ty*tz), (x-jx), (y-iy), (z-iz));

    m = Hash3d( ix, jy, iz ) & 0xFF;
    sum += INCRSUM(m, (tx*sy*tz), (x-ix), (y-jy), (z-iz));

    m = Hash3d( jx, jy, iz ) & 0xFF;
    sum += INCRSUM(m, (sx*sy*tz), (x-jx), (y-jy), (z-iz));

    m = Hash3d( ix, iy, jz ) & 0xFF;
    sum += INCRSUM(m, (tx*ty*sz), (x-ix), (y-iy), (z-jz));

    m = Hash3d( jx, iy, jz ) & 0xFF;
    sum += INCRSUM(m, (sx*ty*sz), (x-jx), (y-iy), (z-jz));

    m = Hash3d( ix, jy, jz ) & 0xFF;
    sum += INCRSUM(m, (tx*sy*sz), (x-ix), (y-jy), (z-jz));

    m = Hash3d( jx, jy, jz ) & 0xFF;
    sum += INCRSUM(m, (sx*sy*sz), (x-jx), (y-jy), (z-jz));

    return sum;

}