Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - bwang

Pages: 1 ... 36 37 [38] 39 40 ... 44
556
TI-Nspire / Re: Nspire Raycaster
« on: April 02, 2010, 07:38:52 pm »
YES! I got sprites working. The current sprites suck, though (they are only 32x32 with two shades of gray). A nice thing about the algorithm is that the speed does not depend very much on sprite resolution (meaning in theory we can have HUGE sprites). New demo is attached.

Lower resolution textures would not help speed up floor casting, since the algorithm depends only on the number of pixels on the screen. Variable-height columns may be possible.

Why is the forum giving me an error about a file with the same name being present when I try to attach a file named ncaster.tns?

557
Awesome! I see it supports the 84 keypad too. Will it have save states and all the other goodies one would expect in an emulator?

558
TI-Nspire / Re: Nspire Raycaster
« on: April 02, 2010, 01:17:11 am »
I had a version with floor textures a while ago, but I took them out because they were causing a dramatic slowdown (floors need to be textured pixel by pixel, so around 20,000 calculations have to be done per frame to draw them). Different heights of sprites sounds possible, though.

Adding collision detection to stop the player from getting close seems like and excellent idea, now that I know its the norm in most FPSes. I was contemplating this a while ago, but didn't add it because I felt it was a rather hackish way to improve speed.

Quote
It is a bit strange, though, because normally in FPSes on the PC, it's when elements that are far away needs to be rendered that the game slows down, not when you're viewing a wall close XD. I guess it's cuz it uses a different algorythm.

On an untextured scene, it would slow down when you see far away elements. But the engine needs to texture more when the columns are closer, which slows it down.

559
TI-Nspire / Re: Nspire Raycaster
« on: April 01, 2010, 01:14:18 am »
It seems that per column, sprites take a little bit more work than texture mapping. Whats with the upside-down text?

560
Hmmm... Seems like they're getting revenge for the RSA factoring and Ndless.

561
TI-Nspire / Re: Nspire Raycaster
« on: March 31, 2010, 07:30:36 pm »
Well, that depends on on difficult linking is on the Nspire.
Besides, I don't have sprites yet. That's next on my to-do list!

562
TI-Nspire / Re: Nspire Raycaster
« on: March 31, 2010, 04:10:15 pm »
I finally fixed the looking up/down code, so the bottoms of the walls no longer vanish when you are close to them.
New demo attached.

563
TI-Nspire / Re: Nspire Raycaster
« on: March 31, 2010, 01:36:07 am »
There was a small bug in the previous demo. I attached a new one.
EDIT: Seems like there are more bugs. Should be easy to fix, since the looking up/down code is only 3 lines.

564
TI-Nspire / Re: Nspire Raycaster
« on: March 31, 2010, 12:23:08 am »
Hmmm... would it be legal for me to post an Nspire Emulator image file with Ndless preinstalled?

565
TI-Nspire / Re: Nspire Raycaster
« on: March 31, 2010, 12:03:59 am »
New demo! This one supports looking up and down (use +/- to do so).

566
TI-Nspire / Re: Nspire Raycaster
« on: March 30, 2010, 06:20:45 pm »
Making it volatile unsigned did the trick. Hooray for 67% more speed!

567
TI-Nspire / Re: Nspire Raycaster
« on: March 30, 2010, 02:41:02 am »
How much FPS does the FAT engine get (so I have an idea of what to aim for)?
I think I'm going to rewrite the engine, since I found a tutorial that seems to be much more like the FAT engine's code.

568
TI-Nspire / Re: Nspire Raycaster
« on: March 28, 2010, 11:34:22 pm »
Source Code:
Code: [Select]
#include <os.h>
#include "utils.h"
#include "rayheader.h"
#define mapWidth 24
#define mapHeight 24
#define texW 32
#define texH 32
#define cos1 0.9950
#define sin1 0.09983
#define stpsize 0.2

asm(".string \"PRG\"\n");

