1
0
Fork 0
VMC_Processing_Step2/VMC_Processing_Step2.pde

95 lines
1.9 KiB
Text
Raw Normal View History

2019-01-07 15:30:48 +00:00
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;
2019-01-07 15:30:48 +00:00
void setup()
{
size(displayWidth, displayHeight, P3D);
if(sensor == null){
sensor = new KetaiSensor(this);
sensor.start();
}
2019-01-07 15:30:48 +00:00
buddha = loadShape("buddha.obj");
buddha.setFill(0xffffffff);
buddha.setSpecular(0xfffff7d5);
2019-01-07 15:30:48 +00:00
textAlign(CENTER, CENTER);
textSize(fontSize);
half.set(width * .5, height * .5);
baseMat = getMatrix(baseMat);
2019-01-07 15:30:48 +00:00
}
void draw()
{
background(0xff000000);
2019-01-07 15:30:48 +00:00
pushMatrix();
camera(0, 0, height,
0, 0, 0,
0, 1, 0);
scale(20);
lightSpecular(64, 64, 64);
2019-01-07 15:30:48 +00:00
// Horizonal light.
spotLight(255, 255, 255,
-half.x, 1, 0,
1, 0, 0,
PI, 10);
2019-01-07 15:30:48 +00:00
// // Vertical light.
spotLight(255, 255, 255,
1, -half.y, 0,
0, 1, 0,
PI, 10);
2019-01-07 15:30:48 +00:00
shape(buddha);
pitch += rotationX;
roll += rotationY;
yaw += rotationZ;
2019-01-07 15:30:48 +00:00
buddha.rotateX(pitch);
buddha.rotateY(-roll);
buddha.rotateZ(yaw);
popMatrix();
this.setMatrix(baseMat);
ambientLight(255, 255, 255);
2019-01-07 15:30:48 +00:00
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 15:30:48 +00:00
}
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;
}
2019-01-07 15:30:48 +00:00
void mousePressed()
{
pitch = roll = yaw = 0;
setup();
2019-01-07 15:30:48 +00:00
}