xxxxxxxxxx
40
// https://discourse.processing.org/t/3d-rotations-rotating-around-the-screen-axes/14239
function setup() {
createCanvas(windowWidth, windowHeight, WEBGL);
smooth();
noFill();
}
function windowResized() {
resizeCanvas(windowWidth, windowHeight, WEBGL);
}
function draw() {
background(255);
let x = map(mouseX, 0, width, -PI, PI);
let y = map(mouseY, 0, height, -PI, PI);
rotateY(x);
// rotateX(y);
rotate(-y, [cos(x), 0, sin(x)]);
axis();
ellipse(0, 0, height / 2, height / 2, 50);
rotateX(HALF_PI);
ellipse(0, 0, height / 2, height / 2, 50);
rotateY(HALF_PI);
ellipse(0, 0, height / 2, height / 2, 50);
}
function axis() {
push();
stroke(200, 0, 0);
line(0, 0, 0, 100, 0, 0);
stroke(0, 200, 0);
line(0, 0, 0, 0, 100, 0);
stroke(0, 0, 200);
line(0, 0, 0, 0, 0, 100);
pop();
}