Answer the question
In order to leave comments, you need to log in
Fix beam throw function?
I'm making a 3D game and using the ray-casting method for this, everything seems to work fine for me, except for the cast ray function itself:
sf::Color cast_ray(float x, float y, float angle, int max_dist) {
float x_pos = x;
float y_pos = y;
float x_step = sin(angle);
float y_step = cos(angle);
for (int i = 0; i < max_dist; i++) {
x_pos += x_step;
y_pos += y_step;
int x_ = x_pos / x_step;
int y_ = y_pos / y_step;
printf("%i %i\n", x_, y_);
if (x_>-1 && x_ < 10 && y_>-1 && y_ < 10) {
if (map[x_][y_] == 1) {
return sf::Color(255, 255, 255);
}
}
}
return sf::Color(0, 0, 0, 0);
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question