Text that is not affected by rotations

I am writing a piece of code that draws 3D objects onto the canvas using P3D render.
I have coded it such that one can rotate the camera and pan and zoom, etc.

I want to write some info text onto the screen, but when I move the camera, the text moves as though it were a real object getting displayed; I want the text to move with the camera, so as to stay in the same place (relative to the screen, not the objects).

Is there a function or way to stop the text being an object?
This is not a bug, just a limit if mu knowledge :)
Thanks!

if you have installed the library
PeasyCam 302 Jonathan Feinberg
can use example
HeadUpDisplay
like:

import peasy.PeasyCam;

PeasyCam cam;

public void setup() {
  size(800, 600, P3D);
  cam = new PeasyCam(this, 400);
}

public void draw() {
  myView();
  myHUD();
}

void myView() {
  rotateX(-.5f);
  rotateY(-.5f);
  lights();
  scale(10);
  strokeWeight(1 / 10f);
  background(0);
  fill(96, 255, 0);
  box(30);
  pushMatrix();
  translate(0, 0, 17.5);
  fill(0, 96, 255);
  box(5);
  popMatrix();
}

void myHUD() {
  cam.beginHUD();
  fill(0, 128);
  rect(0, 0, 70, 30);
  fill(255);
  text(nfc(frameRate, 2)+" FPS", 10, 18);
  cam.endHUD();
}

Hello,

This is an example that rotates the text back with the movement of the camera.
It will require more work if adding additional rotations along the other axis.

float rotation = 0;
float theta = 0;

void setup() 
  {
  size(500, 500, P3D);
  background(255);
  textSize(48);
  hint(ENABLE_DEPTH_SORT); //Comment this to see what it does!
  }

void draw() 
  {
  background(0);
  lights();
  
  pushMatrix();
  float radius = 250;
  float ypos = 0;
  float xpos = cos(theta)*radius;
  float zpos = sin(theta)*radius; 
  camera(xpos, ypos, zpos, 0, 0, 0, 0, 1, 0);

  translate(0, -50, 0);
  fill(128);
  noStroke();
  float s = 1.5;
  box(s*90, s*40, s*10);
  
  fill(255);
  textAlign(CENTER);
  textSize(48);
  text("Monolith", 0, 100, 0);
  
  pushMatrix();
  rotateY(TAU/4);
  pushMatrix();
  rotateY(-theta);
  textSize(48);
  text("Monolith", 0, 100, 0);
  popMatrix();
  popMatrix();
  
  theta += TAU/500;
  popMatrix();
  }

I used hint(ENABLE_DEPTH_SORT) so the text would overlap nicely.

I rotated text back in this example:

:slight_smile:

Specifically Peasycam has a HUD

it’s

cam.beginHUD();

Then your text buttons etc

Then

cam.endHUD();

http://mrfeinberg.com/peasycam/

Another method is:

void draw() {
  pushMatrix();
  // 3d camera here
  // 3d draw here
  popMatrix();
  text("foo", x, y);
}

Another approach is to render your text onto a PGraphics pg, then composite it with image(pg, 0, 0) at the end of draw. Note that it can be a 2D even if the main sketch is P3D – this can give you better baseline text quality.