return toolong rays at max dist isntead of failing

master
BuildTools 4 years ago
parent c84dedd768
commit b0d7bb7cfd
  1. 14
      demo/demo.cpp
  2. 7
      stuff/objects/ray2D.h

@ -2,14 +2,14 @@
void game::run(SDL_Renderer* renderer) void game::run(SDL_Renderer* renderer)
{ {
ray2D ray = ray2D::trace(vector2(0, 201), vector2(1, 0)); for (int i = 0; i < 360; i += 1)
ray2D ray2 = ray2D::trace(vector2(201, 0), vector2(0, 1)); {
SDL_RenderDrawLine(renderer, ray.start.x, ray.start.y, ray.end.x, ray.end.y); float x = 1 * sinf(i);
SDL_RenderDrawLine(renderer, ray2.start.x, ray2.start.y, ray2.end.x, ray2.end.y); float y = 1 * cosf(i);
std::cout << global::entList.at(0) << std::endl; ray2D ray2 = ray2D::trace(vector2(300, 300), vector2(x, y));
if (ray.hitEnt)
std::cout << std::hex << ray.hitEnt << std::endl;
SDL_RenderDrawLine(renderer, ray2.start.x, ray2.start.y, ray2.end.x, ray2.end.y);
}
//demo rays with moving object //demo rays with moving object
global::entList.at(0)->x = global::mousePos.x; global::entList.at(0)->x = global::mousePos.x;
global::entList.at(0)->y = global::mousePos.y; global::entList.at(0)->y = global::mousePos.y;

@ -19,7 +19,7 @@ struct ray2D
{ {
for (square* object : global::entList) for (square* object : global::entList)
{ {
if (inRect(point, vector2(object->x, object->y), vector2(object->x + object->radius, object->y + object->radius))) if (inRect(point, vector2(object->x, object->y), vector2(object->x + object->radius, object->y + object->radius)) || ray.dist > 1500)
{ {
ray.start = start; ray.start = start;
ray.end = point; ray.end = point;
@ -30,11 +30,6 @@ struct ray2D
} }
} }
ray.dist = start.distance(point); ray.dist = start.distance(point);
if (ray.dist > 1500)
{
ray.dist = -1;
break;
}
point.x += direction.x; point.x += direction.x;
point.y += direction.y; point.y += direction.y;
} }

Loading…
Cancel
Save