return -1 dist on failed rays, slightly extend max ray distance

master
BuildTools 5 years ago
parent 4ed7ed1339
commit af8b91ab33
  1. 3
      main.cpp
  2. 5
      stuff/objects/ray2D.h

@ -35,12 +35,13 @@ int main(int argc, char** argv)
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0);
SDL_RenderFillRect(renderer, NULL);
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
ray2D ray = ray2D::trace(vector2(0, 201), vector2(1, 0));
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);
SDL_RenderDrawLine(renderer, ray2.start.x, ray2.start.y, ray2.end.x, ray2.end.y);
//demo rays with moving object
global::entList.at(0).x = global::mousePos.x;
global::entList.at(0).y = global::mousePos.y;

@ -33,8 +33,11 @@ struct ray2D
}
}
ray.dist = start.distance(point);
if (ray.dist > 1000)
if (ray.dist > 1500)
{
ray.dist = -1;
break;
}
point.x += direction.x;
point.y += direction.y;
}

Loading…
Cancel
Save