Quantcast
Channel: Library Questions - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 2896

Sliders' (g4p) changes not affecting my object?

$
0
0

I want 2 separate sliders to rotate 1 stick each, but the sliders seem to not change the value in the objects that I made. This is one tab of my code (main sketch)

// Need G4P library
import g4p_controls.*;

Stick stick1;
Stick stick2;

public void setup(){
  size(480, 320, P3D);
  createGUI();
  customGUI();
  // Place your setup code here
  stick1 = new Stick();
  stick2 = new Stick(0, 20);
}

public void draw(){
  background(230);
  stick1.control();
  stick1.display();

  stick2.control();
  stick2.display();
}

// Use this method to add additional statements
// to customise the GUI controls
public void customGUI(){

}

This is the tab for the class Stick.

class Stick {

 int stickLength = 40;
 int tempRotation = stickRotate.getValueI();
 int tempRotation2 = stick2Rotate.getValueI();
 int strokeColor = 255;
 float rotation;

  Stick() {
    rotation = map(tempRotation, 0, 1023, 1, 2*PI);
  }

  Stick(int c, int tempLength) {
    strokeColor = c;
    stickLength = tempLength;
    rotation = map(tempRotation2, 0, 1023, 1, 2*PI);
  }

  void control() {

  }

  void display() {
    stroke(strokeColor);
    line(width/2, height/2, stickLength*cos(rotation), stickLength*sin(rotation));
  }

}

And lastly, from the GUI builder.

/* =========================================================
 * ====                   WARNING                        ===
 * =========================================================
 * The code in this tab has been generated from the GUI form
 * designer and care should be taken when editing this file.
 * Only add/edit code inside the event handlers i.e. only
 * use lines between the matching comment tags. e.g.

 void myBtnEvents(GButton button) { //_CODE_:button1:12356:
     // It is safe to enter your event code here
 } //_CODE_:button1:12356:

 * Do not rename this tab!
 * =========================================================
 */

public void stick_rotateChange(GSlider source, GEvent event) { //_CODE_:stickRotate:354541:
  println("stickRotate - GSlider >> GEvent." + event + " @ " + millis());
} //_CODE_:stickRotate:354541:

public void stick2Rotate_change(GSlider source, GEvent event) { //_CODE_:stick2Rotate:420625:
  println("stick2Rotate - GSlider >> GEvent." + event + " @ " + millis());
} //_CODE_:stick2Rotate:420625:



// Create all the GUI controls.
// autogenerated do not edit
public void createGUI(){
  G4P.messagesEnabled(false);
  G4P.setGlobalColorScheme(GCScheme.BLUE_SCHEME);
  G4P.setCursor(ARROW);
  surface.setTitle("Sketch Window");
  stickRotate = new GSlider(this, 199, 174, 112, 34, 10.0);
  stickRotate.setRotation(PI/2, GControlMode.CORNER);
  stickRotate.setLimits(0.0, 0.0, 1023.0);
  stickRotate.setNumberFormat(G4P.DECIMAL, 2);
  stickRotate.setOpaque(false);
  stickRotate.addEventHandler(this, "stick_rotateChange");
  stick2Rotate = new GSlider(this, 244, 184, 154, 37, 10.0);
  stick2Rotate.setLimits(500, 0, 1023);
  stick2Rotate.setNumberFormat(G4P.INTEGER, 0);
  stick2Rotate.setOpaque(false);
  stick2Rotate.addEventHandler(this, "stick2Rotate_change");
}

// Variable declarations
// autogenerated do not edit
GSlider stickRotate;
GSlider stick2Rotate;

This is a more condensed version of my main code. I tried creating another code (this one) following the same framework as the original code and it looks like I was able to reproduce the problem. But I can't pinpoint where the problem is. I think the values are not getting into the constructor? Does it only get the initial value? If so, how do i fix this so that the stick follows the sliders? Thank you in advance.


Viewing all articles
Browse latest Browse all 2896

Trending Articles