Skip to content

Commit 2190572

Browse files
committed
added getRenderer, vrCoordinates, registerUpdate
1 parent 5792609 commit 2190572

File tree

4 files changed

+53
-13
lines changed

4 files changed

+53
-13
lines changed

libraries/vr/examples/drawAim/drawAim.pde

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
11
import processing.vr.*;
22

3+
PGraphicsVR pg;
34

45
void setup() {
5-
fullScreen(PVR.STEREO);
6+
fullScreen(PVR.STEREO);
7+
pg = PVR.getRenderer(this);
8+
pg.registerUpdate();
9+
}
10+
11+
void update() {
12+
println("in update function");
613
}
714

815
void draw() {
916
background(150);
10-
PGraphicsVR pvr = (PGraphicsVR)g;
11-
17+
18+
println("in draw function for eye " + pg.eyeType);
19+
1220
// Some lights
13-
pointLight(255, 255, 255, pvr.cameraX, pvr.cameraY, pvr.cameraZ);
21+
pointLight(255, 255, 255, pg.cameraX, pg.cameraY, pg.cameraZ);
1422

1523
translate(width/2, height/2);
1624

@@ -57,9 +65,9 @@ void draw() {
5765

5866
// Place the aim at 100 units from the camera eye
5967
float d = 100;
60-
float x = d * pvr.forwardX;
61-
float y = d * pvr.forwardY;
62-
float z = pvr.cameraZ + d * pvr.forwardZ;
68+
float x = d * pg.forwardX;
69+
float y = d * pg.forwardY;
70+
float z = pg.cameraZ + d * pg.forwardZ;
6371
stroke(255, 200);
6472
strokeWeight(50);
6573
point(x, y, z);

libraries/vr/src/processing/vr/PGraphicsVR.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,25 @@ protected PGL createPGL(PGraphicsOpenGL pg) {
5959
}
6060

6161

62+
public void vrCoordinates(boolean v) {
63+
if (glCoordsEnabled != v) {
64+
flush();
65+
glCoordsEnabled = v;
66+
}
67+
}
68+
69+
70+
public void registerUpdate() {
71+
registerUpdate("update");
72+
}
73+
74+
75+
public void registerUpdate(String methodName) {
76+
PSurfaceVR surface = (PSurfaceVR)parent.getSurface();
77+
surface.registerUpdateMethod(methodName);
78+
}
79+
80+
6281
public PMatrix3D getEyeMatrix() {
6382
PMatrix3D mat = new PMatrix3D();
6483
mat.set(rightX, upX, forwardX, 0,

libraries/vr/src/processing/vr/PSurfaceVR.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,6 @@ public PSurfaceVR(PGraphics graphics, AppComponent component, SurfaceHolder hold
6767
this.component = component;
6868
this.pgl = (PGLES)((PGraphicsOpenGL)graphics).pgl;
6969

70-
Class<?> c = sketch.getClass();
71-
try {
72-
updateMethod = c.getMethod("update", new Class[] {});
73-
} catch (Exception e) {
74-
}
75-
7670
vrActivity = (GvrActivity)component;
7771
this.activity = vrActivity;
7872
pvr = (PGraphicsVR)graphics;
@@ -177,6 +171,20 @@ public void dispose() {
177171
// surface.onDestroy();
178172
}
179173

174+
public void registerUpdateMethod(String name) {
175+
Class<?> c = sketch.getClass();
176+
try {
177+
updateMethod = c.getMethod(name, new Class[] {});
178+
179+
} catch (NoSuchMethodException nsme) {
180+
sketch.die("There is no public " + name + "() method in sketch class " +
181+
sketch.getClass().getName());
182+
183+
} catch (Exception e) {
184+
sketch.die("Could not register " + name + " + () for " + sketch, e);
185+
}
186+
}
187+
180188
///////////////////////////////////////////////////////////
181189

182190
// Thread handling

libraries/vr/src/processing/vr/PVR.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ public PVR() {
4949
}
5050

5151

52+
static public PGraphicsVR getRenderer(PApplet p) {
53+
return (PGraphicsVR) p.g;
54+
}
55+
56+
5257
public PVR(PApplet sketch) {
5358
this.sketch = sketch;
5459
}

0 commit comments

Comments
 (0)