Thread: how create RayCasting?

  1. #1
    Registered User
    Join Date
    Aug 2013
    Posts
    451

    how create RayCasting?

    how create RayCasting?
    i have seen some videos, but without success
    so i ask: and someone told me that use 1 pixel, or the square size it's the same.. so i did these function:
    Code:
    void DrawRays(){
        //getting the player map position:
        int MapX = floor(PlayerPosX / 32);
        int MapY = floor(PlayerPosY / 32)
        
        //getting the player position for the destination line:
        double DestinationX = PlayerPosX;
        double DestinationY = PlayerPosY;
        
        //testing if i'm on previous hit wall:
        while (LevelMap0[MapY-1][MapX-1] != 1)
        {
            //if don't hit the wall,
            //add the 1 for Map position combined with palyer radians:
            MapX += cos(PlayerRadians);
            MapY += sin(PlayerRadians);
            
            //then we add the square size, by player radians, on destination line:
            DestinationX += cos(PlayerRadians)*32;
            DestinationY += sin(PlayerRadians)*32;
    
    
    
    
        }
        DrawLine(PlayerPosX, PlayerPosY, DestinationX, DestinationY, RGB(0, 255, 0));
    }
    problems:
    - if i change the player radians, the program seems freeze
    - if i move, i can get the same line size

  2. #2
    Registered User
    Join Date
    Jan 2010
    Posts
    179
    Hi, can you post a picture showing an example of this working (or not working). I don't quite understand what's happening. Also is LevelMap0[x][y] just a two dimensional array? This might be easier with a picture or a bit more explanation, thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how use RayCasting?
    By joaquim in forum Game Programming
    Replies: 0
    Last Post: 05-14-2023, 03:51 AM
  2. Raycasting
    By damien_casaveli in forum Game Programming
    Replies: 3
    Last Post: 11-28-2004, 08:31 AM
  3. Raycasting code
    By BMJ in forum Game Programming
    Replies: 2
    Last Post: 09-07-2004, 03:26 PM
  4. raycasting
    By Nat_the_Gnat in forum Game Programming
    Replies: 3
    Last Post: 04-15-2002, 09:04 AM
  5. Raycasting Tutorials??..?.?.//.?>?
    By kaygee in forum Game Programming
    Replies: 9
    Last Post: 01-26-2002, 06:06 PM

Tags for this Thread