Hi there,
I got this error when trying to integrate controlp5 into proscene based on controlp5 examples and examples from this forum. The error points out to the bold lines in the codes. I can't seem to solve this problem.
Can anyone help me on this please?
Thank you
29-Aug-2013 00:26:24 controlP5.ControlBroadcaster printMethodError
SEVERE: An error occured while forwarding a Controller event, please check your code at c0
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at controlP5.ControlBroadcaster.invokeMethod(Unknown Source)
at controlP5.ControlBroadcaster.callTarget(Unknown Source)
at controlP5.ControlBroadcaster.broadcast(Unknown Source)
at controlP5.Controller.broadcast(Unknown Source)
at controlP5.Button.setValue(Unknown Source)
at femur_proscene_obj_interface.createButtons(femur_proscene_obj_interface.java:212)
at femur_proscene_obj_interface.setup(femur_proscene_obj_interface.java:50)
at processing.core.PApplet.handleDraw(Unknown Source)
at processing.core.PApplet.run(Unknown Source)
at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.NullPointerException
at femur_proscene_obj_interface.addStem(femur_proscene_obj_interface.java:101)
at femur_proscene_obj_interface.c0(femur_proscene_obj_interface.java:297)
... 14 more
the code i'm working on is
- import remixlab.proscene.*;
- import java.util.HashMap;
- import controlP5.*;
- ControlP5 cp5;
- controlP5.Button c0,c1;
- Scene scene;
- ArrayList stems;
- int myColor;
- Stem s0;
- void setup() {
- size(800, 600, P3D);
- scene = new Scene(this);
- scene.setShortcut('f', Scene.KeyboardAction.DRAW_FRAME_SELECTION_HINT);
- cp5 = new ControlP5(this);
- createButtons();
- scene.setGridIsDrawn(true);
- scene.setCameraType(Camera.Type.ORTHOGRAPHIC);
- scene.setRadius(150);
- scene.showAll();
- s0 = new Stem();
- myColor = 130;
- stems = new ArrayList();
- addStem();
- }
- void draw() {
- background(0);
- drawScene();
- gui();
- }
- void addStem() {
- s0 = new Stem();
- stems.add(s0);
- }
- void drawScene() {
- // here goes your drawing code
- for (int j = 0; j <stems.size(); j++) {
- Stem s0 = (Stem) stems.get(j);
- s0.draw(true);
- }
- }
- void createButtons(){
- c0 = cp5.addButton("c0")
- .setValue(1)
- .setPosition(20, 20)
- .setSize(100, 30)
- .setId(1);
- c1 = cp5.addButton("c1")
- .setValue(2)
- .setPosition(20, 60)
- .setSize(100, 30)
- .setId(1);
- cp5.setAutoDraw(false);
- }
- void gui() {
- saveState();
- // (2)
- // load a new font. ControlFont is a wrapper for processing's PFont
- // with processing 1.1 ControlFont.setSmooth() is not supported anymore.
- // to display a font as smooth or non-smooth, use true/false as 3rd parameter
- // when creating a PFont:
- PFont pfont = createFont("Arial", 20, true); // use true/false for smooth/no-smooth
- ControlFont font = new ControlFont(pfont, 241);
- // (3)
- // change the font and content of the captionlabels
- // for both buttons create earlier.
- c0.captionLabel()
- .setFont(font)
- .setSize(20)
- .setText("add")
- ;
- c1.captionLabel()
- .setFont(font)
- .setSize(20)
- .setText("remove")
- ;
- // (4)
- // adjust the location of a catiption label using the
- // style property of a controller.
- c0.captionLabel()
- .getStyle()
- .marginLeft = 25;
- c1.captionLabel()
- .getStyle()
- .marginLeft = 3;
- cp5.draw();
- restoreState();
- }
- // properly hack to make it work
- void saveState() {
- // Set processing projection and modelview matrices to draw in 2D:
- // 1. projection matrix:
- float cameraZ = ((height/2.0f) / tan(PI*60.0f/360.0f));
- scene.pg3d.perspective(PI/3.0f, scene.camera().aspectRatio(), cameraZ/10.0f, cameraZ*10.0f);
- // 2 model view matrix
- scene.pg3d.camera();
- }
- void restoreState() {
- // 1. Restore processing projection matrix
- switch (scene.camera().type()) {
- case PERSPECTIVE:
- scene.pg3d.perspective(scene.camera().fieldOfView(), scene.camera().aspectRatio(), scene.camera().zNear(), scene.camera().zFar());
- break;
- case ORTHOGRAPHIC:
- float[] wh = scene.camera().getOrthoWidthHeight();
- scene.pg3d.ortho(-wh[0], wh[0], -wh[1], wh[1], scene.camera().zNear(), scene.camera().zFar());
- break;
- }
- // 2. Restore processing modelview matrix
- scene.pg3d.camera(scene.camera().position().x, scene.camera().position().y, scene.camera().position().z, scene.camera().at().x, scene.camera().at().y, scene.camera().at().z, scene.camera().upVector().x, scene.camera().upVector().y, scene.camera().upVector().z);
- }
- //functions for buttons
- void c0(int theValue) {
- println("a button event. "+theValue);
- addStem();
- }
- -------------------------------------------------------------------------------------------------------------------------
- public class Stem {
- InteractiveFrame iFrame;
- float w, h, d;
- int c;
- float px, py, pz;
- float rx, ry, rz;
- int col;
- Stem() {
- iFrame = new InteractiveFrame(scene);
- setSize();
- setColor();
- setPosition();
- col = color(255);
- }
- public void draw() {
- draw(false);
- }
- public void draw(boolean drawAxis) {
- pushMatrix();
- pushStyle();
- iFrame.applyTransformation(); //optimum
- if(drawAxis) scene.drawAxis(max(w,h,d)*1.3f);
- noStroke();
- if (iFrame.grabsMouse()){
- fill(255, 0, 0);
- }
- else {
- fill(getColor());
- }
- stroke(col);
- sphere(10);
- popMatrix();
- }
- // sets size randomly
- public void setSize() {
- w = random(10, 40);
- h = random(10, 40);
- d = random(10, 40);
- }
- public void setSize(float myW, float myH, float myD) {
- w=myW; h=myH; d=myD;
- }
- public int getColor() {
- return c;
- }
- // sets color randomly
- public void setColor() {
- c = color(random(0, 255), random(0, 255), random(0, 255));
- }
- public void setColor(int myC) {
- c = myC;
- }
- public PVector getPosition() {
- return iFrame.position();
- }
- // sets position randomly
- public void setPosition() {
- float low = -100;
- float high = 100;
- iFrame.setPosition(new PVector(random(low, high), random(low, high), random(low, high)));
- }
- public void setPosition(PVector pos) {
- iFrame.setPosition(pos);
- }
- public Quaternion getOrientation() {
- return iFrame.orientation();
- }
- public void setOrientation(PVector v) {
- PVector to = PVector.sub(v, iFrame.position());
- iFrame.setOrientation(new Quaternion(new PVector(0,1,0), to));
- }
- }
1