2019-01-07 22:32:13 +00:00
|
|
|
import ketai.sensors.*;
|
|
|
|
import processing.vr.*;
|
|
|
|
|
|
|
|
KetaiSensor sensor;
|
|
|
|
float fontSize = 130*displayDensity;
|
2019-01-13 20:45:04 +00:00
|
|
|
float rotationX, rotationY, rotationZ;
|
|
|
|
float roll, pitch, yaw;
|
|
|
|
PShape buddha;
|
|
|
|
PVector half = new PVector();
|
|
|
|
PMatrix3D baseMat;
|
2019-01-07 22:32:13 +00:00
|
|
|
|
|
|
|
void setup()
|
|
|
|
{
|
|
|
|
fullScreen(STEREO);
|
2019-01-13 20:45:04 +00:00
|
|
|
// size(displayWidth, displayHeight, P3D);
|
|
|
|
if(sensor == null){
|
|
|
|
sensor = new KetaiSensor(this);
|
|
|
|
sensor.start();
|
|
|
|
}
|
|
|
|
|
|
|
|
buddha = loadShape("buddha.obj");
|
|
|
|
buddha.setFill(0xffffffff);
|
|
|
|
buddha.setSpecular(0xfffff7d5);
|
2019-01-07 22:32:13 +00:00
|
|
|
|
|
|
|
textAlign(CENTER, CENTER);
|
|
|
|
textSize(fontSize);
|
|
|
|
|
2019-01-13 20:45:04 +00:00
|
|
|
half.set(width * .5, height * .5);
|
|
|
|
baseMat = getMatrix(baseMat);
|
2019-01-07 22:32:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void draw()
|
|
|
|
{
|
2019-01-13 20:45:04 +00:00
|
|
|
background(0xff000000);
|
2019-01-07 22:32:13 +00:00
|
|
|
|
2019-01-13 20:45:04 +00:00
|
|
|
pushMatrix();
|
2019-01-14 21:13:57 +00:00
|
|
|
scale(5);
|
|
|
|
translate(0.0, 0.0, -150.0);
|
2019-01-13 20:45:04 +00:00
|
|
|
lightSpecular(64, 64, 64);
|
2019-01-07 22:32:13 +00:00
|
|
|
|
2019-01-13 20:45:04 +00:00
|
|
|
// Horizonal light.
|
|
|
|
spotLight(255, 255, 255,
|
|
|
|
-half.x, 1, 0,
|
|
|
|
1, 0, 0,
|
|
|
|
PI, 10);
|
2019-01-07 22:32:13 +00:00
|
|
|
|
2019-01-13 20:45:04 +00:00
|
|
|
// // Vertical light.
|
|
|
|
spotLight(255, 255, 255,
|
|
|
|
1, -half.y, 0,
|
|
|
|
0, 1, 0,
|
|
|
|
PI, 10);
|
2019-01-07 22:32:13 +00:00
|
|
|
|
2019-01-13 20:45:04 +00:00
|
|
|
shape(buddha);
|
|
|
|
|
|
|
|
pitch += rotationX;
|
|
|
|
roll += rotationY;
|
|
|
|
yaw += rotationZ;
|
2019-01-07 22:32:13 +00:00
|
|
|
|
2019-01-13 20:45:04 +00:00
|
|
|
buddha.rotateX(pitch);
|
|
|
|
buddha.rotateY(-roll);
|
|
|
|
buddha.rotateZ(yaw);
|
2019-01-07 22:32:13 +00:00
|
|
|
|
2019-01-13 20:45:04 +00:00
|
|
|
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);
|
2019-01-07 22:32:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void onGyroscopeEvent(float x, float y, float z)
|
|
|
|
{
|
2019-01-13 20:45:04 +00:00
|
|
|
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;
|
|
|
|
}
|
2019-01-07 22:32:13 +00:00
|
|
|
|
2019-01-13 20:45:04 +00:00
|
|
|
void mousePressed()
|
|
|
|
{
|
|
|
|
pitch = roll = yaw = 0;
|
|
|
|
setup();
|
2019-01-07 22:32:13 +00:00
|
|
|
}
|