hello All,
as far as I can see (perhaps I'm not getting this right) the solution provided by Jean Pierre does not work when you tring to use interactive frames and drag objects around. The camera works but the interactive frames goes back to the "originalMatrix" (basically at time 0) detaching from the objects.
In fact if you try to select the boxes it won't to anything but if you over in the left corner (original position of the boxes) the frames will display in green (not really easy to see)
I attach there the code although which is literally indentical to the one given by Jean Pierre apart from the fact that there is a box class to draw multiple boxes (taken from the examples)
- /**
- * ControlP5 with Proscene support
- */
- import remixlab.proscene.*;
- import controlP5.*;
- import processing.opengl.*;
- Scene scene;
- ControlP5 controlP5;
- PMatrix3D currCameraMatrix;
- PGraphics buffer;
- PGraphics3D g3;
- int buttonValue = 1;
- Box [] boxes;
- public PMatrix3D originalMatrix;
- void setup()
- {
- size(800, 800, OPENGL);
- smooth();
- stroke(0);
- strokeWeight(2);
- scene = new Scene(this);
- scene.setRadius(150);
- scene.showAll();
- scene.setGridIsDrawn(false);
- scene.setAxisIsDrawn(false);
- scene.setShortcut('f', Scene.KeyboardAction.DRAW_FRAME_SELECTION_HINT);
- g3 = (PGraphics3D)g;
- boxes = new Box[5];
- for (int i = 0; i < boxes.length; i++)
- {
- boxes[i] = new Box(i);
- }
- controlP5 = new ControlP5(this);
- controlP5.addButton("button", 10, 100, 60, 80, 20).setId(1);
- controlP5.addButton("buttonValue", 4, 100, 90, 80, 20).setId(2);
- controlP5.setAutoDraw(false);
- //originalMatrix = getMatrix((PMatrix3D)null);
- }
- void draw()
- {
- background(255);
- stroke(0);
- strokeWeight(2);
-
- for (int i = 0; i < boxes.length; i++)
- {
- boxes[i].draw();
- }
- gui();
- }
- void gui()
- {
- //currCameraMatrix=scene.renderer().camera;
- //currCameraMatrix=scene.getModelViewMatrix(currCameraMatrix);
- currCameraMatrix = new PMatrix3D(g3.camera);
- //Disable depth test to draw 2d on top
- hint(DISABLE_DEPTH_TEST);
- //Since proscene handles the projection in a slightly different manner
- //we set the camera to Processing default values before calling camera():
- float cameraZ = ((height/2.0) / tan(PI*60.0/360.0));
- perspective(PI/3.0, scene.camera().aspectRatio(), cameraZ/10.0, cameraZ*10.0);
- camera();
- controlP5.draw();
- //Re-enble depth test
- hint(ENABLE_DEPTH_TEST);
- g3.camera = currCameraMatrix;
- //g3.applyMatrix(currCameraMatrix);
- }
- void controlEvent(ControlEvent theEvent) {
- println(theEvent.controller().id());
- }
- void button(float theValue) {
- println("a button event. "+theValue);
- }
- public class Box {
- InteractiveFrame iFrame;
- float w, h, d;
- int c;
- int ID;
- Box(int ID)
- {
- iFrame = new InteractiveFrame(scene);
- setSize();
- setColor();
- this.ID=ID;
- setPosition();
-
- }
-
- // don't draw local axis
- public void draw() {
- draw(false);
- }
- public void draw(boolean drawAxis)
- {
- //setPosition();
- pushMatrix();
- pushStyle();
- // Multiply matrix to get in the frame coordinate system.
- // scene.parent.applyMatrix(iFrame.matrix()) is handy but inefficient
- iFrame.applyTransformation(); //optimum
- if(drawAxis) scene.drawAxis(max(w,h,d)*1.3f);
- //noStroke();
- if (iFrame.grabsMouse())
- fill(255, 0, 0);
- else
- fill(getColor());
- //Draw a box
- box(w,h,d);
- popStyle();
- 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)));
- //iFrame.setPosition(new PVector(50*ID, 0, 0));
- }
-
- public void setPosition(PVector pos) {
- iFrame.setPosition(pos);
- }
- }
any idea on this ? I'd appreciate your help