vblperf_end();
wait_vblank();
present(backbuf);
-
- tunrot = nframes;
- bgmat[0] = (COS(tunrot) * 140) >> 8;
- bgmat[1] = (-SIN(tunrot) * 140) >> 8;
- bgmat[2] = (SIN(tunrot) * 140) >> 8;
- bgmat[3] = (COS(tunrot) * 140) >> 8;
- bgx = (120 << 8) - bgmat[0] * 120 + bgmat[1] * -80;
- bgy = (80 << 8) - bgmat[2] * 120 + bgmat[3] * -80;
-
vblperf_begin();
}
}
__attribute__((noinline, target("arm"), section(".iwram")))
static void draw_tunnel(void)
{
- int i, j, tx, ty, angle, depth, zoffs, uoffs;
+ int i, j, tx, ty, angle, depth, zoffs, uoffs, flip;
+ int tunsweep;
uint16_t pptop, ppbot;
uint16_t *top, *bot;
uint32_t tun, *tunptr;
+ tunsweep = (SIN(nframes) >> 2) + 64;
+ if(tunsweep > 127) tunsweep = 127;
+
+ flip = tunsweep >= 64;
+
+ tunsweep = (tunsweep & 0x3f);
+ if(tunsweep >= 32) tunsweep = 63 - tunsweep;
+
zoffs = nframes;
uoffs = tunrot >> 1;
- top = vram[backbuf] + 20;
- bot = vram[backbuf] + 159 * 240 / 2 + 20;
- tunptr = tunmap;
+ top = vram[backbuf];
+ bot = vram[backbuf] + 159 * 240 / 2;
+ tunptr = tunmap + tunsweep * 9600;
+ if(flip) tunptr += 240/2;
for(i=0; i<80; i++) {
- for(j=0; j<160/2; j++) {
-#ifdef VBLBAR
- if(j == 160/4) {
- tunptr++;
- top++;
- bot++;
- continue;
+ for(j=0; j<240/2; j++) {
+ if(flip) {
+ tun = *--tunptr;
+ tun = (tun >> 16) | (tun << 16);
+ } else {
+ tun = *tunptr++;
}
-#endif
- tun = *tunptr++;
angle = tun & 0xff;
depth = (tun >> 8) & 0xff;
*top++ = pptop;
*bot++ = ppbot;
}
- top += 40;
- bot -= 240 - 40;
+ bot -= 240;
+
+ if(flip) tunptr += 240;
}
}
int16_t mat[4];
static short gate_speed;
- REG_BG2PA = bgmat[0];
- REG_BG2PB = bgmat[1];
- REG_BG2PC = bgmat[2];
- REG_BG2PD = bgmat[3];
- REG_BG2X = bgx;
- REG_BG2Y = bgy;
-
bnstate = ~REG_KEYINPUT;
if(bnstate & BN_DPAD) {
if(gate_speed < 5) {
int main(int argc, char **argv)
{
- int i, j, imgrad, xsz = 240, ysz = 160, texsz = 128;
+ int i, j, frm, imgrad, out_nlines, xsz = 240, ysz = 160, texsz = 128;
+ int half_y = 0;
+ int center = 0;
struct vec2 *tunbuf, *tun;
- float aspect, prev_r;
+ float prev_r;
struct vec2 *buf, *ptr;
+ char *endp;
+ int num_frames = 1;
for(i=1; i<argc; i++) {
if(argv[i][0] == '-') {
}
break;
+ case 'y':
+ half_y = 1;
+ break;
+
+ case 'c':
+ if(!argv[++i]) {
+ fprintf(stderr, "-c must be followed by a center pixel\n");
+ return 1;
+ }
+ center = strtol(argv[i], &endp, 10);
+ if(endp == argv[i]) {
+ fprintf(stderr, "-c invalid center position: %s\n", argv[i]);
+ return 1;
+ }
+ break;
+
+ case 'n':
+ if(!argv[++i]) {
+ fprintf(stderr, "-n must be followed by the number of frames\n");
+ return 1;
+ }
+ if(!(num_frames = atoi(argv[i]))) {
+ fprintf(stderr, "-n invalid number of frames: %s\n", argv[i]);
+ return 1;
+ }
+ break;
+
default:
goto invalopt;
}
}
}
+ out_nlines = half_y ? ysz / 2 : ysz;
+
if(!(buf = malloc(xsz * ysz * sizeof *buf))) {
perror("failed to allocate buffer");
return 1;
}
imgrad = sqrt(xsz * xsz + ysz * ysz);
-#define UDIV 2048
-#define VDIV 32768
- prev_r = 0.0f;
- for(i=0; i<VDIV; i++) {
- float v = (float)(VDIV - i) / (float)VDIV;
- float r = 1.5 / v + 16;
- float z = v * 200.0f;
-
- /* don't bother drawing rings < 1 pixel apart */
- if(fabs(r - prev_r) < 0.05) continue;
-
- for(j=0; j<UDIV; j++) {
- float u = (float)j / (float)(UDIV - 1);
- float theta = 2.0f * u * M_PI;
-
- int x = (int)(cos(theta) * r - z) + xsz / 2;
- int y = (int)(sin(theta) * r) + ysz / 2;
-
- if(x >= 0 && x < xsz && y >= 0 && y < ysz) {
- ptr = buf + y * xsz + x;
- ptr->x = u;
- ptr->y = v * 8;
- }
- }
- prev_r = r;
- }
-
FILE *fp = fopen("tun_preview.ppm", "wb");
if(fp) {
- fprintf(fp, "P6\n%d %d\n255\n", xsz, ysz);
+ fprintf(fp, "P6\n%d %d\n255\n", xsz, out_nlines * num_frames);
}
- aspect = (float)xsz / (float)ysz;
-
- ptr = buf;
- for(i=0; i<ysz; i++) {
- for(j=0; j<xsz; j++) {
- float u = ptr->x;
- float v = ptr->y;
- int r = (int)(u * 8.0 * 255.0f) & 0xff;
- int g = (int)(v * 8.0 * 255.0f) & 0xff;
- int b = (~(int)(v * 0.5 * 255.0f) & 0xff) + 105;
- if(b > 255) b = 255;
- if(b < 0) b = 0;
-
- /*if(v > 2.0) r = g = b = 0;*/
- ptr++;
+ for(frm=0; frm<num_frames; frm++) {
+ int coffs = num_frames > 1 ? frm * center / (num_frames - 1) : center;
- uint16_t out = ((uint16_t)(u * 255.0f) & 0xff) |
- (((uint16_t)(v * 255.0f) & 0xff) << 8);
- fwrite(&out, sizeof out, 1, stdout);
+#define UDIV 2048
+#define VDIV 32768
+ prev_r = 0.0f;
+#pragma omp parallel for private(i, j, prev_r, ptr) schedule(dynamic)
+ for(i=0; i<VDIV; i++) {
+ float v = (float)(VDIV - i) / (float)VDIV;
+ float r = 4.0 / v + 16;
+ float z = v * coffs;
+
+ /* don't bother drawing rings < 1 pixel apart */
+ if(fabs(r - prev_r) < 0.05) continue;
+
+ for(j=0; j<UDIV; j++) {
+ float u = (float)j / (float)(UDIV - 1);
+ float theta = 2.0f * u * M_PI;
+
+ int x = (int)(cos(theta) * r - z) + xsz / 2;
+ int y = (int)(sin(theta) * r) + ysz / 2;
+
+ if(x >= 0 && x < xsz && y >= 0 && y < ysz) {
+ ptr = buf + y * xsz + x;
+ ptr->x = u;
+ ptr->y = v * 8;
+ }
+ }
+ prev_r = r;
+ }
- if(fp) {
- fputc(r, fp);
- fputc(g, fp);
- fputc(b, fp);
+ ptr = buf;
+ for(i=0; i<out_nlines; i++) {
+ for(j=0; j<xsz; j++) {
+ float u = ptr->x;
+ float v = ptr->y;
+ int r = (int)(u * 8.0 * 255.0f) & 0xff;
+ int g = (int)(v * 8.0 * 255.0f) & 0xff;
+ int b = (~(int)(v * 0.5 * 255.0f) & 0xff) + 105;
+ if(b > 255) b = 255;
+ if(b < 0) b = 0;
+
+ /*if(v > 2.0) r = g = b = 0;*/
+
+ ptr++;
+
+ uint16_t out = ((uint16_t)(u * 255.0f) & 0xff) |
+ (((uint16_t)(v * 255.0f) & 0xff) << 8);
+ fwrite(&out, sizeof out, 1, stdout);
+
+ if(fp) {
+ fputc(r, fp);
+ fputc(g, fp);
+ fputc(b, fp);
+ }
}
}
+
}
fflush(stdout);