raycasting

This is a discussion on raycasting within the Game Programming forums, part of the General Programming Boards category; I've seen several demos of raycasting on this site (they're all helpful) but i need something special. I am programming ...

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    2

    Question raycasting

    I've seen several demos of raycasting on this site (they're all helpful)
    but i need something special.
    I am programming for a console and i need a raycaster that can ray cast a certain size.
    If any one could tell me how to change the resolution of a raycaster, could you please tell me?

    thanx in advance
    The Gnat

  2. #2
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,590
    To change the resolution of a ray caster you simply change the cellsize of each cell.


    gridx=rayx/CELLSIZE
    gridy=rayy/CELLSIZE

    I assume you are splitting rayx and rayy up into two separate functions based upon tangents instead of sin and cos.

    Wolf3D uses a cell size of 64 as well as texture sizes of 64. Be careful when altering the cell size because it can produce very ugly images when incorrect values are used. Also if you do not change the step size of your player, but increase the cell size, you may be causing the player to walk a very long way or you may cause the player to not be able to hardly move at all.

    If you wish to change the resolution at which the ray caster casts rays you do this. This is assuming a 360 degree circle.

    AngleInc=HFOV/ScreenWidth
    NumAngles=RayStep/NumAnglesInCircle

    so the angle increment on a screen width of 320 is .1875 and the number of angles is 1920. These can be pre-calculated.

    #define PI 3.14159
    double cos[NumAngles];
    double sin[NumAngles];

    double angle=0.0;
    for (int i=0;i<NumAngles;i++)
    {
    cos[i]=(angle*PI/(double)180);
    sin[i]=(angle*PI/(double)180);
    angle+=AngleInc;
    }


    This is if you use cos and sin - for tangents you do the same but you must make sure you do not try to take the tangent of an invalid angle such as 90 or 270 (90/AngleInc,270/AngleInc).

  3. #3
    Registered User
    Join Date
    Apr 2002
    Posts
    2

    Question re-raycasting

    I got some of that,
    my program uses sine+cosine and is single coloured walls (not textured)
    I'm trying to pull the size of the screen from 360x240 to 160x128
    (half size of 360x240 is 180x120, i was thinking of blending a 2x2 set of pixels together)


    just in case, can anyone tell me where i can get a program that blends a 15bit map into a half length+width bitmap?

    thanx anywayz Bubba

  4. #4
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,590
    Do not use sine and cosine. Go here for more information on raycasting. It also discusses raycasting with textures.

    www.peroxide.dk

    Go to the tutorials sections and download them.

    To change the resolution you will also change the number of angles on the screen. Follow my example to do just that. What you are doing is filtering the screen, or you are making one pixel equal one block of pixels, which would be extremely ugly. There is no need to do this.


    Your framerate problems are stemming from your use of sine and cosine. Using tangents is much faster.

    sin(angle)= a/h
    cos(angle)=o/h
    tan(angle)=o/a

    So if you know the angle and the size of either the adjacent or opposite, you can find the step size by solving the tangent equation for o and a respectively. Since the cell size will never change in an orthogonic projection, you can increase x and y by constants depending on whether or not you are tracing the x-ray or y-ray. This will reduce your intersections test by a factor of 10 on a 10x10 map.

    Simple trigonometry will help you a lot in raycasting as well as using as many look-up tables as you can.

    For screen size of 160 your angle increment would be 60/160 or .375 which would yield 960 tangents instead of 1920, given you are using 360 degree circle. Some use 256 degrees in a circle.

    There is no need to vertically scale the projection since the viewer is assumed to always be looking at the middle of the walls. The only time you must also vertical raycast is normally in the case of voxels and heightmaps or if you wanted to program a DOOM type raycaster, which is essentially a heightmap and a texturemap raycaster. Very close to a voxel-type projection.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Raycasting
    By damien_casaveli in forum Game Programming
    Replies: 3
    Last Post: 11-28-2004, 07:31 AM
  2. Raycasting code
    By BMJ in forum Game Programming
    Replies: 2
    Last Post: 09-07-2004, 03:26 PM
  3. Doors in a raycasting engine
    By lmaster in forum Game Programming
    Replies: 3
    Last Post: 06-09-2004, 11:57 PM
  4. raycasting sprites
    By lmaster in forum Game Programming
    Replies: 1
    Last Post: 12-21-2003, 11:34 PM
  5. Raycasting Tutorials??..?.?.//.?>?
    By kaygee in forum Game Programming
    Replies: 9
    Last Post: 01-26-2002, 05:06 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21