I have a 3D box and I would like to show data on top of the picture, which are always on front and are not moving, when I move the box.
I found, that hint can be used to disable depth test for that but that just gives text, which turns with the box camera angle, instead of staying independent of it.
I can try to rotate the text in opposition to the camera angle. That looks good, but as soon as I hit the mouse button to turn the box, the text slightly bends in.
I am not sure, how to get to a text, which just stay’s on on top of the rest without moving.
Here the relevant code of the part that draws everything :
void draw(){
background(129,200,273);
lights();
translate(450,350,0);
rotateY(camangle);
noFill();
stroke(0);
box(boxsize);
for (int j=0; j < coil.length; j++){
for (int i = 1; i < coil[j].segments.length; i++){
PVector point0 = new PVector();
PVector point1 = new PVector();
point0 = coil[j].segments[i-1].location.copy();
point1= coil[j].segments[i].location.copy();
//check that segments are within box; while instead of if to cover cases with coordinates larger than boxsize/2
while (point0.x > boxsize/2){ point0.x -=boxsize; }
while (point0.x < -boxsize/2){ point0.x +=boxsize; }
while (point0.y > boxsize/2){ point0.y -=boxsize; }
while (point0.y < -boxsize/2){ point0.y +=boxsize; }
while (point0.z > boxsize/2){ point0.z -=boxsize; }
while (point0.z < -boxsize/2){ point0.z +=boxsize; }
while (point1.x > boxsize/2){ point1.x -=boxsize; }
while (point1.x < -boxsize/2){ point1.x +=boxsize; }
while (point1.y > boxsize/2){ point1.y -=boxsize; }
while (point1.y < -boxsize/2){ point1.y +=boxsize; }
while (point1.z > boxsize/2){ point1.z -=boxsize; }
while (point1.z < -boxsize/2){ point1.z +=boxsize; }
//check if points are on opposite ends of box, then no line is drawn, 2*sdistance to accommodate deviation
if (abs(point1.x - point0.x) < 2*sdistance && abs(point1.y - point0.y) < 2*sdistance && abs(point1.z - point0.z) < 2*sdistance*sdistance){
strokeWeight(5);
line(point0.x,point0.y, point0.z, point1.x, point1.y, point1.z);
strokeWeight(1);
}
}
}
if(mousePressed == true){
camangle += 0.1;
}
textSize(30);
//hint(DISABLE_DEPTH_TEST);
pushMatrix();
rotateY(-camangle);
text(coil[j].cRg, -boxsize+50+j*150, boxsize-200);
popMatrix();
//hint(ENABLE_DEPTH_TEST);
}
}