The link to the header file that @dutch gave earlier shows two overloads of procedure PlotLines: the first takes a pre-computed array of values, the second a pointer to a function that will compute those values. You are currently trying to use the second of these, although I believe that you might actually do better pre-computing the values and using the first, because then you could work out what the max and min values of y were.
1 2 3
|
IMGUI_API void PlotLines(const char* label, const float* values, int values_count, int values_offset = 0, const char* overlay_text = NULL, float scale_min = FLT_MAX, float scale_max = FLT_MAX, ImVec2 graph_size = ImVec2(0, 0), int stride = sizeof(float));
IMGUI_API void PlotLines(const char* label, float(*values_getter)(void* data, int idx), void* data, int values_count, int values_offset = 0, const char* overlay_text = NULL, float scale_min = FLT_MAX, float scale_max = FLT_MAX, ImVec2 graph_size = ImVec2(0, 0));
|
I believe that @dutch's guess was correct. The function takes the integers 0, ..., values_count-1 and returns the value at these points. On this basis, the LHS of the window will correspond to the function returned for idx = 0 and the RHS of the window will correspond to the function returned for idx = values_count - 1.
You appear to have to manually set minimum y and maximum y (which is why a pre-computed array with these limits found might be better). At present, the plotter seems to be clipping at upper (and, presumably, lower) limits; this is relatively unusual behaviour for a plotting routine; I would prefer it to simply stop drawing at this point. Maybe there is some setting in ImGUI to change this. I have no idea what "values_offset" does; I suggest you leave it with the default value 0.
Don't just guess "any old quadratic" - why not construct one for which you know the limits.
1 2 3 4 5 6 7
|
[](void* data, int idx ) // values_getter
{
float x = ( idx - 49.5f )/ 49.5f; // generate an x value from -1 to 1 from idx's from 0 to 99
// and make sure that its y-limits for this interval are -1 and 1
return -1.0f + 2.0f * x * x;
}
|
Now call your function with
values_count = 100;
scale_min = -1.0f;
scale_max = 1.0f;
Let us know how you get on (and preferably show your code).