Archive 17/01/2023.

:test_tube: DebugRenderer as GUI

Modanung

Seems to work pretty well.

GUI::GUI(Context* context): Object(context),
    guiScene_{ new Scene{ context } },
    guiCamera_{ guiScene_->CreateChild("Camera")
                         ->CreateComponent<Camera>() },
    guiRenderer_{ guiScene_->CreateComponent<DebugRenderer>() }
{
    guiScene_->CreateComponent<Octree>();

    SharedPtr<Viewport> viewport{
        new Viewport{ context_, guiScene_, guiCamera_ } };
    SharedPtr<RenderPath> renderPath{
        viewport->GetRenderPath()->Clone() };
    renderPath->RemoveCommand(0);
    viewport->SetRenderPath(renderPath);
    GetSubsystem<Renderer>()->SetViewport(1, viewport);

    guiCamera_->GetNode()->SetWorldPosition(Vector3::BACK);
    guiCamera_->SetOrthographic(true);
    guiCamera_->SetOrthoSize(GRAPHICS->GetHeight());

    SubscribeToEvent(E_POSTRENDERUPDATE, DRY_HANDLER(GUI, Draw));
    SubscribeToEvent(E_SCREENMODE, DRY_HANDLER(GUI, HandleScreenModeChanged));
}

void GUI::HandleScreenModeChanged(StringHash eventType, VariantMap &eventData)
{
    guiCamera_->SetOrthoSize(GRAPHICS->GetHeight());
}

And of course I’m trying it out with some harmonic elements. :slight_smile:

void GUI::DrawElipse(const Vector2& center,
                     const Vector2& size, const Color& color)
{
    TypedPolynomial<Vector2> ellipse{};
    ellipse.SetPolynomialType(0, PT_HARMONIC_SIN);
    ellipse.SetPolynomialType(1, PT_HARMONIC_COS);
    ellipse.SetCoefficient(0, center);
    ellipse.SetCoefficient(1, size * .5f);

    const int segments{ 100 };
    const float dt{ 1.f / segments };
    for (int i{ 0 }; i < segments; ++i)
    {
        guiRenderer_->AddLine({ ellipse.Solve((i) * dt) },
                              { ellipse.Solve((i + 1.f) * dt) }, color);
    }
}
Modanung

Because who doesn’t want hypocycloids as GUI elements? :grin:

Each defined by a single TypedPolynomial<Vector2>.

GodMan

So what does this do exactly?

Modanung

It draws shapes. :slight_smile:

Could you be more specific?