Slider.setValue bugging out

Anything libgdx related goes here!

Slider.setValue bugging out

Postby Anitrate » Sat Feb 08, 2020 3:22 pm

Hi there! So long story short I'm making a set of sliders that change the rotation of a modelInstance. I've implemented an undo/redo feature (that can go back 19 times) which works well until I try to set the value of the sliders to match the instances rotation, for whatever reason the sliders value only sometimes changes position and it causes my method of undoing to completely break. Normally if something breaks like this it's due to some really bad and buggy code that's hiding in plain sight but I can't find it. Here are some videos on the issue: Without setting value (works) https://www.youtube.com/watch?v=7-ACR9PxMOw, with setting value (doesn't work) https://www.youtube.com/watch?v=SOhFoRW1PKk&authuser=0

Listener of the slider:
Code: Select all
 
            final int k = i;
            final int l = j;
            rotationSlider[i][j].addListener(new EventListener() {//I is the instance in question (multiple can be selected at once, and j is the axis //0 = x, 1 = y, 2 = z // in two for loops
                @Override
                public boolean handle(Event event) {
                    createScreen.changeInstanceRotation(k, rotationSlider[k][l].getValue() - previousValue[k][l], l);
                    lastSliderInteractedWith[k] = l;
                    createScreen.userInteractingWithUI = true;
                    previousValue[k][l] = rotationSlider[k][l].getValue();
                    return true;
                }
            });


Undo/redo:
Detect changes in the rotation of instance, when using Slider.setValue() it sometimes fires off when it's not meant to.
Code: Select all
if((previousRotation.x != rotation.x || previousRotation.y != rotation.y || previousRotation.z != rotation.z) && !userInteractingWithUI && !Gdx.input.isTouched()) {//if the instances rotation has changed update the history
                if(currentRotationHistory != 0) {
                    resetCurrentHistory();//If the user rotates object while in history remove any moves made after this history
                }

                for(int i = 19 ; i > 0 ; i--) {//move all history back a slot
                    if(rotationHistory[i - 1] != null) {
                        rotationHistory[i] = rotationHistory[i - 1].cpy();
                    }
                    if(sliderAxisHistory[i - 1] != -1) {
                        sliderAxisHistory[i] = sliderAxisHistory[i - 1];
                    }
                    if(sliderValueHistory[i - 1] != -1) {
                        sliderValueHistory[i] = sliderValueHistory[i - 1];
                    }
                }
                //set current values
                rotationHistory[0] = rotation.cpy();
                sliderAxisHistory[0] = createScreenUI.getLastSliderInteractedWith(identifier);
                sliderValueHistory[0] = createScreenUI.getSliderValue(identifier, createScreenUI.getLastSliderInteractedWith(identifier));

                if(maxRotationUndo != 19) {//prevent undoing beyond the original history
                    maxRotationUndo++;
                }
       
                previousRotation = rotation.cpy();
            }


the undo method:
Code: Select all
            modelInstance[i].currentRotationHistory += amount;//undo/redo // amount is either 1 or -1
            modelInstance[i].transform.set(modelInstance[i].position, modelInstance[i].rotationHistory[modelInstance[i].currentRotationHistory]); //set its position to the history
            modelInstance[i].transform.getRotation(modelInstance[i].rotation);//set rotation value
            modelInstance[i].transform.getRotation(modelInstance[i].previousRotation);//set previous rotation to stop rotation detection method from firing off
            createScreenUI.setSliderValue(i, modelInstance[i].sliderAxisHistory[modelInstance[i].currentRotationHistory], modelInstance[i].sliderValueHistory[modelInstance[i].currentRotationHistory]);//set the sliders value to match the instances rotation
       


setting the sliders value:

Code: Select all
public void setSliderValue(int i, int axis, float value) {
        rotationSlider[i][axis].setValue(value);
        previousValue[i][axis] = value;
    }


To prove that the history code isn't bunked I did some logging (not on the videos provided) and came back with this:

I/System.out: i = 0, axis = 0, value = 279.0
I/System.out: i = 0, axis = 1, value = 135.0
I/System.out: i = 0, axis = 1, value = 264.0
I/System.out: PR = [0.30901486|0.0|0.0|0.9510572]
I/System.out: R = [0.9914446|0.0|0.0|0.13052846]
I/System.out: i = 0, axis = 0, value = 132.0
I/System.out: PR = [0.91354454|0.0|0.0|0.40673986]
R = [-0.13052915|0.0|0.0|0.9914448]
I/System.out: i = 0, axis = 0, value = 132.0
I/System.out: i = 0, axis = 0, value = 255.0
I/System.out: i = 0, axis = 0, value = 0.0
i = 0, axis = 1, value = 0.0
i = 0, axis = 2, value = 0.0

Those are all good numbers (0-360) and on different axes, the PR and R is the difference in rotation method firing off which should not be happening, the logical answer would be that the previous rotation value and previous slider value are causing issues but I specifically set their values to make sure this doesn't happen. My best guess is that it's just something to do with the listener on the slider.
Anitrate
 
Posts: 6
Joined: Mon Jul 16, 2018 11:39 am

Return to Libgdx

Who is online

Users browsing this forum: No registered users and 1 guest