Skip to content

Commit

Permalink
added getRenderer, vrCoordinates, registerUpdate
Browse files Browse the repository at this point in the history
  • Loading branch information
codeanticode committed May 6, 2017
1 parent 5792609 commit 2190572
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 13 deletions.
22 changes: 15 additions & 7 deletions libraries/vr/examples/drawAim/drawAim.pde
@@ -1,16 +1,24 @@
import processing.vr.*;

PGraphicsVR pg;

void setup() {
fullScreen(PVR.STEREO);
fullScreen(PVR.STEREO);
pg = PVR.getRenderer(this);
pg.registerUpdate();
}

void update() {
println("in update function");
}

void draw() {
background(150);
PGraphicsVR pvr = (PGraphicsVR)g;


println("in draw function for eye " + pg.eyeType);

// Some lights
pointLight(255, 255, 255, pvr.cameraX, pvr.cameraY, pvr.cameraZ);
pointLight(255, 255, 255, pg.cameraX, pg.cameraY, pg.cameraZ);

translate(width/2, height/2);

Expand Down Expand Up @@ -57,9 +65,9 @@ void draw() {

// Place the aim at 100 units from the camera eye
float d = 100;
float x = d * pvr.forwardX;
float y = d * pvr.forwardY;
float z = pvr.cameraZ + d * pvr.forwardZ;
float x = d * pg.forwardX;
float y = d * pg.forwardY;
float z = pg.cameraZ + d * pg.forwardZ;
stroke(255, 200);
strokeWeight(50);
point(x, y, z);
Expand Down
19 changes: 19 additions & 0 deletions libraries/vr/src/processing/vr/PGraphicsVR.java
Expand Up @@ -59,6 +59,25 @@ protected PGL createPGL(PGraphicsOpenGL pg) {
}


public void vrCoordinates(boolean v) {
if (glCoordsEnabled != v) {
flush();
glCoordsEnabled = v;
}
}


public void registerUpdate() {
registerUpdate("update");
}


public void registerUpdate(String methodName) {
PSurfaceVR surface = (PSurfaceVR)parent.getSurface();
surface.registerUpdateMethod(methodName);
}


public PMatrix3D getEyeMatrix() {
PMatrix3D mat = new PMatrix3D();
mat.set(rightX, upX, forwardX, 0,
Expand Down
20 changes: 14 additions & 6 deletions libraries/vr/src/processing/vr/PSurfaceVR.java
Expand Up @@ -67,12 +67,6 @@ public PSurfaceVR(PGraphics graphics, AppComponent component, SurfaceHolder hold
this.component = component;
this.pgl = (PGLES)((PGraphicsOpenGL)graphics).pgl;

Class<?> c = sketch.getClass();
try {
updateMethod = c.getMethod("update", new Class[] {});
} catch (Exception e) {
}

vrActivity = (GvrActivity)component;
this.activity = vrActivity;
pvr = (PGraphicsVR)graphics;
Expand Down Expand Up @@ -177,6 +171,20 @@ public void dispose() {
// surface.onDestroy();
}

public void registerUpdateMethod(String name) {
Class<?> c = sketch.getClass();
try {
updateMethod = c.getMethod(name, new Class[] {});

} catch (NoSuchMethodException nsme) {
sketch.die("There is no public " + name + "() method in sketch class " +
sketch.getClass().getName());

} catch (Exception e) {
sketch.die("Could not register " + name + " + () for " + sketch, e);
}
}

///////////////////////////////////////////////////////////

// Thread handling
Expand Down
5 changes: 5 additions & 0 deletions libraries/vr/src/processing/vr/PVR.java
Expand Up @@ -49,6 +49,11 @@ public PVR() {
}


static public PGraphicsVR getRenderer(PApplet p) {
return (PGraphicsVR) p.g;
}


public PVR(PApplet sketch) {
this.sketch = sketch;
}
Expand Down

0 comments on commit 2190572

Please sign in to comment.