Quantcast
Channel: Cemetech
Viewing all articles
Browse latest Browse all 75370

Casio Prizm/FX Development & Programming :: RE: Spenceboy98's OFFICIAL Prizm C Help Topic

$
0
0
Author: Spenceboy98
Posted: 14 Oct 2012 03:11:25 pm (GMT -5)

Okay....


Code:
#include <os.h>
#include <common.h>
#include <fdlibm.h>
#include "utils.h"

#define TEXTURE_WIDTH 16
#define TEXTURE_HEIGHT 16
#define DEPTH_MAX 153600
#define OBSTACLE_WIDTH 128
#define OBSTACLE_HEIGHT 128

char getObstacleColor(int, int, int*);

int main(void)
{
 char *screen;
 double (*angle_lut)[240];
 double (*depth_lut)[240];
 double relativeX, relativeY;
 int textureX, textureY;
 int tunnel_rotate = 0, tunnel_zoom = 0;
 
 int w = 320, h = 240, x, y;
 char color, colorT, colorO;
 
 char texture[256] = {
  0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  0xFF,0xFF,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0xFF,
  0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  0xFF,0xFF,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0xFF,
  0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF
 };
 
 angle_lut = malloc(w * sizeof(*angle_lut));
 if(!angle_lut) exit(0);
 
 depth_lut = malloc(w * sizeof(*depth_lut));
 if(!depth_lut)
 {
  free(angle_lut);
  exit(0);
 }
 
 screen = malloc(SCREEN_BYTES_SIZE * sizeof(char));     // just a buffer
 if(!screen)
 {
  free(angle_lut);
  free(depth_lut);
  exit(0);
 }
 for(y = 0; y < h; y+=2)
 {
  relativeY = h / 4 - y;
  for(x = 0; x < w; x+=2)
  {
   relativeX = x - w / 2;
   
   depth_lut[x][y] = w*h*2 / max(relativeX * relativeX + relativeY * relativeY, 1);
   
   angle_lut[x][y] = atan2(relativeX, relativeY) * (TEXTURE_WIDTH / M_PI) * 4;
  }
 }
 lcd_ingray(); // just ignore it
 
 while(!isKeyPressed(KEY_NSPIRE_ESC))
 {
  clearBuf(screen);
  for(y = 0; y < h; y+=2)
  {
   for(x = 0; x < w; x+=2)
   {
    // X is the angle, Y is the depth
    textureX = angle_lut[x][y] + tunnel_rotate;
    textureY = depth_lut[x][y] + tunnel_zoom;
   
    color = texture[(textureY & (TEXTURE_HEIGHT - 1)) * TEXTURE_WIDTH + (textureX & (TEXTURE_WIDTH - 1))]; // Texture's color
   
    if(color != 0xff)
    {
     setPixelBuf(screen, x, y, color);
     setPixelBuf(screen, x + 1, y, color);
     setPixelBuf(screen, x, y + 1, color);
     setPixelBuf(screen, x + 1, y + 1, color);
    }
   }
  }
 
 
  refresh(screen);
  tunnel_zoom += 2;
 }

 free(screen);
 free(angle_lut);
 free(depth_lut);
 return 0;
}


Viewing all articles
Browse latest Browse all 75370

Trending Articles