SliderFloat3的实现委托给SliderScalarN,其实现如下:
bool ImGui::SliderScalarN(const char* label, ImGuiDataType data_type, void* v, int components, const void* v_min, const void* v_max, const char* format, float power)
{
ImGuiWindow* window = GetCurrentWindow();
if (window->SkipItems)
return false;
ImGuiContext& g = *GImGui;
bool value_changed = false;
BeginGroup();
PushID(label);
PushMultiItemsWidths(components, CalcItemWidth());
size_t type_size = GDataTypeInfo[data_type].Size;
for (int i = 0; i < components; i++)
{
PushID(i);
if (i > 0)
SameLine(0, g.Style.ItemInnerSpacing.x);
value_changed |= SliderScalar("", data_type, v, v_min, v_max, format, power);
PopID();
PopItemWidth();
v = (void*)((char*)v + type_size);
}
PopID();
const char* label_end = FindRenderedTextEnd(label);
if (label != label_end)
{
SameLine(0, g.Style.ItemInnerSpacing.x);
TextEx(label, label_end);
}
EndGroup();
return value_changed;
}
出于您的目的,您需要使用此函数的修改版本,该版本可以移动v\u min和v\u max以及v,因此在修改后的函数中,将For循环的最后一行更改为:
v = (void*)((char*)v + type_size);
v_min = (void*)((char*)v_min + type_size);
v_max = (void*)((char*)v_max + type_size);
浮动*v、v_min、v_max;
最后,您可以调用修改后的函数,如下所示:
float mins[] = {0.0f, 0.0f, 0.0f};
float maxs[] = {960.0f, 540.0f, 0.0f};
MyModifiedSliderFloat3("Model Matrix Translation", &model_matrix_translation.x, mins, maxs);