We are about to switch to a new forum software. Until then we have removed the registration on this forum.
hello all,
simple question, but I couldn't find anything about it.
I want to do a Picking with 3D boxes.
I don't want to use the shapes lib.
All boxes have different colors, So I just wanted to take the color via get(mouseX, mouseY), bu I realized that doesn't work since I use lights().
Then I decided to draw everything in a second PGraphics and do the get(mouseX, mouseY) there - but since I use peasyCam, the boxes on the screen and in PGraphics don't match. So it doesn't work.
So my question here is: How can I do a picking without lib but with lights() and peasyCam in use?
Or in other words: How can I impose peasyCam on my PGraphics?
(or can I use modelX etc. and use it to paint my boxes in my PGraphics?)
Thank you all!
Greetings, Chrisir ;-)
part of my class:
void display() {
noStroke();
stroke(0);
fill(boxFillColor);
if (selected) { // only outline
noFill();
strokeWeight(2);
stroke(boxFillColor);
}
if (allNoFill) { // only outline
noFill();
strokeWeight(2);
stroke(boxFillColor);
}
//pg.beginDraw();
pg.pushMatrix();
pg.fill(boxFillColor);
pg.noStroke();
pg.translate (Position.x, Position.y, Position.z);
pg.box ( boxSize.x );
pg.popMatrix();
// pg.endDraw();
// the box
pushMatrix();
translate (Position.x, Position.y, Position.z);
box ( boxSize.x );
popMatrix();
}
Answers
The answer is to copy the drawing matrix from the visible surface to the buffer then switch off lights etc before drawing to the buffer. This can be seen in the Shape3D class pickShape method (line 169)
@ quark: would that work also with peasyCam?
I think so but I am not in a position to test it at the moment. I suggest you install the Shapes3D library and modify the shape picking example (remove the rotation code) and add PeasyCam.
If the pickShape method works then there's your answer :)
Test the pickShape method from draw() if that doesn't work try it from the mouseReleased() method.
ok, thanks a lot!
;-)
Its a pain, doesn't work at all....
how can I impose the peasyCam values on the PGraphicsOpenGL var please?
There are no comments in the code below but it should make sense. Each cube has two colours the display colour and the pick colour. This allows you to change the display colour without affecting the picking process and also means cubes with the same display colour can be distinguished.
HTH
hi dear quark,
thanks a ton. I'll try tonight.
Thank you very much!
Chrisir
it works now, I had a stupid mistake somewhere else...
took me all night
thanks a ton!