Skip to content

Commit 7b1143e

Browse files
committed
ported ray casting examples from p5.xr
1 parent 5975c3c commit 7b1143e

File tree

8 files changed

+148
-0
lines changed

8 files changed

+148
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import processing.vr.*;
2+
3+
float[] randomx = new float[5];
4+
float[] randomy = new float[5];
5+
VRCamera cam;
6+
7+
void setup() {
8+
fullScreen(VR);
9+
cameraUp();
10+
cam = new VRCamera(this);
11+
12+
for (int i = 0; i < 5; ++i) {
13+
randomx[i] = random(-500, 500);
14+
randomy[i] = random(-500, 500);
15+
}
16+
}
17+
18+
void draw() {
19+
backgroundColor(200, 0, 150);
20+
21+
cam.setPosition(0, 0, 400);
22+
push();
23+
translate(randomx[0], randomy[0]);
24+
fill(0, 255, 0);
25+
sphere(30);
26+
rotateZ(millis() / 1000);
27+
line(0, 0, 0, 1000, 1000, 0);
28+
PVector[] ray = generateRay(0, 0, 0, 1000, 1000, 0);
29+
30+
pop();
31+
for (int i = 1; i < 5; ++i) {
32+
push();
33+
translate(randomx[i], randomy[i]);
34+
fill(255, 0, 0);
35+
if (intersectsSphere(70, ray)) {
36+
fill(0, 0, 255);
37+
}
38+
sphere(70);
39+
pop();
40+
}
41+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
mode=Android
2+
component=vr
3+
mode.id=processing.mode.android.AndroidMode
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import processing.vr.*;
2+
3+
VRCamera cam;
4+
float rotSpeed = 0.3;
5+
float rotAngle = 0;
6+
7+
void setup() {
8+
fullScreen(VR);
9+
cameraUp();
10+
VRCamera cam;
11+
}
12+
13+
void draw() {
14+
backgroundColor(200, 0, 150);
15+
16+
cam.setPosition(0, 0, 200);
17+
push();
18+
angleMode(DEGREES);
19+
rotateZ(rotAngle);
20+
translate(100, 0, 0);
21+
fill(255, 0, 0);
22+
if (intersectsBox(50)) {
23+
rotAngle += rotSpeed;
24+
fill(0, 0, 255);
25+
}
26+
box(50);
27+
pop();
28+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
mode=Android
2+
component=vr
3+
mode.id=processing.mode.android.AndroidMode
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import processing.vr.*;
2+
3+
VRCamera cam;
4+
float x, y;
5+
6+
void setup() {
7+
fullScreen(VR);
8+
cameraUp();
9+
VRCamera cam;
10+
}
11+
12+
void draw() {
13+
backgroundColor(200, 0, 150);
14+
15+
cam.setPosition(0, 0, 400);
16+
fill(255,170,238);
17+
// plane(400, 400);
18+
fill(255, 0, 0);
19+
translate(x, y, 0);
20+
PVector offset;
21+
if (intersectsBox(60)) {
22+
translate(-x, -y, 0);
23+
fill(0, 0, 255);
24+
offset = intersectsPlane(0, 0);
25+
x = offset.x;
26+
y = offset.y;
27+
}
28+
translate(x, y, 0);
29+
box(60);
30+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
mode=Android
2+
component=vr
3+
mode.id=processing.mode.android.AndroidMode
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import processing.vr.*;
2+
3+
float[] randomx = new float[5];
4+
float[] randomy = new float[5];
5+
VRCamera cam;
6+
7+
void setup() {
8+
fullScreen(VR);
9+
cameraUp();
10+
cam = new VRCamera(this);
11+
12+
for (int i = 0; i < 5; ++i) {
13+
randomx[i] = random(-500, 500);
14+
randomy[i] = random(-500, 500);
15+
}
16+
}
17+
18+
void draw() {
19+
backgroundColor(200, 0, 150);
20+
21+
cam.setPosition(0, 0, 400);
22+
for (int i = 0; i < 5; ++i) {
23+
push();
24+
translate(randomx[i], randomy[i]);
25+
fill(255, 0, 0);
26+
if (intersectsSphere(70, 0, 0)) {
27+
fill(0, 0, 255);
28+
}
29+
sphere(70);
30+
// noLoop();
31+
pop();
32+
}
33+
cam.sticky();
34+
circle(windowWidth/2, windowHeight/2, 25);
35+
// image(pg, -windowWidth/2, -windowHeight/2, windowWidth, windowHeight);
36+
cam.noSticky();
37+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
mode=Android
2+
component=vr
3+
mode.id=processing.mode.android.AndroidMode

0 commit comments

Comments
 (0)