Original Post
I am fairly proficient in c++ and I am working on a project in college. I am creating a roguelike from scratch without using external libraries other than SDL. I am working on implementing field of view for the player. I have looked a several different kinds of algorithms to use but they are either in a different language or I am unable to follow what is going on. Could someone please explain how any kind of FOV algorithm works. It just needs to be simple. Ive tried using Bresenham's line algorithm but i couldnt get it to detect when something was blocking the line.
If anyone could please help me, I would appreciate it.
thanks,
Manderin87
void cMap::calculateLOSBresenham(int x0, int y0, int x1, int y1)
{
int x = 0, y = 0;
int delta_x = x1 - x0;
int delta_y = y1 - y0; // slope defined
int steps = max( abs(delta_x), abs(delta_y));
double c = 1.0 / max(1, steps);
for(int i = 0; i <= steps; i++) {
x = int(x0 + (i * delta_x * c) + 0.5);
y = int(y0 + (i * delta_y * c) + 0.5);
// should detect it in here but i couldnt get it to work.
}
}
If anyone could please help me, I would appreciate it.
thanks,
Manderin87