I’m plotting some datapoints in 3D, I would like to display a textbox (with text in it) on mouseover. Do you have any suggestions on how to start? Do you know of any examples, libraries, or code I could use as a template?
Hi,
I think that what you are looking for is discussed on this previous thread :
https://forum.processing.org/one/topic/2d-coordinates-from-3d-coordinates.html
You can use the screenX()
and screenY()
functions to get the 2D window coordinates of a 3d point in space.
Then you should be able to check on which point the mouse is over and draw the appropriate information.
Hope it helps!
1 Like
When those are in a class you can make a new xs,ys in the class and fill it from screenX(), screenY() and (to see if we have a mouse over) compare the mouseX, mouseY using:
if(dist(mouseX,mouseY, xs,ys)> 33) ....
Sketch
// the floor
ArrayList<Plate> plates = new ArrayList();
// -------------------------------------------------------------------------------------
void setup() {
size( 1200, 900, P3D );
//text
textMode(SHAPE);
Plate np=new Plate();
np.pos=new PVector(65, 112, 33);
plates.add(np) ;
np=new Plate();
np.pos=new PVector(265, 212, -233);
plates.add(np) ;
np=new Plate();
np.pos=new PVector(665, 112, -233);
plates.add(np) ;
}
void draw() {
background(0);
lights();
// plates
for (Plate currentPlate : plates) {
currentPlate.display();
}//for
}
//==================================================================
class Plate {
// one cube
PVector pos;
float xs, ys;
void display() {
// show rect/plate
pushMatrix();
fill(255, 2, 2);
stroke(0);
translate(pos.x, pos.y, pos.z);
box ( 20, 21, 20);
xs=screenX(0, 0, 0);
ys=screenY(0, 0, 0);
if (dist(mouseX, mouseY, xs, ys) < 33) {
// prepare for 2D
hint(DISABLE_DEPTH_TEST);
camera();
noLights();
// 2D code
fill(255);
text("2e", xs+22, ys);
// reset for 3D again
hint(ENABLE_DEPTH_TEST);
lights();
}
popMatrix();
}
//
}//class
//
1 Like
This worked great for me, thanks!
2 Likes