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 ... 32 33 [34] 35 36 ... 44
496
TI-Nspire / Re: Nspire Raycaster
« on: April 21, 2010, 01:30:06 pm »
I could always render the floor at a very low resolution, or cheat and use an image.

497
Other Calc-Related Projects and Ideas / Re: TILP: beta-testing...
« on: April 20, 2010, 06:54:04 pm »
Yes, because sending the files via the official Nspire Link Software works.

498
TI-Nspire / Re: Nspire Raycaster
« on: April 20, 2010, 06:53:03 pm »
I think the writer of the client program should write their own collision detection routines, the reason being some games might want custom routines (walk through walls, physics, etc.)

499
TI-Nspire / Re: Nspire Raycaster
« on: April 20, 2010, 06:13:04 pm »
Nearly trivial, but that's low on my priority list. I want to re-organize the code to make it usable as a graphics engine right now. Collision detection and such would be handled by the client program.

500
Other Calc-Related Projects and Ideas / Re: TILP: beta-testing...
« on: April 19, 2010, 11:48:33 pm »
For some reason, I cannot get the 32 KB Gameboy .sav file from VisualBoy Advance to send to my Nspire. It sends correctly on TI's official software, though. I wonder if this is a problem with TILP or because I installed TIEmu.

501
News / Re: TI-Nspire calculators now have Ndless possibilities
« on: April 19, 2010, 11:45:07 pm »
How fast did your Pentium II run a GBA emulator? I never knew such machines could emulate a GBA in a playable way.

502
TI-Nspire / Re: Nspire Raycaster
« on: April 19, 2010, 05:08:11 pm »
Sprite clipping fixed! New demo attached.

503
TI-Nspire / Re: Nspire Raycaster
« on: April 19, 2010, 02:27:38 pm »
It doesn't crash, but doesn't give correct results either. I'm probably doing something wrong when putting values into zbuf.

504
TI-Nspire / Re: Nspire Raycaster
« on: April 18, 2010, 11:33:49 pm »
Lionel Debroux suggested here that I allocate zbuf with malloc. It kind of works (see last post on UTI thread).

505
General Calculator Help / Re: TI Nspire Memory
« on: April 18, 2010, 10:51:33 pm »
I think this is happens on all calculators. All the examples in various languages, and the OS, take up ROM space.

506
TI-Nspire / Re: DevkitPro for Nspire possible?
« on: April 18, 2010, 12:52:33 am »
Hmmm...I see that devkitPro is also a gcc-based toolchain. It should be possible.

507
TI-Nspire / Re: Nspire Raycaster
« on: April 18, 2010, 12:49:35 am »
It didn't work when the data was ints, either.
EDIT: I will post some commented code on Monday, as I am a bit busy right now.

508
TI-Nspire / Re: A symbolic library for the Nspire non-CAS
« on: April 17, 2010, 11:41:26 pm »
thous = thus and inpack = impact, maybe?
I believe there are some places where I calculate the same thing several times over (basically, I want the numerator and denominator of a rational expression, so I simplify it 3 times). I think that's a good place to start optimizing if you want big speedup for relatively little work.

