Raycasting

Hi. I decided to use the tutorials and source code from http://www.permadi.com/tutorial/raycast/index.html as a basis for a raycasting game/engine that I’d like to develop. It seems great so far, but there’s something I’d like to change:

  static final int ANGLE60 = PROJECTIONPLANEWIDTH;
  static final int ANGLE30 = (ANGLE60/2);
  static final int ANGLE15 = (ANGLE30/2);
  static final int ANGLE90 = (ANGLE30*3);
  static final int ANGLE180 = (ANGLE90*2);
  static final int ANGLE270 = (ANGLE90*3);
  static final int ANGLE360 = (ANGLE60*6);
  static final int ANGLE0 = 0;
  static final int ANGLE5 = (ANGLE30/6);
  static final int ANGLE10 = (ANGLE5*2);

  // trigonometric tables
  float fSinTable[];
  float fISinTable[];
  float fCosTable[];
  float fICosTable[];
  float fTanTable[];
  float fITanTable[];
  float fFishTable[];
  float fXStepTable[];
  float fYStepTable[];

and

public void createTables()
  {
    int i;
    float radian;
    fSinTable = new float[ANGLE360+1];
    fISinTable = new float[ANGLE360+1];
    fCosTable = new float[ANGLE360+1];
    fICosTable = new float[ANGLE360+1];
    fTanTable = new float[ANGLE360+1];
    fITanTable = new float[ANGLE360+1];
    fFishTable = new float[ANGLE60+1];
    fXStepTable = new float[ANGLE360+1];
    fYStepTable = new float[ANGLE360+1];

    for (i=0; i<=ANGLE360;i++)
    {
      // get the radian value (the last addition is to avoid division by 0, try removing
          // that and you'll see a hole in the wall when a ray is at 0, 90, 180, or 270 degree)
      radian = arcToRad(i) + (float)(0.0001);
      fSinTable[i]=(float)Math.sin(radian);
      fISinTable[i]=(1.0F/(fSinTable[i]));
      fCosTable[i]=(float)Math.cos(radian);
      fICosTable[i]=(1.0F/(fCosTable[i]));
      fTanTable[i]=(float)Math.tan(radian);
      fITanTable[i]=(1.0F/fTanTable[i]);

        //  you can see that the distance between xi is the same
        //  if we know the angle
        //  _____|_/next xi______________
        //       |
        //  ____/|next xi_________   slope = tan = height / dist between xi's
        //     / |
        //  __/__|_________  dist between xi = height/tan where height=tile size
        // old xi|
        //                  distance between xi = x_step[view_angle];
        //
        //
        // facine left
      // facing left
      if (i>=ANGLE90 && i<ANGLE270)
      {
        fXStepTable[i] = (float)(TILE_SIZE/fTanTable[i]);
        if (fXStepTable[i]>0)
          fXStepTable[i]=-fXStepTable[i];
      }
      // facing right
      else
      {
        fXStepTable[i] = (float)(TILE_SIZE/fTanTable[i]);
        if (fXStepTable[i]<0)
          fXStepTable[i]=-fXStepTable[i];
      }

      // FACING DOWN
      if (i>=ANGLE0 && i<ANGLE180)
      {
        fYStepTable[i] = (float)(TILE_SIZE*fTanTable[i]);
        if (fYStepTable[i]<0)
          fYStepTable[i]=-fYStepTable[i];
      }
      // FACING UP
      else
      {
        fYStepTable[i] = (float)(TILE_SIZE*fTanTable[i]);
        if (fYStepTable[i]>0)
          fYStepTable[i]=-fYStepTable[i];
      }
    }

    for (i=-ANGLE30; i<=ANGLE30; i++)
    {
        radian = arcToRad(i);
        // we don't have negative angle, so make it start at 0
        // this will give range 0 to 320
        fFishTable[i+ANGLE30] = (float)(1.0F/Math.cos(radian));
    }

It seems that these tables generate trig function values that would only be of use to raycasting specifically with a specific width, height, and what not. I’d like to use something like this: http://code.google.com/p/libgdx/source/browse/trunk/gdx/src/com/badlogic/gdx/math/MathUtils.java because I feel it would unionize the trig functions more and not just serve the raycasting rendering process alone; I could use the trig functions for other things such as weapon bobbing movement.

Problem is, I’m completely lost and I don’t have any idea how I can implement this and replace the old trig tables in the source code without it messing with the rendering process completely. Can anyone help me with this please?

Hi

You will have to keep step and fish tables. Take care of the units. I used raycasting in 2006 for my first person shooter, keep in mind it is very slow. I hope you use it only for pedagogical purposes.

I have nothing to add to this post except for this, gouessej:

BOOM TRIPLE WORD SCORE!