-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathROTOZOOM.C
More file actions
81 lines (71 loc) · 1.87 KB
/
ROTOZOOM.C
File metadata and controls
81 lines (71 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/* Rotozoom effect - Copyright (c) 2025 Henrik Löfgren
* This program is distributable under the terms of the 2-clause BSD license.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
#include <time.h>
#include <math.h>
#include "gfxlib.h"
void setPalette(void);
void genPalette(void);
void genSineTable(void);
int sine_table[5760];
unsigned char r_pal[256];
unsigned char g_pal[256];
unsigned char b_pal[256];
unsigned char buffer[64000];
unsigned char texture[64000];
int main(void)
{
int x,y,cnt;
int ypos;
float runtime;
int u,v;
clock_t start_time, end_time;
int c,s;
genSineTable();
setVideoMode(0x13);
// Read graphics and palette data from PCX file
readPCX("rotozoom.pcx", &texture, &r_pal, &g_pal, &b_pal);
setPalette();
start_time = clock();
for(cnt=0; cnt<60000; cnt++) {
s = sine_table[(cnt<<2) % 5760];
c = -1*sine_table[((cnt<<2) + 1440) % 5760];
for(y=0; y<200; y++) {
ypos = (y<<8) + (y<<6);
for(x=0; x<320; x++) {
u = abs((((((x*c-y*s))*((s<<1)+2))>>20) % 320));
v = abs((((((x*s+y*c))*((s<<1)+2))>>20) % 200));
if((u>319) || (u<0) || (v>199) || (v<0))
printf("u: %d\tv: %d\n", u, v);
buffer[ypos + x] = texture[(v<<8)+(v<<6)+u];
}
}
updateScreen(&buffer);
if(kbhit()) break;
}
end_time=clock();
getch();
runtime = (float)(end_time-start_time)/((float)CLOCKS_PER_SEC);
setVideoMode(0x03);
printf("Frames: %d\n", cnt);
printf("Runtime: %f\n", runtime);
printf("FPS: %f\n", (float)cnt/runtime);
return 0;
}
void setPalette(void) {
int i;
for(i=0; i<256; i++) {
setPalReg(i, r_pal[i], g_pal[i], b_pal[i]);
}
}
void genSineTable(void)
{
// Generate a sine table, 12 bit fixed point, 1/16 degrees resolution
int i;
for(i=0; i<5760; i++)
sine_table[i] = (int)(1024.0*sin((float)i*3.1415927/(180.0*16)));
}