Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Box scaling (custom aspect ratios) #46

Merged
merged 9 commits into from
Jan 4, 2025
Merged

Box scaling (custom aspect ratios) #46

merged 9 commits into from
Jan 4, 2025

Conversation

brenocq
Copy link
Owner

@brenocq brenocq commented Jan 4, 2025

This PR implements the custom aspect ratio proposed in #15 and #24

The plot box can now be scaled using the context menu (right-click), or programmatically.

Change with context menu

Here is an example of changing the box scale using the context menu.

Peek.2025-01-04.14-15.mp4

Change with code

And here is the new demo demonstrating how to do it through code (from implot3d_demo.cpp).

Peek.2025-01-04.14-16.mp4

The demo code:

void DemoBoxScale() {
    constexpr int N = 100;
    float xs[N], ys[N], zs[N];
    for (int i = 0; i < N; ++i) {
        float t = i / (float)(N - 1);
        xs[i] = sinf(t * 2.0f * IM_PI);
        ys[i] = cosf(t * 4.0f * IM_PI);
        zs[i] = t * 2.0f - 1.0f;
    }

    static float scale[3] = {1.0f, 1.0f, 1.0f};
    ImGui::SliderFloat3("Box Scale", scale, 0.1f, 2.0f, "%.2f");

    if (ImPlot3D::BeginPlot("##BoxScale")) {
        ImPlot3D::SetupBoxScale(scale[0], scale[1], scale[2]);
        ImPlot3D::PlotLine("3D Curve", xs, ys, zs, N);
        ImPlot3D::EndPlot();
    }
}

Other changes

  • Added IMPLOT_DISABLE_OBSOLETE_FUNCTIONS to implot3d.cpp and implot3d_demo.cpp to avoid using deprecated ImGui API
  • Improved Locator_Default to change the grid depending on the plot box scale

@brenocq brenocq added type:feat New feature or request prio:high High priority status:done Task completed successfully labels Jan 4, 2025
@brenocq brenocq self-assigned this Jan 4, 2025
@brenocq brenocq merged commit 4be7ae6 into dev Jan 4, 2025
8 checks passed
@brenocq brenocq deleted the box-aspect-scale branch January 4, 2025 13:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
prio:high High priority status:done Task completed successfully type:feat New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant