1
0
Fork 0

Add buddha model to VR Mode

This commit is contained in:
Simon Giesel 2019-01-13 21:45:04 +01:00
parent ce63a90345
commit 5727a328ea
3 changed files with 38767 additions and 83 deletions

View file

@ -13,7 +13,7 @@
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN"/> <action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/> <category android:name="android.intent.category.LAUNCHER"/>
<category android:name="com.google.intent.category.CARDBOARD"/> <category android:name="com.google.intent.category.DAYDREAM"/>
</intent-filter> </intent-filter>
</activity> </activity>
</application> </application>

View file

@ -3,105 +3,95 @@ import processing.vr.*;
KetaiSensor sensor; KetaiSensor sensor;
float fontSize = 130*displayDensity; float fontSize = 130*displayDensity;
float accelerometerX, accelerometerY, accelerometerZ, rotationX, rotationY, rotationZ; float rotationX, rotationY, rotationZ;
ArrayList<Integer> valuesAccelX = new ArrayList<Integer>(); float roll, pitch, yaw;
ArrayList<Integer> valuesAccelY = new ArrayList<Integer>(); PShape buddha;
ArrayList<Integer> valuesAccelZ = new ArrayList<Integer>(); PVector half = new PVector();
ArrayList<Integer> valuesRotX = new ArrayList<Integer>(); PMatrix3D baseMat;
ArrayList<Integer> valuesRotY = new ArrayList<Integer>();
ArrayList<Integer> valuesRotZ = new ArrayList<Integer>();
void setup() void setup()
{ {
fullScreen(STEREO);
// size(displayWidth, displayHeight, P3D);
if(sensor == null){
sensor = new KetaiSensor(this); sensor = new KetaiSensor(this);
sensor.start(); sensor.start();
}
fullScreen(STEREO); buddha = loadShape("buddha.obj");
buddha.setFill(0xffffffff);
buddha.setSpecular(0xfffff7d5);
textAlign(CENTER, CENTER); textAlign(CENTER, CENTER);
textSize(fontSize); textSize(fontSize);
strokeWeight(6); half.set(width * .5, height * .5);
smooth(); baseMat = getMatrix(baseMat);
} }
float mapNum;
void draw() void draw()
{ {
background(78, 93, 75); background(0xff000000);
drawGraph(valuesAccelX, height / 2 - fontSize * 4); pushMatrix();
drawGraph(valuesAccelY, height / 2 - fontSize * 3); // FIXME: Camera not setable in VR mode
drawGraph(valuesAccelZ, height / 2 - fontSize * 2); camera(0, 0, height,
drawGraph(valuesRotX, height / 2 + fontSize * 3); 0, 0, 0,
drawGraph(valuesRotY, height / 2 + fontSize * 4); 0, 1, 0);
drawGraph(valuesRotZ, height / 2 + fontSize * 5); scale(20);
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); fill(255);
text("Accelerometer:", 0, -fontSize*5.5, width, height); textSize(fontSize * .5);
mapNum = mapColor(accelerometerX); text(
fill(mapNum, 255-mapNum, 0); "pitch: " + nfp(pitch * 100, 1, 1) +
text("x: " + nfp(accelerometerX, 1, 3), 0, -fontSize*4, width, height); " | roll: " + nfp(roll * 100, 1, 1) +
mapNum = mapColor(accelerometerY); " | yaw: " + nfp(yaw * 100, 1, 1),
fill(mapNum, 255-mapNum, 0); 0, fontSize*7.5, width, height
text("y: " + nfp(accelerometerY, 1, 3), 0, -fontSize*3, width, height); );
mapNum = mapColor(accelerometerZ); text("Tap screen to reset orientation", 0, fontSize*8.1, width, height);
fill(mapNum, 255-mapNum, 0); textSize(fontSize);
text("z: " + nfp(accelerometerZ, 1, 3), 0, -fontSize*2, width, height); text("fps: " + round(frameRate), 0, fontSize*9, width, height);
fill(255);
text("Gyroscope:", 0, fontSize*1.5, width, height);
mapNum = mapColor(rotationX);
fill(mapNum, 255-mapNum, 0);
text("x: " + nfp(rotationX, 1, 3), 0, fontSize*3, width, height);
mapNum = mapColor(rotationY);
fill(mapNum, 255-mapNum, 0);
text("y: " + nfp(rotationY, 1, 3), 0, fontSize*4, width, height);
mapNum = mapColor(rotationZ);
fill(mapNum, 255-mapNum, 0);
text("z: " + nfp(rotationZ, 1, 3), 0, fontSize*5, width, height);
}
float mapColor(float in){
return map(in, -9.83, 9.83, 0, 255);
}
void drawGraph(ArrayList<Integer> values, float margin){
float lineWidth = (float) width / (values.size() - 1);
for (int i=0; i < values.size() - 1; i++) {
line(i * lineWidth, margin + values.get(i), (i + 1) * lineWidth, margin + values.get(i + 1));
}
}
void onAccelerometerEvent(float x, float y, float z)
{
valuesAccelX.add(int(x * 10));
while(valuesAccelX.size() > 10)
valuesAccelX.remove(0);
valuesAccelY.add(int(y * 10));
while(valuesAccelY.size() > 10)
valuesAccelY.remove(0);
valuesAccelZ.add(int(z * 10));
while(valuesAccelZ.size() > 10)
valuesAccelZ.remove(0);
accelerometerX = x;
accelerometerY = y;
accelerometerZ = z;
} }
void onGyroscopeEvent(float x, float y, float z) void onGyroscopeEvent(float x, float y, float z)
{ {
valuesRotX.add(int(x * 10)); rotationX = radians(x);
while(valuesRotX.size() > 10) if(round(rotationX) == 0) pitch = 0;
valuesRotX.remove(0); rotationY = radians(y);
valuesRotY.add(int(y * 10)); if(round(rotationY) == 0) roll = 0;
while(valuesRotY.size() > 10) rotationZ = radians(z);
valuesRotY.remove(0); if(round(rotationZ) == 0) yaw = 0;
valuesRotZ.add(int(z * 10)); }
while(valuesRotZ.size() > 10)
valuesRotZ.remove(0); void mousePressed()
{
rotationX = x; pitch = roll = yaw = 0;
rotationY = y; setup();
rotationZ = z;
} }

38694
data/buddha.obj Normal file

File diff suppressed because it is too large Load diff