int main(void)
{
  *(unsigned*) 0x900B0000 = 0x00000002;
  *(unsigned*) 0x900B000C = 4;

  int map[mapWidth][mapHeight]=
  {
  {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
  {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
  {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
  {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
  {1,0,0,0,0,0,1,1,1,1,1,0,0,0,0,1,0,1,0,1,0,0,0,1},
  {1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1},
  {1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,1,0,0,0,1,0,0,0,1},
  {1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1},
  {1,0,0,0,0,0,1,1,0,1,1,0,0,0,0,1,0,1,0,1,0,0,0,1},
  {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
  {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
  {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
  {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
  {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
  {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
  {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
  {1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
  {1,1,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
  {1,1,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
  {1,1,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
  {1,1,0,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
  {1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
  {1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
  {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}
  };
  char* scrbuf = (char*) malloc(SCREEN_BYTES_SIZE);
  int tex[texW][texH]; 
  int u, v;
  for (u = 0; u < texW; u++) {
    for (v = 0; v < texH; v++) {
      tex[u][v] = 6;
    }
  }
  for (u = 0; u < texW; u++) {
    for (v = 0; v < texH; v++) {
      if (u % 4 == 3 || (v % 8 == 2 && ((u / 4) % 2) == 0) ||
         (v % 8 == 6 && ((u / 4) % 2) == 1)) {
        tex[u][v] = 15;
      }
    }
  }
  float px = 12, py = 12; 
  float dx = -1, dy = 0;
  float plx = 0, ply = 0.66;
  int w = 320, h = 240;
  int x, y;
  int redraw;
  while (!isKeyPressed(KEY_NSPIRE_ESC)) {
    redraw = 0;
    if (isKeyPressed(KEY_NSPIRE_LEFT)) {
      float olddx = dx;
      dx = dx * cos1 - dy * sin1;
      dy = olddx * sin1 + dy * cos1;
      float oldplx = plx;
      plx = plx * cos1 - ply * sin1;
      ply = oldplx * sin1 + ply * cos1;
      redraw = 1;
    }
    if (isKeyPressed(KEY_NSPIRE_RIGHT)) {
      float olddx = dx;
      dx = dx * cos1 + dy * sin1;
      dy = -olddx * sin1 + dy * cos1;
      float oldplx = plx;
      plx = plx * cos1 + ply * sin1;
      ply = -oldplx * sin1 + ply * cos1;
      redraw = 1;
    }
    if (isKeyPressed(KEY_NSPIRE_UP)) {
      if (map[(int) (px + stpsize * dx)][(int) (py)] == 0) px += stpsize * dx;
      if (map[(int) (px)][(int) (py + stpsize * dy)] == 0) py += stpsize * dy;
      if (px < 0) px = 0;
      if (px > 24) px = 24;
      if (py < 0) py = 0;
      if (py > 24) py = 24;
      redraw = true;
    }
    if (isKeyPressed(KEY_NSPIRE_DOWN)) {
      if (map[(int) (px - stpsize * dx)][(int) (py)] == 0) px -= stpsize * dx;
      if (map[(int) (px)][(int) (py - stpsize * dy)] == 0) py -= stpsize * dy;
      if (px < 0) px = 0;
      if (px > 24) px = 24;
      if (py < 0) py = 0;
      if (py > 24) py = 24;
      redraw = true;
    }
    if (redraw) {
      memset(scrbuf, 0x00, SCREEN_BYTES_SIZE);
      for(x = 0; x < w; x++) {
        float raypx = px;
        float raypy = py;
        int mapX = (int) raypx;
        int mapY = (int) raypy;
        float cameraX = 2 * x / (float) (w) - 1;
        float raydx = dx + plx * cameraX;
        float raydy = dy + ply * cameraX;       
        float sideDistX;
        float sideDistY;
        float raydx2 = raydx * raydx, raydy2 = raydy * raydy;
        float deltaDistX = sqrt(1 + raydy2 / raydx2);
        float deltaDistY = sqrt(1 + raydx2 / raydy2);
        float perpWallDist;
           
        int stepX;
        int stepY;

        int hit = 0;
        int side;
     
        if (raydx < 0) {
          stepX = -1;
          sideDistX = (raypx - mapX) * deltaDistX;
        } else {
          stepX = 1;
          sideDistX = (mapX + 1.0 - raypx) * deltaDistX;
        }
        if (raydy < 0) {
          stepY = -1;
          sideDistY = (raypy - mapY) * deltaDistY;
        } else {
          stepY = 1;
          sideDistY = (mapY + 1.0 - raypy) * deltaDistY;
        }
        while (!hit) {
          if (sideDistX < sideDistY) {
            sideDistX += deltaDistX;
            mapX += stepX;
            side = 0;
          } else {
            sideDistY += deltaDistY;
            mapY += stepY;
            side = 1;
          }
          if (map[mapX][mapY]) hit = 1;
        }
        if (side == 0) {
          perpWallDist = fabs((mapX - raypx + (1 - stepX) / 2) / raydx);
        } else {
          perpWallDist = fabs((mapY - raypy + (1 - stepY) / 2) / raydy);
        }

        int lineHeight = abs((int) (h / perpWallDist));
         
        int drawStart = (-lineHeight + h) / 2;
        if(drawStart < 0) drawStart = 0;
        int drawEnd = (lineHeight + h) / 2;
        if(drawEnd >= h) drawEnd = h - 1;

        float wallX;
        if (side == 1) {
          wallX = raypx + ((mapY - raypy + (1 - stepY) / 2) / raydy) * raydx;
        } else {       
          wallX = raypy + ((mapX - raypx + (1 - stepX) / 2) / raydx) * raydy;
        }
        wallX -= (int) wallX;
        int texX = (int) (wallX * (float) (texW));
        if(side == 0 && raydx > 0) texX = texW - texX - 1;
        if(side == 1 && raydy < 0) texX = texW - texX - 1;

        for (y = drawStart; y <= drawEnd; y++) {
          int d = (y << 8) - (h << 7)  + (lineHeight << 7);
          int texY = ((d * texH) / lineHeight) >> 8 ;
          int color = tex[texY][texX];
          if (side == 1) color = color / 2  ;
          setPixelBuf(scrbuf, x, y, color);
        }
      }
      refresh(scrbuf);
    }
  }

  *(unsigned*) 0x900B0000 = 0x00141002;
  *(unsigned*) 0x900B000C = 4;
  return 0;
}

569
TI-Nspire / Re: Nspire Raycaster
« on: March 28, 2010, 08:02:02 pm »
Hmm...the clock speed stuff doesn't seem to work on my calculator, either. Maybe it has something to do with hardware changes in newer calcs?

570
TI-Nspire / Re: Nspire Raycaster
« on: March 28, 2010, 02:37:04 pm »
Quote
Question I have is will it support being able to look up and down?
That depends on how computationally intensive looking up and down is, how much speed I have left after adding sprites, and how much I can optimize the code.

calc84: The clock speed changing code you posted doesn't seem to do anything. Is there a special way I have to use it, or can I just stick it anywhere in my code?

Pages: 1 ... 36 37 [38] 39 40 ... 44