gpmark

diff src/rotozoomer.cpp @ 0:5019d031b485

initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Wed, 05 Jun 2013 22:33:37 +0300
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/rotozoomer.cpp	Wed Jun 05 22:33:37 2013 +0300
     1.3 @@ -0,0 +1,77 @@
     1.4 +#include <math.h>
     1.5 +#include <stdio.h>
     1.6 +#include "main.h"
     1.7 +
     1.8 +unsigned short draculin[128 * 128];
     1.9 +
    1.10 +void InitRotozoomer()
    1.11 +{
    1.12 +	unsigned short dracol[256];
    1.13 +
    1.14 +	FILE *dracdata;
    1.15 +	dracdata=fopen("draculf.bin","rb");
    1.16 +
    1.17 +	int x0=fgetc(dracdata);
    1.18 +	int y0=fgetc(dracdata);
    1.19 +
    1.20 +	int r,g,b;
    1.21 +	for (int i=0;i<256;i++)
    1.22 +		dracol[i]=(((fgetc(dracdata)>>1)<<11) | (fgetc(dracdata)<<5) | (fgetc(dracdata))>>1);
    1.23 +
    1.24 +	for (int y=0;y<y0;y++)
    1.25 +		for (int x=0;x<x0;x++)
    1.26 +			draculin[(y<<7) + x]=dracol[fgetc(dracdata)];
    1.27 +
    1.28 +	fclose(dracdata);
    1.29 +}
    1.30 +
    1.31 +void RunRotozoomer(float rot, float zoom, unsigned short *vram)
    1.32 +{
    1.33 +	int fp = 16;
    1.34 +
    1.35 +	int mx = 0, my = 0, mmx = 50<<fp, mmy = 20<<fp;
    1.36 +	int dx = (int)((cos(rot/d2r)*zoom) * pow(2,fp));
    1.37 +	int dy = (int)((sin(rot/d2r)*zoom) * pow(2,fp));
    1.38 +
    1.39 +    int x,y;
    1.40 +	unsigned short c;
    1.41 +
    1.42 +    for (y=0; y<ScreenHeight; y++)
    1.43 +    {
    1.44 +        mmx = mmx - dy;
    1.45 +        mmy = mmy + dx;
    1.46 +        mx = mmx;
    1.47 +        my = mmy;
    1.48 +        for (x=0; x<ScreenWidth; x++)
    1.49 +        {
    1.50 +            mx = mx + dx;
    1.51 +            my = my + dy;
    1.52 +            c = draculin[((mx>>fp)&127) + (((my>>fp)&127) << 7)];
    1.53 +            *vram++=c;
    1.54 +        }
    1.55 +    }
    1.56 +}
    1.57 +
    1.58 +void RunRotozoomerNormal(int ntime, unsigned short *vram)
    1.59 +{
    1.60 +    float rot = sin(ntime/478.0f) * 280.0f;
    1.61 +    float zoom = sin(ntime/227.0f)*0.75f + 0.76f;
    1.62 +
    1.63 +    RunRotozoomer(rot, zoom, vram);
    1.64 +}
    1.65 +
    1.66 +void RunRotozoomerNear(int ntime, unsigned short *vram)
    1.67 +{
    1.68 +    float rot = sin(ntime/478.0f) * 280.0f;
    1.69 +    float zoom = 0.05f;
    1.70 +
    1.71 +    RunRotozoomer(rot, zoom, vram);
    1.72 +}
    1.73 +
    1.74 +void RunRotozoomerFar(int ntime, unsigned short *vram)
    1.75 +{
    1.76 +    float rot = sin(ntime/478.0f) * 280.0f;
    1.77 +    float zoom = 8.0f;
    1.78 +
    1.79 +    RunRotozoomer(rot, zoom, vram);
    1.80 +}