Friday, October 14, 2022
HomeGame Developmentc++ - ImGui part generated by loop altering the worth of all...

c++ – ImGui part generated by loop altering the worth of all different lessons with part in the identical loop


I am making an attempt to create a UI part for each object that I’ve on an array so I might change the values of them, and I am doing this by a loop:

for (int i = 0; i < objs_array->measurement(); i++) {

    obj *current_obj = &objs_array->at(i);
    ImGui::PushID(current_obj->id.c_str()); 
    ImGui::Start(current_obj->id.c_str());

    std::string label_x = "Translation x " + current_obj->id;
    std::string label_y = "Translation y " + current_obj->id;
    std::string label_z = "Translation z " + current_obj->id;
   
    ImGui::SliderFloat(label_x.c_str(), &current_obj->translation.x,-50.0f, 50.0f);
    ImGui::SliderFloat(label_y.c_str(), &current_obj->translation.y,-50.0f, 50.0f);
    ImGui::SliderFloat(label_y.c_str(), &current_obj->translation.z,-50.0f, 50.0f);

    ImGui::Finish();
    ImGui::PopID();
}

Only a small instance however the construction is just about the identical. With just one part all the things works effective, nonetheless with a number of objects the final part created is altering the identical values to all different objects and the values of the remaining parts will get mounted at zeroes or with big random values.

I’ve additionally modified the PushID passing the precise object to it nonetheless the behaviour stays the identical.

enter image description here

Relying the way in which I set the PushID, the values get mounted like within the picture or altering for big random values.

Is there one other means I could make this work? Or a strategy to repair this could be superior.

Edit: the double id “translation y” is already mounted.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments