#include "components/ProjectionComponent.hpp" #include "Entity.hpp" #include "components/GravityReceiverComponent.hpp" #include "components/GravityWellComponent.hpp" #include "components/PhysicsComponent.hpp" #include "components/TransformComponent.hpp" void ProjectionComponent::Setup() { points.clear(); } void ProjectionComponent::Update(float) { points.clear(); highlightActive = false; if (!context || !context->probeEntity || entity != context->probeEntity) { return; } auto transform = entity->GetComponent(); auto physics = entity->GetComponent(); auto receiver = entity->GetComponent(); if (!transform || !physics || !receiver) { return; } Entity *wellEntity = receiver->get().well ? receiver->get().well : context->wellEntity; if (!wellEntity) { return; } auto wellTransform = wellEntity->GetComponent(); auto wellGravity = wellEntity->GetComponent(); if (!wellTransform || !wellGravity) { return; } // only highlight if the well is active, inactive will be a lighter color to show the potential // projection if the player were to activate it highlightActive = wellGravity->get().active; double px = static_cast(transform->get().x); double py = static_cast(transform->get().y); double vx = static_cast(physics->get().vx); double vy = static_cast(physics->get().vy); points.reserve(static_cast(steps)); for (int i = 0; i < steps; ++i) { physics->get().SimulateStep(px, py, vx, vy, static_cast(stepDt), true); points.push_back({static_cast(px), static_cast(py)}); } Draw(); } void ProjectionComponent::Cleanup() { points.clear(); } void ProjectionComponent::Draw() const { if (points.empty()) { return; } const Color base = highlightActive ? activeColor : inactiveColor; for (size_t i = 0; i < points.size(); ++i) { // t goes from 0 to 1 across the points, used for fading effect const float t = (points.size() <= 1) ? 0.0f : (float)i / (points.size() - 1); Color c = base; float alphaScale = 1.0f - t; // multiply alpha to make it fade towards the end c.a = (unsigned char)((float)(base.a) * alphaScale); DrawCircleV(points[i], pointRadius, c); } }