Hi,
I'm working on making a pair of eyes using a 3D renderer. And I made it so when the mouse is clicked, the eyes bulge out. Yet before the mouse is pressed the spheres are translated back 100. So I was able to draw ellipses on top of the spheres as pupils, yet how can I draw the pupils now that the sphere is bulging out in front of the spheres(whites)?
Code:
float x;
float y;
float x2;
float y2;
float easing = 0.07;
void setup(){
size(640, 480, P3D);
noStroke();
background(0);
//noCursor();
}
void draw(){
if(pmouseX != 0 && pmouseY != 0){
background(0);
//moving pupils
float targetX = mouseX;
float targetY = mouseY;
x += (targetX - x) * easing;
y += (targetY - y) * easing;
fill(0);
ellipse(x, y, 30, 30);
x = constrain(x, 175, 275);
y = constrain(y, 180, 300);
//other pupil
x2 += (targetX - x2) * easing;
y2 += (targetY - y2) * easing;
fill(0);
ellipse(x2, y2, 30, 30);
x2 = constrain(x2, 365, 470);
y2 = constrain(y2, 180, 300);
//whites
float dirY = (mouseY / float(height) - 0.5) * 2;
float dirX = (mouseX / float(width) - 0.5) * 2;
directionalLight(204, 204, 204, -dirX, -dirY, -1);
if(mousePressed && (mouseButton == LEFT)){
fill(255);
pushMatrix();
translate(430, 240, random(100, 110)); //bulge!
sphere(100); //65 w/o random
popMatrix();
pushMatrix();
translate(210, 260, random(40, 50));
sphere(100);
popMatrix();
//insert new constraints for ellipses
}else{
pushMatrix();
fill(255);
translate(210, 240, -100);
sphere(100); //value = radius
popMatrix();
fill(255);
translate(430, 240, -100);
sphere(100);
}
}
}