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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| 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);
float fSinTable[]; float fISinTable[]; float fCosTable[]; float fICosTable[]; float fTanTable[]; float fITanTable[]; float fFishTable[]; float fXStepTable[]; float fYStepTable[]; |
and
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
| 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++) { 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]);
if (i>=ANGLE90 && i<ANGLE270) { fXStepTable[i] = (float)(TILE_SIZE/fTanTable[i]); if (fXStepTable[i]>0) fXStepTable[i]=-fXStepTable[i]; } else { fXStepTable[i] = (float)(TILE_SIZE/fTanTable[i]); if (fXStepTable[i]<0) fXStepTable[i]=-fXStepTable[i]; }
if (i>=ANGLE0 && i<ANGLE180) { fYStepTable[i] = (float)(TILE_SIZE*fTanTable[i]); if (fYStepTable[i]<0) fYStepTable[i]=-fYStepTable[i]; } 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); 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?