| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,40 @@ | |||
| 1 | + /** | ||
| 2 | + * Perspective vs. Ortho | ||
| 3 | + * | ||
| 4 | + * Move the mouse left to right to change the "far" | ||
| 5 | + * parameter for the perspective() and ortho() functions. | ||
| 6 | + * This parameter sets the maximum distance from the | ||
| 7 | + * origin away from the viewer and will clip the geometry. | ||
| 8 | + * Click a mouse button to switch between the perspective and | ||
| 9 | + * orthographic projections. | ||
| 10 | + */ | ||
| 11 | + | ||
| 12 | + | ||
| 13 | + boolean showPerspective = false; | ||
| 14 | + | ||
| 15 | + void setup() { | ||
| 16 | + size(600, 360, P3D); | ||
| 17 | + noFill(); | ||
| 18 | + fill(255); | ||
| 19 | + noStroke(); | ||
| 20 | + } | ||
| 21 | + | ||
| 22 | + void draw() { | ||
| 23 | + lights(); | ||
| 24 | + background(0); | ||
| 25 | + float far = map(mouseX, 0, width, 120, 400); | ||
| 26 | + if (showPerspective == true) { | ||
| 27 | + perspective(PI/3.0, float(width)/float(height), 10, far); | ||
| 28 | + } else { | ||
| 29 | + ortho(0, width, 0, height, 10, far); | ||
| 30 | + } | ||
| 31 | + translate(width/2, height/2, 0); | ||
| 32 | + rotateX(-PI/6); | ||
| 33 | + rotateY(PI/3); | ||
| 34 | + box(180); | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | + void mousePressed() { | ||
| 38 | + showPerspective = !showPerspective; | ||
| 39 | + } | ||
| 40 | + | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments