Skip to content

Commit

Permalink
new features: better offscreen/splitview support using viewport data.
Browse files Browse the repository at this point in the history
simplyfied rotation math + stabilization at all scales
zoom-fix when exceeding limits

new examples.
  • Loading branch information
diwi committed Jan 3, 2018
1 parent 078290b commit 35b4c23
Show file tree
Hide file tree
Showing 15 changed files with 895 additions and 252 deletions.
1 change: 0 additions & 1 deletion .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="test"/>
<classpathentry kind="src" path="testHUD"/>
<classpathentry combineaccessrules="false" kind="src" path="/processing-core"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path="bin"/>
Expand Down
42 changes: 42 additions & 0 deletions examples/CameraStates/CameraStates.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@

import peasy.*;


//
// '1' save current camera-state
// '2' apply saved camera-state
//

PeasyCam cam;

public void settings() {
size(800, 600, P3D);
}

public void setup() {
cam = new PeasyCam(this, 400);
state = cam.getState();
}

public void draw() {
rotateX(-.5f);
rotateY(-.5f);
lights();
scale(10);
strokeWeight(1 / 10f);
background(0);
fill(220, 255, 0);
box(30);
pushMatrix();
translate(0, 0, 20);
fill(0, 96, 255);
box(5);
popMatrix();
}

CameraState state;

public void keyReleased() {
if (key == '1') state = cam.getState();
if (key == '2') cam.setState(state, 1000);
}
41 changes: 41 additions & 0 deletions examples/HeadUpDisplay/HeadUpDisplay.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

import peasy.PeasyCam;


//
// screen-aligned, orthographic HUD-scope
//

PeasyCam cam;

public void settings() {
size(800, 600, P3D);
smooth(8);
}

public void setup() {
cam = new PeasyCam(this, 400);
}

public void draw() {
rotateX(-.5f);
rotateY(-.5f);
lights();
scale(10);
strokeWeight(1 / 10f);
background(0);
fill(96, 255, 0);
box(30);
pushMatrix();
translate(0, 0, 20);
fill(0, 96, 255);
box(5);
popMatrix();

cam.beginHUD();
fill(0, 128);
rect(0, 0, 70, 30);
fill(255);
text("" + nfc(frameRate, 2), 10, 18);
cam.endHUD();
}
51 changes: 28 additions & 23 deletions examples/HelloPeasy/HelloPeasy.pde
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
import peasy.*;

PeasyCam cam;

void setup() {
size(200,200,P3D);
cam = new PeasyCam(this, 100);
cam.setMinimumDistance(50);
cam.setMaximumDistance(500);
}
void draw() {
rotateX(-.5);
rotateY(-.5);
background(0);
fill(255,0,0);
box(30);
pushMatrix();
translate(0,0,20);
fill(0,0,255);
box(5);
popMatrix();
}


import peasy.PeasyCam;


PeasyCam cam;

public void settings() {
size(800, 600, P3D);
}

public void setup() {
cam = new PeasyCam(this, 400);
}

public void draw() {
rotateX(-.5f);
rotateY(-.5f);
lights();
scale(10);
strokeWeight(1 / 10f);
background(0);
fill(255, 0, 0);
box(30);
pushMatrix();
translate(0, 0, 20);
fill(0, 0, 255);
box(5);
popMatrix();
}
115 changes: 115 additions & 0 deletions examples/MultiView_Offscreen/MultiView_Offscreen.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@


import peasy.PeasyCam;


//
//
// MultiView (advanced version)
//
// N x N Camera Views of the same scene, using N x N separate pgraphics.
//
//

final int NX = 3;
final int NY = 2;
PeasyCam[] cameras = new PeasyCam[NX * NY];

public void settings() {
size(1280, 720, P2D); // 2D
smooth(8);
}

public void setup() {

int gap = 5;

// tiling size
int tilex = floor((width - gap) / NX);
int tiley = floor((height - gap) / NY);

// viewport offset ... corrected gap due to floor()
int offx = (width - (tilex * NX - gap)) / 2;
int offy = (height - (tiley * NY - gap)) / 2;

// viewport dimension
int cw = tilex - gap;
int ch = tiley - gap;

// create new viewport for each camera
for(int y = 0; y < NY; y++){
for(int x = 0; x < NX; x++){
int id = y * NX + x;
int cx = offx + x * tilex;
int cy = offy + y * tiley;
PGraphics pg = createGraphics(cw, ch, P3D);
cameras[id] = new PeasyCam(this, pg, 400);
cameras[id].setViewport(cx, cy, cw, ch); // this is the key of this whole demo
}
}

}


public void draw(){
// render scene once per camera/viewport
for(int i = 0; i < cameras.length; i++){
displayScene(cameras[i], i);
}

background(0);
for(int i = 0; i < cameras.length; i++){
int[] viewport = cameras[i].getViewport();
image(cameras[i].getCanvas(), viewport[0], viewport[1], viewport[2], viewport[3]);
}
}


public void displayScene(PeasyCam cam, int ID){

PGraphics pg = cam.getCanvas();

int[] viewport = cam.getViewport();
int w = viewport[2];
int h = viewport[3];

pg.beginDraw();
pg.resetMatrix();

// modelview - using camera state
cam.feed();

// projection - using camera viewport
pg.perspective(60 * PI/180, w/(float)h, 1, 5000);

// clear background (scissors makes sure we only clear the region we own)
pg.background(24);
pg.stroke(0);
pg.strokeWeight(0.3f);

// scene objects
pg.pushMatrix();
pg.translate(-100, 0, 0);
pg.fill(0,96,255);
pg.box(100);
pg.popMatrix();

pg.pushMatrix();
pg.translate(100, 0, 0);
pg.rotateX(PI/2);
float c = 255 * ID/(float) (cameras.length-1);
pg.fill(255, 255-c/2, 255-c);
pg.sphere(80);
pg.popMatrix();

// screen-aligned 2D HUD
cam.beginHUD();
pg.rectMode(CORNER);
pg.fill(0);
pg.rect(0, 0, 60, 23);
pg.fill(255,128,0);
pg.text("cam "+ID, 10, 15);
cam.endHUD();

pg.endDraw();
}
Loading

0 comments on commit 35b4c23

Please sign in to comment.