Quantcast
Channel: Processing Forum
Viewing all articles
Browse latest Browse all 1768

How to make sure 3D light does not affect UI text?

$
0
0
Hi everyone,

I am new to Processing and I was playing with 3D rendering in processing. I have a ball move around following the mouse. The scene is lit by a point light. I have some text on the screen that shows the position of the ball in the space. But the texts are affected by the point light as well. I was wondering is there a way to exclude the texts from the lighting?

Below is my code.

Thank you for your help in advance.

3d_ball.pde
------------------------------------------
Walk w1 = new Walk();
float mouseZ = 0.0;
PFont font;


void setup() {
  size(800, 320, OPENGL);
  smooth();
  
  noStroke();
  fill(255);

  font = createFont("SegoeWP", 14);
  textFont(font);
  textAlign(LEFT);
  
  //pointLight(255, 244, 178, width/2, height/2, 10);
}

void draw() {
  background(50);
  pointLight(255, 244, 178, width/2, height/2, 100);
  
  if(mousePressed) {
    mouseZ -= 1;
  } else {
    mouseZ = 0;
  }

  text("x: " + mouseX, 10, 20);
  text("y: " + mouseY, 10, 40);
  text("z: " + mouseZ, 10, 60);
  
  w1.update(mouseZ);
}
--------------------------------------------------

Walk.pde
---------------------------------------------------
class Walk {
  float x, y, z;
  float speedX, speedY, speedZ;
  
  Walk() {
    x = width/2;
    y = height/2;
    z = 0.0;
    
    speedX = 0.0;
    speedY = 0.0;
    speedZ = 0.0;
  }
  
  Walk(float x, float y) {
    x = width/2;
    y = height/2;
    z = 0.0;
    
    speedX = 0.0;
    speedY = 0.0;
    speedZ = 0.0;
  }
  
  void step(float mz) {
    float distanceX = mouseX - x;
    float distanceY = mouseY - y;
    float distanceZ = mz - z;
    
    speedX = distanceX/10;
    speedY = distanceY/10;
    speedZ = distanceZ/10;
    
    x += speedX;
    y += speedY;
    z += speedZ;
  }
  
  void update(float mz) {
    step(mz);
    pushMatrix();
    translate(x, y, z);
    sphere(20);
    popMatrix();
  }
}
--------------------------------------------

Viewing all articles
Browse latest Browse all 1768

Trending Articles