Skip to content

Commit

Permalink
Add CameraTextureOnCube example
Browse files Browse the repository at this point in the history
Signed-off-by: Umair Khan <[email protected]>
  • Loading branch information
omerjerk committed Aug 15, 2015
1 parent 866aaf1 commit ac78aaf
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 0 deletions.
1 change: 1 addition & 0 deletions examples/Capture/CameraTextureOnCube/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package=""><uses-sdk android:minSdkVersion="22"/><application android:debuggable="true" android:icon="@drawable/icon" android:label=""><activity android:name=".MainActivity">android:theme="@android:style/Theme.NoTitleBar"&gt;<intent-filter><action android:name="android.intent.action.MAIN"/><category android:name="android.intent.category.LAUNCHER"/></intent-filter></activity></application><uses-permission android:name="android.permission.CAMERA"/></manifest>
85 changes: 85 additions & 0 deletions examples/Capture/CameraTextureOnCube/CameraTextureOnCube.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import in.omerjerk.processing.video.android.*;

Capture cameraTex;
float rotx = PI/4;
float roty = PI/4;

void setup() {
fullScreen(P3D);

String[] cameras = Capture.list();
cameraTex = new Capture(this, cameras[0]);
cameraTex.start();
textureMode(NORMAL);
fill(255);
stroke(color(44,48,32));
}

void draw() {
cameraTex.read();
background(255);
noStroke();
translate(width/2.0, height/2.0, -100);
rotateX(rotx);
rotateY(roty);
scale(230);
TexturedCube(cameraTex);
}

void TexturedCube(PImage tex) {
beginShape(QUADS);
texture(tex);

// Given one texture and six faces, we can easily set up the uv coordinates
// such that four of the faces tile "perfectly" along either u or v, but the other
// two faces cannot be so aligned. This code tiles "along" u, "around" the X/Z faces
// and fudges the Y faces - the Y faces are arbitrarily aligned such that a
// rotation along the X axis will put the "top" of either texture at the "top"
// of the screen, but is not otherwised aligned with the X/Z faces. (This
// just affects what type of symmetry is required if you need seamless
// tiling all the way around the cube)

// +Z "front" face
vertex(-1, -1, 1, 0, 0);
vertex( 1, -1, 1, 1, 0);
vertex( 1, 1, 1, 1, 1);
vertex(-1, 1, 1, 0, 1);

// -Z "back" face
vertex( 1, -1, -1, 0, 0);
vertex(-1, -1, -1, 1, 0);
vertex(-1, 1, -1, 1, 1);
vertex( 1, 1, -1, 0, 1);

// +Y "bottom" face
vertex(-1, 1, 1, 0, 0);
vertex( 1, 1, 1, 1, 0);
vertex( 1, 1, -1, 1, 1);
vertex(-1, 1, -1, 0, 1);

// -Y "top" face
vertex(-1, -1, -1, 0, 0);
vertex( 1, -1, -1, 1, 0);
vertex( 1, -1, 1, 1, 1);
vertex(-1, -1, 1, 0, 1);

// +X "right" face
vertex( 1, -1, 1, 0, 0);
vertex( 1, -1, -1, 1, 0);
vertex( 1, 1, -1, 1, 1);
vertex( 1, 1, 1, 0, 1);

// -X "left" face
vertex(-1, -1, -1, 0, 0);
vertex(-1, -1, 1, 1, 0);
vertex(-1, 1, 1, 1, 1);
vertex(-1, 1, -1, 0, 1);

endShape();
}

void mouseDragged() {
float rate = 0.01;
rotx += (pmouseY-mouseY) * rate;
roty += (mouseX-pmouseX) * rate;
}
2 changes: 2 additions & 0 deletions examples/Capture/CameraTextureOnCube/sketch.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mode=Android
mode.id=processing.mode.android.AndroidMode

0 comments on commit ac78aaf

Please sign in to comment.