diff --git a/main.cpp b/main.cpp index ff050c8..70307ac 100644 --- a/main.cpp +++ b/main.cpp @@ -24,7 +24,7 @@ int main(int argc, char** argv) SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255); SDL_Event eventHandler; - global::entList.push_back(square(200, 200, 50)); + global::entList.push_back(&square(200, 200, 50)); //global::entList3D.push_back(cube(200, 200, 100, 50)); @@ -40,10 +40,12 @@ int main(int argc, char** argv) 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); - + std::cout << global::entList.at(0) << std::endl; + if (ray.hitEnt) + std::cout << std::hex << ray.hitEnt << std::endl; //demo rays with moving object - global::entList.at(0).x = global::mousePos.x; - global::entList.at(0).y = global::mousePos.y; + global::entList.at(0)->x = global::mousePos.x; + global::entList.at(0)->y = global::mousePos.y; global::entList.run(renderer); global::entList3D.run(renderer); diff --git a/stuff/objects/entityList2D.h b/stuff/objects/entityList2D.h index c837707..5b3a2e3 100644 --- a/stuff/objects/entityList2D.h +++ b/stuff/objects/entityList2D.h @@ -6,14 +6,14 @@ /* entityList2D is the 2D entity container class */ -class entityList2D : public std::vector +class entityList2D : public std::vector { public: void run(SDL_Renderer* renderer) { - for (square entity : *this) + for (square* entity : *this) { - entity.run(renderer); + entity->run(renderer); } } }; \ No newline at end of file diff --git a/stuff/objects/ray2D.h b/stuff/objects/ray2D.h index f39a4a3..f99592a 100644 --- a/stuff/objects/ray2D.h +++ b/stuff/objects/ray2D.h @@ -14,6 +14,7 @@ struct ray2D vector2 start; vector2 end; float dist; + square* hitEnt; static ray2D trace(vector2 start, vector2 direction) { ray2D ray { start, start, -1 }; @@ -21,13 +22,14 @@ struct ray2D bool hit = false; while (!hit) { - 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.start = start; ray.end = point; ray.dist = start.distance(point); + ray.hitEnt = object; hit = true; break; }