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