Picking in PGraphics
              in 
             Contributed Library Questions 
              •  
              1 year ago    
            
 
           
             Hello. 
            
             
            
            
             
              
             
             
              
               
              
              
               
              
              
               
              
              
               
              
              
                 
              
              
               
              
              
             
              
             
             
              
             
             
              
             
             
              
             
             
              
             
             
              
             
             
              
             
             
              
             
             
              
             
             
              
               
              
              
               
              
              
               
              
              
               
              
              
                 
              
              
                 
              
              
               
              
              
             
              
             
             
              
             
              
           
 
            
           
              I'm trying to use the picking library, but I have a problem and I don't know how to solve it.
             
             
              I have this code that works correctly:
             
             
               import picking.*;
              
              
               Picker picker;
              
              
               void setup() 
              
              
               {
              
              
                 size(500, 500, P3D);
              
              
                 picker = new Picker(this);
              
              
               }
              
              
               void draw()
              
              
               {
              
              
                 camera(-20, -20, 50, 0, 0, 0, 0, 1, 0);
              
              
                 rotateY(10); 
              
              
                 background(255);
              
              
                 lights();
              
              
                 picker.start(1);
              
              
                 fill(32,64,128);
              
              
                 box(10,10,10);
              
              
                 picker.start(2);
              
              
                 translate(20,0,0);
              
              
                 fill(255,0,0);
              
              
                 box(10,10,10);
              
              
               }
              
              
               void mouseClicked() 
              
              
               {
              
              
                 int id = picker.get(mouseX, mouseY);
              
              
                 println(id);
              
              
               }
              
             
              But in my program 
              I need to draw in a PGraphics object. Then the picking doesn't work.
             
             
              How could I fix this???
             
             
              This code doesn't work
             
             
               import picking.*;
              
              
               Picker picker;
              
              
               PGraphics render;
              
              
               void setup() 
              
              
               {
              
              
                 size(500, 500, P3D);
              
              
                 render = createGraphics(500,500,P3D);
              
              
                 picker = new Picker(this);
              
              
               }
              
              
               void draw()
              
              
               {
              
              
                 render.beginDraw();
              
              
                 render.camera(-20, -20, 50, 0, 0, 0, 0, 1, 0);
              
              
                 render.rotateY(10); 
              
              
                 render.background(255);
              
              
                 render.lights();
              
              
                 picker.start(1);
              
              
                 render.fill(32,64,128);
              
              
                 render.box(10,10,10);
              
              
                 picker.start(2);
              
              
                 render.translate(20,0,0);
              
              
                 render.fill(255,0,0);
              
              
                 render.box(10,10,10);
              
              
                 render.endDraw();
              
              
                 image(render,0,0);
              
              
               }
              
              
               void mouseClicked() 
              
              
               {
              
              
                 int id = picker.get(mouseX, mouseY);
              
              
                 println(id);
              
              
               }
              
             
              Best regards and thanks in advance
             
             
              
              1  
            
 
            