import ketai.sensors.*; KetaiSensor sensor; float fontSize = 130*displayDensity; float rotationX, rotationY, rotationZ; float roll, pitch, yaw; PShape buddha; PVector half = new PVector(); PMatrix3D baseMat; void setup() { size(displayWidth, displayHeight, P3D); if(sensor == null){ sensor = new KetaiSensor(this); sensor.start(); } buddha = loadShape("buddha.obj"); buddha.setFill(0xffffffff); buddha.setSpecular(0xfffff7d5); textAlign(CENTER, CENTER); textSize(fontSize); half.set(width * .5, height * .5); baseMat = getMatrix(baseMat); } void draw() { background(0xff000000); pushMatrix(); scale(5); translate(0.0, 0.0, -150.0); lightSpecular(64, 64, 64); // Horizonal light. spotLight(255, 255, 255, -half.x, 1, 0, 1, 0, 0, PI, 10); // // Vertical light. spotLight(255, 255, 255, 1, -half.y, 0, 0, 1, 0, PI, 10); shape(buddha); pitch += rotationX; roll += rotationY; yaw += rotationZ; buddha.rotateX(pitch); buddha.rotateY(-roll); buddha.rotateZ(yaw); popMatrix(); this.setMatrix(baseMat); ambientLight(255, 255, 255); fill(255); textSize(fontSize * .5); text( "pitch: " + nfp(pitch * 100, 1, 1) + " | roll: " + nfp(roll * 100, 1, 1) + " | yaw: " + nfp(yaw * 100, 1, 1), 0, fontSize*7.5, width, height ); text("Tap screen to reset orientation", 0, fontSize*8.1, width, height); textSize(fontSize); text("fps: " + round(frameRate), 0, fontSize*9, width, height); } void onGyroscopeEvent(float x, float y, float z) { rotationX = radians(x); if(round(rotationX) == 0) pitch = 0; rotationY = radians(y); if(round(rotationY) == 0) roll = 0; rotationZ = radians(z); if(round(rotationZ) == 0) yaw = 0; } void mousePressed() { pitch = roll = yaw = 0; setup(); }