Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (476)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (531)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Raycasting  (Read 1413 times)
0 Members and 1 Guest are viewing this topic.
Offline mfrancis

Innocent Bystander





« Posted 2012-05-14 23: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?
Offline gouessej
« Reply #1 - Posted 2012-05-15 00:18:30 »

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.

Offline westloar

Junior Member





« Reply #2 - Posted 2012-05-18 01:19:30 »

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

BOOM TRIPLE WORD SCORE!
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

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

The first screenshot will be displayed as a thumbnail.

pw (13 views)
2014-07-24 01:59:36

Riven (13 views)
2014-07-23 21:16:32

Riven (13 views)
2014-07-23 21:07:15

Riven (14 views)
2014-07-23 20:56:16

ctomni231 (43 views)
2014-07-18 06:55:21

Zero Volt (39 views)
2014-07-17 23:47:54

danieldean (32 views)
2014-07-17 23:41:23

MustardPeter (35 views)
2014-07-16 23:30:00

Cero (50 views)
2014-07-16 00:42:17

Riven (50 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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!