Skip to content

Commit ac78aaf

Browse files
committed
Add CameraTextureOnCube example
Signed-off-by: Umair Khan <[email protected]>
1 parent 866aaf1 commit ac78aaf

File tree

3 files changed

+88
-0
lines changed

3 files changed

+88
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import in.omerjerk.processing.video.android.*;
2+
3+
Capture cameraTex;
4+
float rotx = PI/4;
5+
float roty = PI/4;
6+
7+
void setup() {
8+
fullScreen(P3D);
9+
10+
String[] cameras = Capture.list();
11+
cameraTex = new Capture(this, cameras[0]);
12+
cameraTex.start();
13+
textureMode(NORMAL);
14+
fill(255);
15+
stroke(color(44,48,32));
16+
}
17+
18+
void draw() {
19+
cameraTex.read();
20+
background(255);
21+
noStroke();
22+
translate(width/2.0, height/2.0, -100);
23+
rotateX(rotx);
24+
rotateY(roty);
25+
scale(230);
26+
TexturedCube(cameraTex);
27+
}
28+
29+
void TexturedCube(PImage tex) {
30+
beginShape(QUADS);
31+
texture(tex);
32+
33+
// Given one texture and six faces, we can easily set up the uv coordinates
34+
// such that four of the faces tile "perfectly" along either u or v, but the other
35+
// two faces cannot be so aligned. This code tiles "along" u, "around" the X/Z faces
36+
// and fudges the Y faces - the Y faces are arbitrarily aligned such that a
37+
// rotation along the X axis will put the "top" of either texture at the "top"
38+
// of the screen, but is not otherwised aligned with the X/Z faces. (This
39+
// just affects what type of symmetry is required if you need seamless
40+
// tiling all the way around the cube)
41+
42+
// +Z "front" face
43+
vertex(-1, -1, 1, 0, 0);
44+
vertex( 1, -1, 1, 1, 0);
45+
vertex( 1, 1, 1, 1, 1);
46+
vertex(-1, 1, 1, 0, 1);
47+
48+
// -Z "back" face
49+
vertex( 1, -1, -1, 0, 0);
50+
vertex(-1, -1, -1, 1, 0);
51+
vertex(-1, 1, -1, 1, 1);
52+
vertex( 1, 1, -1, 0, 1);
53+
54+
// +Y "bottom" face
55+
vertex(-1, 1, 1, 0, 0);
56+
vertex( 1, 1, 1, 1, 0);
57+
vertex( 1, 1, -1, 1, 1);
58+
vertex(-1, 1, -1, 0, 1);
59+
60+
// -Y "top" face
61+
vertex(-1, -1, -1, 0, 0);
62+
vertex( 1, -1, -1, 1, 0);
63+
vertex( 1, -1, 1, 1, 1);
64+
vertex(-1, -1, 1, 0, 1);
65+
66+
// +X "right" face
67+
vertex( 1, -1, 1, 0, 0);
68+
vertex( 1, -1, -1, 1, 0);
69+
vertex( 1, 1, -1, 1, 1);
70+
vertex( 1, 1, 1, 0, 1);
71+
72+
// -X "left" face
73+
vertex(-1, -1, -1, 0, 0);
74+
vertex(-1, -1, 1, 1, 0);
75+
vertex(-1, 1, 1, 1, 1);
76+
vertex(-1, 1, -1, 0, 1);
77+
78+
endShape();
79+
}
80+
81+
void mouseDragged() {
82+
float rate = 0.01;
83+
rotx += (pmouseY-mouseY) * rate;
84+
roty += (mouseX-pmouseX) * rate;
85+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
mode=Android
2+
mode.id=processing.mode.android.AndroidMode

0 commit comments

Comments
 (0)