509
TI-Nspire / Re: Nspire Raycaster
« on: April 16, 2010, 05:43:29 pm »
Source:
Code: [Select]
#include <os.h>
#include "utils.h"
#include "raymath.h"
#include "sort.h"
#include "sprites.h"
#include "config.h"

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

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

  struct Sprite sprite[numSprites] =
  {
    {12, 12},
    {13, 12},
    {14, 12},
    {15, 12},
  };

  int map[mapWidth][mapHeight]=
  {
  {0,0,0,0,0,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,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0},
  {0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0},
  {0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0},
  {0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0},
  {0,1,0,0,0,0,0,1,1,1,1,1,0,0,0,0,2,2,2,2,2,0,0,0,1,0},
  {0,1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,2,0,0,0,2,0,0,0,1,0},
  {0,1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,2,0,0,0,0,0,0,0,1,0},
  {0,1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,2,0,0,0,2,0,0,0,1,0},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,0,0,0,0,0,0,0,1,0},
  {0,1,1,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0},
  {0,1,1,0,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,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,1,0},
  {0,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,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,0},
  {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
  };

  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;
      }
    }
  }

  int tex2[texW][texH];
  for (u = 0; u < texW; u++) {
    for (v = 0; v < texH; v++) {
      tex2[u][v] = (u ^ v) / 2;
    }
  }

  int texSpr[texW][texH];
  for (u = 0; u < texW; u++) {
    for (v = 0; v < texH; v++) {
      int dsq = (u - 16) * (u - 16) + (v - 16) * (v - 16);
      if (dsq > 196 && dsq < 256) {
        texSpr[u][v] = 0;
      } else if (dsq < 196 && dsq > 64) {
        texSpr[u][v] = 8;
      } else if (dsq < 64 && dsq > 49) {
        texSpr[u][v] = 0;
      } else {
        texSpr[u][v] = -1;
      }
    }
  }
 
  float posX = 12, posY = 12; 
  float dirX = -1, dirY = 0;
  float planeX = 0, planeY = 0.66;
  int w = 320, h = 240;
  int res = 1;
  int x, y;
  float zbuf[w][h];
  int spriteOrder[numSprites];
  float spriteDistance[numSprites];
  int redraw;
  float heye = 0.5;

  while (!isKeyPressed(KEY_NSPIRE_ESC)) {
    redraw = 0;
    if (isKeyPressed(KEY_NSPIRE_LEFT)) {
      float oldDirX = dirX;
      dirX = dirX * cos1 - dirY * sin1;
      dirY = oldDirX * sin1 + dirY * cos1;
      float oldPlaneX = planeX;
      planeX = planeX * cos1 - planeY * sin1;
      planeY = oldPlaneX * sin1 + planeY * cos1;
      redraw = 1;
    }
    if (isKeyPressed(KEY_NSPIRE_RIGHT)) {
      float oldDirX = dirX;
      dirX = dirX * cos1 + dirY * sin1;
      dirY = -oldDirX * sin1 + dirY * cos1;
      float oldPlaneX = planeX;
      planeX = planeX * cos1 + planeY * sin1;
      planeY = -oldPlaneX * sin1 + planeY * cos1;
      redraw = 1;
    }
    if (isKeyPressed(KEY_NSPIRE_UP)) {
      if (map[(int) (posX + stpsize * dirX)][(int) (posY)] == 0)
        posX += stpsize * dirX;
      if (map[(int) (posX)][(int) (posY + stpsize * dirY)] == 0)
        posY += stpsize * dirY;
      if (posX < 0) posX = 0;
      if (posX > 24) posX = 24;
      if (posY < 0) posY = 0;
      if (posY > 24) posY = 24;
      redraw = true;
    }
    if (isKeyPressed(KEY_NSPIRE_DOWN)) {
      if (map[(int) (posX - stpsize * dirX)][(int) (posY)] == 0)
        posX -= stpsize * dirX;
      if (map[(int) (posX)][(int) (posY - stpsize * dirY)] == 0)
        posY -= stpsize * dirY;
      if (posX < 0) posX = 0;
      if (posX > 24) posX = 24;
      if (posY < 0) posY = 0;
      if (posY > 24) posY = 24;
      redraw = true;
    }
    if (isKeyPressed(KEY_NSPIRE_MINUS)) {
      heye -= 0.1;
      redraw = true;
    }
    if (isKeyPressed(KEY_NSPIRE_PLUS)) {
      heye += 0.1;
      redraw = true;
    }
    if (isKeyPressed(KEY_NSPIRE_DIVIDE)) {
      w = (int) (w * 1.1);
      if (w > 320) w = 320;
      h = (int) (h * 1.1);
      if (h > 240) h = 240;
      redraw = true;
    }
    if (isKeyPressed(KEY_NSPIRE_MULTIPLY)) {
      w = (int) (w * 0.9);
      h = (int) (h * 0.9);
      redraw = true;
    }
    if (isKeyPressed(KEY_NSPIRE_H)) {
      res = 1;
      redraw = true;
    }
    if (isKeyPressed(KEY_NSPIRE_L)) {
      res = 2;
      redraw = true;
    }
    if (redraw) {
      memset(scrbuf, 0x00, SCREEN_BYTES_SIZE);
      for(x = 0; x < w; x += res) {
        float rayPosX = posX;
        float rayPosY = posY;
        int mapX = (int) rayPosX;
        int mapY = (int) rayPosY;
        float cameraX = 2 * x / (float) (w) - 1;
        float raydx = dirX + planeX * cameraX;
        float raydy = dirY + planeY * 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 side;
        float curH = 0;
        int scrtop = h - 1;
     
        if (raydx < 0) {
          stepX = -1;
          sideDistX = (rayPosX - mapX) * deltaDistX;
        } else {
          stepX = 1;
          sideDistX = (mapX + 1.0 - rayPosX) * deltaDistX;
        }
        if (raydy < 0) {
          stepY = -1;
          sideDistY = (rayPosY - mapY) * deltaDistY;
        } else {
          stepY = 1;
          sideDistY = (mapY + 1.0 - rayPosY) * deltaDistY;
        }
        int first = true;
        while (mapX > 0 && mapX < mapWidth && mapY > 0 && mapY < mapHeight ) {
          if (sideDistX < sideDistY) {
            sideDistX += deltaDistX;
            mapX += stepX;
            side = 0;
          } else {
            sideDistY += deltaDistY;
            mapY += stepY;
            side = 1;
          }
          if (!map[mapX][mapY]) continue;
          if (scrtop < 0) break;
          float hwall = height[mapX][mapY];

          if (side == 0) {
            perpWallDist = fabs((mapX - rayPosX + (1 - stepX) / 2) / raydx);
          } else {
            perpWallDist = fabs((mapY - rayPosY + (1 - stepY) / 2) / raydy);
          }

          int nextX;
          int nextY;
          int nextSide;
          if (sideDistX < sideDistY) {
            nextX = mapX + stepX;
            nextSide = 0;
          } else {
            nextY = mapY + stepY;
            nextSide = 1;
          }
           
          float nextD;
          if (nextSide == 0) {
            nextD = fabs((nextX - rayPosX + (1 - stepX) / 2) / raydx);
          } else {
            nextD = fabs((nextY - rayPosY + (1 - stepY) / 2) / raydy);
          }

          int lo = (int) (h * (0.5 - heye / perpWallDist));
          int lw = (int) (h * hwall / perpWallDist);
         
          int nlo = (int) (h * (0.5 - heye / nextD));
          int nlw = (int) (h * hwall / nextD);

          int fstart = h - nlo - nlw;
          int fend = h - lo - lw - 1;
          int wstart = h - lo - lw;
          int wend = h - lo - 1;

          float wallX;
          if (side == 1) {
            wallX = rayPosX + ((mapY - rayPosY + (1 - stepY) / 2) / raydy) * raydx;
          } else {       
            wallX = rayPosY + ((mapX - rayPosX + (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;
         
          //floor loop
          int y;
          int sfstart = max(fstart, 0);
          int sfend = min(fend, scrtop);
          for (y = sfstart; y <= sfend; y++) {
            setPixelBuf(scrbuf, x, y, 8);
            //very large value since sprites always cover floors
            zbuf[x][y] = 1000;
            if (res == 2 && x < w - 1) {
              setPixelBuf(scrbuf, x + 1, y, 8);
              zbuf[x + 1][y] = 1000;
            }
          }
          //wall loop
          float texY = 0;
          float texD = ((float)texH) / ((float)lw);
          int swstart = max(wstart, 0);
          if (swstart == 0) texY += (-wstart) * texD;
          int swend = min(wend, scrtop);
          for (y = swstart; y <= swend; y++) {
            int color = tex[(int) texY][texX];
            if (side == 1) color = color / 2;
            setPixelBuf(scrbuf, x, y, color);
            //set the zbuffer
            zbuf[x][y] = perpWallDist;
            if (res == 2 && x < w - 1) {
              setPixelBuf(scrbuf, x + 1, y, color);
              zbuf[x + 1][y] = perpWallDist;
            }
            texY += texD;
          }
          int oldtop = scrtop;
          scrtop = fstart - 1;
          if (scrtop > wstart - 1) scrtop = wstart;
          if (scrtop > oldtop) scrtop = oldtop;
          curH = hwall;
        }
      }
      int i;
      for(i = 0; i < numSprites; i++)
      {
        spriteOrder[i] = i;
        spriteDistance[i] = ((posX - sprite[i].x) * (posX - sprite[i].x)
                           + (posY - sprite[i].y) * (posY - sprite[i].y));
      }
      combSort(spriteOrder, spriteDistance, numSprites);
       
      for(i = 0; i < numSprites; i++)
      {
        float spriteX = sprite[spriteOrder[i]].x - posX;
        float spriteY = sprite[spriteOrder[i]].y - posY;
           
        float invDet = 1.0 / (planeX * dirY - dirX * planeY);
       
        float transformX = invDet * (dirY * spriteX - dirX * spriteY);
        float transformY = invDet * (-planeY * spriteX + planeX * spriteY);       
             
        int spriteScreenX = (int) ((w / 2) * (1 + transformX / transformY));
       
        #define uDiv 1
        #define vDiv 1
        #define vMove 0.0

        int vMoveScreen = (int) (vMove / transformY);
       
        int spriteHeight = abs((int) (h / transformY)) / vDiv;
        int lo = (int) (h * (0.5 - heye / transformY));
        int drawStartY = h - lo - spriteHeight;
        int drawEndY = h - lo;
        if (drawEndY > h - 1) drawEndY = h - 1;
        int texOff = 0;
        if (drawStartY < 0) {
          texOff = -drawStartY;
          drawStartY = 0;
        }

        int spriteWidth = abs((int) (h / (transformY))) / uDiv;
        int drawStartX = -spriteWidth / 2 + spriteScreenX;
        if(drawStartX < 0) drawStartX = 0;
        int drawEndX = spriteWidth / 2 + spriteScreenX;
        if(drawEndX >= w) drawEndX = w - 1;
       
        int stripe;
        float texD = ((float)texH) / ((float)spriteHeight);
        texOff *= texD;
        for(stripe = drawStartX; stripe < drawEndX; stripe += res)
        {
          int texX = (int) (256 * (stripe - (-spriteWidth / 2 + spriteScreenX)) * texW / spriteWidth) / 256;
          float texY = texOff;
          if(transformY > 0 && stripe > 0 && stripe < w) {
            for(y = drawStartY; y < drawEndY; y++)
            {
              if (y >= 0 && y <= h - 1) {
                if (transformY >= zbuf[stripe][y]) continue;
                int color = texSpr[(int)texY][texX];
                if (color != -1) {
                  setPixelBuf(scrbuf, stripe, y, color);
                  if (res == 2 && stripe < w - 1) {
                    setPixelBuf(scrbuf, stripe + 1, y, color);
                  }
                }
              }
              texY += texD;
            }
          }
        }
      }
      refresh(scrbuf);
    }
  }

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

510
TI-Nspire / Re: Nspire Raycaster
« on: April 16, 2010, 12:37:34 pm »
For some reason, if I make my Z-Buffer a 320x240 array of floats, trying to write anything into it crashes the calculator. Anyone have any ideas why?

phj: no, the walls are not infinitely high internally.

EDIT: This is odder than I thought. Even if I manually check whether the array indices are in-bounds (if (x < w && y < h)...), the program still crashes.

EDIT AGAIN: I had the same problem a while back with a 320x240 array of ints. I also had the same problem with a 320 * 240 1-dimensional array of ints. Should I post source code?

Pages: 1 ... 32 33 [34] 35 36 ... 44