Skip to content

Commit a706a8b

Browse files
committed
added calculate() function to PApplet
1 parent c886fd8 commit a706a8b

File tree

4 files changed

+16
-54
lines changed

4 files changed

+16
-54
lines changed

core/src/processing/core/PApplet.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,6 +1144,10 @@ public void setup() {
11441144
}
11451145

11461146

1147+
public void calculate() {
1148+
}
1149+
1150+
11471151
public void draw() {
11481152
// if no draw method, then shut things down
11491153
//System.out.println("no draw method, goodbye");

libraries/vr/examples/drawAim/drawAim.pde

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,21 @@
11
import processing.vr.*;
22

3-
PGraphicsVR pg;
4-
53
void setup() {
64
fullScreen(PVR.STEREO);
7-
pg = PVR.getRenderer(this);
8-
pg.registerUpdate();
95
}
106

11-
void update() {
12-
println("in update function");
7+
void calculate() {
8+
println("in calculate function");
139
}
1410

1511
void draw() {
16-
background(150);
17-
18-
println("in draw function for eye " + pg.eyeType);
19-
20-
// Some lights
21-
pointLight(255, 255, 255, pg.cameraX, pg.cameraY, pg.cameraZ);
22-
12+
background(150);
2313
translate(width/2, height/2);
24-
2514
noStroke();
2615

16+
// Some lights
17+
pointLight(255, 255, 255, 0, 0, 500);
18+
2719
// Floor
2820
beginShape(QUADS);
2921
fill(255, 0, 0);
@@ -36,6 +28,7 @@ void draw() {
3628
vertex(+width/2, +500, -width/2);
3729
endShape();
3830

31+
// Large box at the center
3932
pushMatrix();
4033
rotateY(millis()/1000.0);
4134
fill(220);
@@ -63,12 +56,10 @@ void draw() {
6356
box(100);
6457
popMatrix();
6558

66-
// Place the aim at 100 units from the camera eye
67-
float d = 100;
68-
float x = d * pg.forwardX;
69-
float y = d * pg.forwardY;
70-
float z = pg.cameraZ + d * pg.forwardZ;
59+
// Use eye coordinates at 100 units from the camera position:
60+
PGraphicsVR gvr = (PGraphicsVR)g;
61+
gvr.eye();
7162
stroke(255, 200);
7263
strokeWeight(50);
73-
point(x, y, z);
64+
point(0, 0, 100);
7465
}

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

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,6 @@ public void vrCoordinates(boolean v) {
6767
}
6868

6969

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-
8170
public PMatrix3D getEyeMatrix() {
8271
PMatrix3D mat = new PMatrix3D();
8372
mat.set(rightX, upX, forwardX, cameraX,

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

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424

2525
import java.io.File;
2626
import java.io.InputStream;
27-
import java.lang.reflect.Method;
2827

2928
import javax.microedition.khronos.egl.EGLConfig;
3029

@@ -58,9 +57,6 @@ public class PSurfaceVR extends PSurfaceGLES {
5857
protected GvrActivity vrActivity;
5958
protected AndroidVRStereoRenderer renderer;
6059

61-
protected Method updateMethod;
62-
protected Object[] noArgs = new Object[] {};
63-
6460
public PSurfaceVR(PGraphics graphics, AppComponent component, SurfaceHolder holder, boolean vr) {
6561
this.sketch = graphics.parent;
6662
this.graphics = graphics;
@@ -171,19 +167,6 @@ public void dispose() {
171167
// surface.onDestroy();
172168
}
173169

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-
}
187170

188171
///////////////////////////////////////////////////////////
189172

@@ -294,12 +277,7 @@ public void onNewFrame(HeadTransform transform) {
294277
hadnleGVREnumError();
295278
pgl.getGL(null);
296279
pvr.headTransform(transform);
297-
if (updateMethod != null) {
298-
try {
299-
updateMethod.invoke(sketch, noArgs);
300-
} catch (Exception e) {
301-
}
302-
}
280+
sketch.calculate();
303281
}
304282

305283
@Override

0 commit comments

Comments
 (0)