here is my version
- sphere not pointing on the mouse but rotating nicely with mouse
- a nicer sphere with a nose
- using
lights()
command which is always nice in 3D
- using sphere with noStroke so that it doesn’t have the ugly grid but looks smooth (the
lights()
do this by the way)
void setup()
{
size(600, 600, P3D);
sphereDetail(30); // standard
}
void draw()
{
background(255);
lights();
pushMatrix();
translate(width/2, height/2);
rotateX(radians(map(mouseY, height, 0, 0, height)));
rotateY(radians(mouseX));
// sphere with nose
drawSphereWithNose();
popMatrix();
}
void drawSphereWithNose()
{
// sphere
noStroke();
fill(246, 225, 65);// yellow
sphere(40);
// red nose
translate (45, 0, 0);
fill(255, 0, 0); // red
stroke(0);
box(10);
}
//
New version
New version that looks at the mouse
final float degrees90 = 90;
void setup()
{
size(600, 600, P3D);
sphereDetail(30); // standard
}
void draw()
{
background(255);
lights();
pushMatrix();
translate(width/2, height/2);
rotateX(radians(map(mouseY, height, 0, -degrees90, degrees90)));
rotateY(radians(map(mouseX, 0, width, -degrees90-90, degrees90-90)));
// sphere with nose
drawSphereWithNose();
popMatrix();
}
void drawSphereWithNose()
{
// sphere
noStroke();
fill(246, 225, 65);// yellow
sphere(40);
// red nose
translate (45, 0, 0);
fill(255, 0, 0); // red
stroke(0);
box(10);
}
//
Version 3
void setup()
{
size(600, 600, P3D);
sphereDetail(30); // standard
}
void draw()
{
background(255);
lights();
pushMatrix();
translate(width/2, height/2);
float angleFromMouseY = tan(map(mouseY, 0, height, 1, -1));
rotateX(angleFromMouseY);
float angleFromMouseX = tan(map(mouseX, 0, width, -1, 1));
rotateY(angleFromMouseX-(TWO_PI/4.0));
// sphere with nose
drawSphereWithNose();
popMatrix();
}
void drawSphereWithNose() {
// sphere
noStroke();
fill(246, 225, 65);// yellow
sphere(40);
// red nose
translate (45, 0, 0);
fill(255, 0, 0); // red
stroke(0);
box(10);
}
//