gpmark

view 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 source
1 #include <math.h>
2 #include <stdio.h>
3 #include "main.h"
5 unsigned short draculin[128 * 128];
7 void InitRotozoomer()
8 {
9 unsigned short dracol[256];
11 FILE *dracdata;
12 dracdata=fopen("draculf.bin","rb");
14 int x0=fgetc(dracdata);
15 int y0=fgetc(dracdata);
17 int r,g,b;
18 for (int i=0;i<256;i++)
19 dracol[i]=(((fgetc(dracdata)>>1)<<11) | (fgetc(dracdata)<<5) | (fgetc(dracdata))>>1);
21 for (int y=0;y<y0;y++)
22 for (int x=0;x<x0;x++)
23 draculin[(y<<7) + x]=dracol[fgetc(dracdata)];
25 fclose(dracdata);
26 }
28 void RunRotozoomer(float rot, float zoom, unsigned short *vram)
29 {
30 int fp = 16;
32 int mx = 0, my = 0, mmx = 50<<fp, mmy = 20<<fp;
33 int dx = (int)((cos(rot/d2r)*zoom) * pow(2,fp));
34 int dy = (int)((sin(rot/d2r)*zoom) * pow(2,fp));
36 int x,y;
37 unsigned short c;
39 for (y=0; y<ScreenHeight; y++)
40 {
41 mmx = mmx - dy;
42 mmy = mmy + dx;
43 mx = mmx;
44 my = mmy;
45 for (x=0; x<ScreenWidth; x++)
46 {
47 mx = mx + dx;
48 my = my + dy;
49 c = draculin[((mx>>fp)&127) + (((my>>fp)&127) << 7)];
50 *vram++=c;
51 }
52 }
53 }
55 void RunRotozoomerNormal(int ntime, unsigned short *vram)
56 {
57 float rot = sin(ntime/478.0f) * 280.0f;
58 float zoom = sin(ntime/227.0f)*0.75f + 0.76f;
60 RunRotozoomer(rot, zoom, vram);
61 }
63 void RunRotozoomerNear(int ntime, unsigned short *vram)
64 {
65 float rot = sin(ntime/478.0f) * 280.0f;
66 float zoom = 0.05f;
68 RunRotozoomer(rot, zoom, vram);
69 }
71 void RunRotozoomerFar(int ntime, unsigned short *vram)
72 {
73 float rot = sin(ntime/478.0f) * 280.0f;
74 float zoom = 8.0f;
76 RunRotozoomer(rot, zoom, vram);
77 }