-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new features: better offscreen/splitview support using viewport data.
simplyfied rotation math + stabilization at all scales zoom-fix when exceeding limits new examples.
- Loading branch information
Showing
15 changed files
with
895 additions
and
252 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
Oops, something went wrong.