Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (527)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (594)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1]
1  Game Development / Newbie & Debugging Questions / Raycasting on: 2012-05-14 21:35:20
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);

  // trigonometric tables
  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++)
    {
      // 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?
Pages: [1]
 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

PocketCrafter7 (14 views)
2014-11-28 16:25:35

PocketCrafter7 (9 views)
2014-11-28 16:25:09

PocketCrafter7 (10 views)
2014-11-28 16:24:29

toopeicgaming1999 (76 views)
2014-11-26 15:22:04

toopeicgaming1999 (67 views)
2014-11-26 15:20:36

toopeicgaming1999 (16 views)
2014-11-26 15:20:08

SHC (30 views)
2014-11-25 12:00:59

SHC (28 views)
2014-11-25 11:53:45

Norakomi (32 views)
2014-11-25 11:26:43

Gibbo3771 (28 views)
2014-11-24 19:59:16
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!