Using controlP5, peasycam, and a PGraphics buffer; any thoughts on how to do so?
in
Contributed Library Questions
•
2 years ago
So what I am trying to do is draw into a P3D buffer off screen while the applet is set for P2D. I am able to use this set up to get the text to work right on the labels in controlP5 and then write the buffer to the graphics context to get the 3d drawings I am doing. The issue comes when I want to also rotate the 3d graphics using peasycam. Anyone have any thoughts or has maybe done it before?
here is an example program, it displays how controlP5 can be used with 3D but the camera will not work.
- import controlP5.*;
- import peasy.*;
- // global vars.
- ControlP5 controlP5;
- PeasyCam cam;
- PGraphics3D g3;
- PMatrix3D currCamMatrix;
- PGraphics buffer;
- float rot;
- void setup()
- {
- size(400, 400, P2D);
- cam = new PeasyCam(this, 400);
- buffer = createGraphics(width, height, P3D);
- rot = 0.0;
- controlP5 = new ControlP5(this);
- controlP5.setAutoDraw(false);
- ListBox l = controlP5.addListBox("GUI", 5, 30, 100, height-20);
- l.setLabel("Test controlP5");
- // g3 = (PGraphics3D)cam.g;
- }
- void draw()
- {
- background(0);
- // draw the cube.
- drawCube();
- // refresh the screen with what is
- // in the buffer.
- refresh();
- // draw the "GUI"
- drawGUI();
- }
- void drawCube()
- {
- buffer.beginDraw();
- buffer.pushMatrix();
- buffer.background(150);
- buffer.colorMode(HSB);
- buffer.fill(#66FFFF);
- buffer.stroke(#FF3070);
- buffer.translate(200, 200);
- buffer.rotateY(rot+=.005);
- buffer.box(100);
- buffer.popMatrix();
- buffer.endDraw();
- }
- void refresh()
- {
- image(buffer, 0, 0);
- }
- void drawGUI()
- {
- // currCamMatrix = new PMatrix3D(cam.g.camera);
- // camera();
- controlP5.draw();
- // buffer.setMatrix();
- }
1