X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=dosdemo;a=blobdiff_plain;f=src%2Fbump.c;h=b82594ba536a0e46b6a20395b2b7662bd182c0d4;hp=104b1270dc7125107ea4fe7790fd247ee47bb75c;hb=3398fc6c4188104048f99b650a6cb90beda9b6ed;hpb=bd3de1442570d4159c9b58e456b8d69fed9eadc8 diff --git a/src/bump.c b/src/bump.c index 104b127..b82594b 100644 --- a/src/bump.c +++ b/src/bump.c @@ -7,7 +7,6 @@ #include "demo.h" #include "screen.h" -#include "tinyfps.h" static int init(void); static void destroy(void); @@ -31,6 +30,11 @@ struct point { #define BIG_LIGHT_WIDTH 256 #define BIG_LIGHT_HEIGHT BIG_LIGHT_WIDTH +#define NUM_PARTICLES 64 +#define PARTICLE_LIGHT_WIDTH 32 +#define PARTICLE_LIGHT_HEIGHT 32 + + static unsigned long startingTime; static unsigned char *heightmap; @@ -40,6 +44,9 @@ static int *bumpOffset; static unsigned short *bigLight[NUM_BIG_LIGHTS]; static struct point bigLightPoint[NUM_BIG_LIGHTS]; +static unsigned short *particleLight; +static struct point particlePoint[NUM_PARTICLES]; + struct screen *bump_screen(void) { return &scr; @@ -51,8 +58,10 @@ static int init(void) const int numBlurs = 3; const int lightRadius = BIG_LIGHT_WIDTH / 2; + const int particleRadius = PARTICLE_LIGHT_WIDTH / 2; const int bigLightSize = BIG_LIGHT_WIDTH * BIG_LIGHT_HEIGHT; + const int particleLightSize = PARTICLE_LIGHT_WIDTH * PARTICLE_LIGHT_HEIGHT; const int fb_size = fb_width * fb_height; // Just some parameters to temporary test the colors of 3 lights @@ -60,7 +69,6 @@ static int init(void) const float rgbMul[9] = { 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f}; - initFpsFonts(); heightmap = malloc(sizeof(*heightmap) * fb_size); lightmap = malloc(sizeof(*lightmap) * fb_size); @@ -69,8 +77,11 @@ static int init(void) for (i = 0; i < NUM_BIG_LIGHTS; i++) bigLight[i] = malloc(sizeof(*bigLight[i]) * bigLightSize); + particleLight = malloc(sizeof(*particleLight) * particleLightSize); + memset(lightmap, 0, sizeof(*lightmap) * fb_size); memset(bumpOffset, 0, sizeof(*bumpOffset) * fb_size); + memset(particlePoint, 0, sizeof(*particlePoint) * NUM_PARTICLES); // Create random junk for (i = 0; i < fb_size; i++) @@ -87,7 +98,7 @@ static int init(void) { for (x = 0; x < fb_width; x++) { - const float offsetPower = 2.0f; + const float offsetPower = 0.75f; int dx, dy, xp, yp; dx = i < fb_size - 1 ? (int)((heightmap[i] - heightmap[i + 1]) * offsetPower) : 0; @@ -130,6 +141,22 @@ static int init(void) } } + i = 0; + for (y = 0; y < PARTICLE_LIGHT_HEIGHT; y++) + { + int yc = y - (PARTICLE_LIGHT_HEIGHT / 2); + for (x = 0; x < PARTICLE_LIGHT_WIDTH; x++) + { + int xc = x - (PARTICLE_LIGHT_WIDTH / 2); + + float invDist = ((float)particleRadius - (float)sqrt(xc * xc + yc * yc)) / (float)particleRadius; + if (invDist < 0.0f) invDist = 0.0f; + + c = (int)(pow(invDist, 0.75f) * 63); + particleLight[i++] = ((c >> 1) << 11) | (c << 5) | (c >> 1); + } + } + return 0; } @@ -230,22 +257,31 @@ static void renderLights() renderLight(&bigLightPoint[i], BIG_LIGHT_WIDTH, BIG_LIGHT_HEIGHT, bigLight[i]); } +static void renderParticles() +{ + int i; + for (i = 0; i < NUM_PARTICLES; i++) + renderLight(&particlePoint[i], PARTICLE_LIGHT_WIDTH, PARTICLE_LIGHT_HEIGHT, particleLight); +} + static void animateLights() { struct point center; float dt = (float)(time_msec - startingTime) / 1000.0f; + float tt = 1.0f - sin(dt); + float disperse = tt * 64.0f; center.x = (fb_width >> 1) - (BIG_LIGHT_WIDTH / 2); center.y = (fb_height >> 1) - (BIG_LIGHT_HEIGHT / 2); - bigLightPoint[0].x = center.x + sin(1.2f * dt) * 144.0f; - bigLightPoint[0].y = center.y + sin(0.8f * dt) * 148.0f; + bigLightPoint[0].x = center.x + sin(1.2f * dt) * (144.0f + disperse); + bigLightPoint[0].y = center.y + sin(0.8f * dt) * (148.0f + disperse); - bigLightPoint[1].x = center.x + sin(1.5f * dt) * 156.0f; - bigLightPoint[1].y = center.y + sin(1.1f * dt) * 92.0f; + bigLightPoint[1].x = center.x + sin(1.5f * dt) * (156.0f + disperse); + bigLightPoint[1].y = center.y + sin(1.1f * dt) * (92.0f + disperse); - bigLightPoint[2].x = center.x + sin(2.0f * dt) * 112.0f; - bigLightPoint[2].y = center.y + sin(1.3f * dt) * 136.0f; + bigLightPoint[2].x = center.x + sin(2.0f * dt) * (112.0f + disperse); + bigLightPoint[2].y = center.y + sin(1.3f * dt) * (136.0f + disperse); } static void renderBump(unsigned short *vram) @@ -258,14 +294,35 @@ static void renderBump(unsigned short *vram) } } +static void animateParticles() +{ + int i; + struct point center; + float dt = (float)(time_msec - startingTime) / 2000.0f; + float tt = sin(dt); + + center.x = (fb_width >> 1) - (PARTICLE_LIGHT_WIDTH / 2); + center.y = (fb_height >> 1) - (PARTICLE_LIGHT_HEIGHT / 2); + + for (i = 0; i < NUM_PARTICLES; i++) + { + particlePoint[i].x = center.x + (sin(1.2f * (i*i*i + dt)) * 74.0f + sin(0.6f * (i + dt)) * 144.0f) * tt; + particlePoint[i].y = center.y + (sin(1.8f * (i + dt)) * 68.0f + sin(0.5f * (i*i + dt)) * 132.0f) * tt; + } +} + static void draw(void) { - eraseLights(); + memset(lightmap, 0, fb_width * fb_height * sizeof(*lightmap)); + + //eraseLights(); animateLights(); renderLights(); - renderBump((unsigned short*)vmem_back); - drawFps((unsigned short*)vmem_back); + animateParticles(); + renderParticles(); + + renderBump((unsigned short*)fb_pixels); swap_buffers(0); }