mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
/**
|
||||
* Move Eye.
|
||||
* by Simon Greenwold.
|
||||
*
|
||||
* The camera lifts up (controlled by mouseY) while looking at the same point.
|
||||
*/
|
||||
|
||||
void setup() {
|
||||
size(640, 360, P3D);
|
||||
fill(204);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
lights();
|
||||
background(0);
|
||||
|
||||
// Change height of the camera with mouseY
|
||||
camera(30.0, mouseY, 220.0, // eyeX, eyeY, eyeZ
|
||||
0.0, 0.0, 0.0, // centerX, centerY, centerZ
|
||||
0.0, 1.0, 0.0); // upX, upY, upZ
|
||||
|
||||
noStroke();
|
||||
box(90);
|
||||
stroke(255);
|
||||
line(-100, 0, 0, 100, 0, 0);
|
||||
line(0, -100, 0, 0, 100, 0);
|
||||
line(0, 0, -100, 0, 0, 100);
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
import processing.core.*;
|
||||
|
||||
import java.applet.*;
|
||||
import java.awt.*;
|
||||
import java.awt.image.*;
|
||||
import java.awt.event.*;
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
import java.text.*;
|
||||
import java.util.*;
|
||||
import java.util.zip.*;
|
||||
import java.util.regex.*;
|
||||
|
||||
public class MoveEye extends PApplet {
|
||||
|
||||
/**
|
||||
* Move Eye.
|
||||
* by Simon Greenwold.
|
||||
*
|
||||
* The camera lifts up (controlled by mouseY) while looking at the same point.
|
||||
*/
|
||||
|
||||
public void setup() {
|
||||
size(640, 360, P3D);
|
||||
fill(204);
|
||||
}
|
||||
|
||||
public void draw() {
|
||||
lights();
|
||||
background(0);
|
||||
|
||||
// Change height of the camera with mouseY
|
||||
camera(30.0f, mouseY, 220.0f, // eyeX, eyeY, eyeZ
|
||||
0.0f, 0.0f, 0.0f, // centerX, centerY, centerZ
|
||||
0.0f, 1.0f, 0.0f); // upX, upY, upZ
|
||||
|
||||
noStroke();
|
||||
box(90);
|
||||
stroke(255);
|
||||
line(-100, 0, 0, 100, 0, 0);
|
||||
line(0, -100, 0, 0, 100, 0);
|
||||
line(0, 0, -100, 0, 0, 100);
|
||||
}
|
||||
|
||||
static public void main(String args[]) {
|
||||
PApplet.main(new String[] { "MoveEye" });
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/**
|
||||
* Move Eye.
|
||||
* by Simon Greenwold.
|
||||
*
|
||||
* The camera lifts up (controlled by mouseY) while looking at the same point.
|
||||
*/
|
||||
|
||||
void setup() {
|
||||
size(640, 360, P3D);
|
||||
fill(204);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
lights();
|
||||
background(0);
|
||||
|
||||
// Change height of the camera with mouseY
|
||||
camera(30.0, mouseY, 220.0, // eyeX, eyeY, eyeZ
|
||||
0.0, 0.0, 0.0, // centerX, centerY, centerZ
|
||||
0.0, 1.0, 0.0); // upX, upY, upZ
|
||||
|
||||
noStroke();
|
||||
box(90);
|
||||
stroke(255);
|
||||
line(-100, 0, 0, 100, 0, 0);
|
||||
line(0, -100, 0, 0, 100, 0);
|
||||
line(0, 0, -100, 0, 0, 100);
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 2.2 KiB |
@@ -0,0 +1,42 @@
|
||||
/**
|
||||
* Ortho vs Perspective.
|
||||
*
|
||||
* Click to see the difference between orthographic projection
|
||||
* and perspective projection as applied to a simple box.
|
||||
* The ortho() function sets an orthographic projection and
|
||||
* defines a parallel clipping volume. All objects with the
|
||||
* same dimension appear the same size, regardless of whether
|
||||
* they are near or far from the camera. The parameters to this
|
||||
* function specify the clipping volume where left and right
|
||||
* are the minimum and maximum x values, top and bottom are the
|
||||
* minimum and maximum y values, and near and far are the minimum
|
||||
* and maximum z values.
|
||||
*/
|
||||
|
||||
void setup()
|
||||
{
|
||||
size(640, 360, P3D);
|
||||
noStroke();
|
||||
fill(204);
|
||||
}
|
||||
|
||||
void draw()
|
||||
{
|
||||
background(0);
|
||||
lights();
|
||||
|
||||
if(mousePressed) {
|
||||
float fov = PI/3.0;
|
||||
float cameraZ = (height/2.0) / tan(PI * fov / 360.0);
|
||||
perspective(fov, float(width)/float(height),
|
||||
cameraZ/2.0, cameraZ*2.0);
|
||||
} else {
|
||||
ortho(-width/2, width/2, -height/2, height/2, -10, 10);
|
||||
}
|
||||
|
||||
translate(width/2, height/2, 0);
|
||||
rotateX(-PI/6);
|
||||
rotateY(PI/3);
|
||||
box(160);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
import processing.core.*;
|
||||
|
||||
import java.applet.*;
|
||||
import java.awt.*;
|
||||
import java.awt.image.*;
|
||||
import java.awt.event.*;
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
import java.text.*;
|
||||
import java.util.*;
|
||||
import java.util.zip.*;
|
||||
import java.util.regex.*;
|
||||
|
||||
public class OrthoVSPerspective extends PApplet {
|
||||
|
||||
/**
|
||||
* Ortho vs Perspective.
|
||||
*
|
||||
* Click to see the difference between orthographic projection
|
||||
* and perspective projection as applied to a simple box.
|
||||
* The ortho() function sets an orthographic projection and
|
||||
* defines a parallel clipping volume. All objects with the
|
||||
* same dimension appear the same size, regardless of whether
|
||||
* they are near or far from the camera. The parameters to this
|
||||
* function specify the clipping volume where left and right
|
||||
* are the minimum and maximum x values, top and bottom are the
|
||||
* minimum and maximum y values, and near and far are the minimum
|
||||
* and maximum z values.
|
||||
*/
|
||||
|
||||
public void setup()
|
||||
{
|
||||
size(640, 360, P3D);
|
||||
noStroke();
|
||||
fill(204);
|
||||
}
|
||||
|
||||
public void draw()
|
||||
{
|
||||
background(0);
|
||||
lights();
|
||||
|
||||
if(mousePressed) {
|
||||
float fov = PI/3.0f;
|
||||
float cameraZ = (height/2.0f) / tan(PI * fov / 360.0f);
|
||||
perspective(fov, PApplet.parseFloat(width)/PApplet.parseFloat(height),
|
||||
cameraZ/2.0f, cameraZ*2.0f);
|
||||
} else {
|
||||
ortho(-width/2, width/2, -height/2, height/2, -10, 10);
|
||||
}
|
||||
|
||||
translate(width/2, height/2, 0);
|
||||
rotateX(-PI/6);
|
||||
rotateY(PI/3);
|
||||
box(160);
|
||||
}
|
||||
|
||||
|
||||
static public void main(String args[]) {
|
||||
PApplet.main(new String[] { "OrthoVSPerspective" });
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/**
|
||||
* Ortho vs Perspective.
|
||||
*
|
||||
* Click to see the difference between orthographic projection
|
||||
* and perspective projection as applied to a simple box.
|
||||
* The ortho() function sets an orthographic projection and
|
||||
* defines a parallel clipping volume. All objects with the
|
||||
* same dimension appear the same size, regardless of whether
|
||||
* they are near or far from the camera. The parameters to this
|
||||
* function specify the clipping volume where left and right
|
||||
* are the minimum and maximum x values, top and bottom are the
|
||||
* minimum and maximum y values, and near and far are the minimum
|
||||
* and maximum z values.
|
||||
*/
|
||||
|
||||
void setup()
|
||||
{
|
||||
size(640, 360, P3D);
|
||||
noStroke();
|
||||
fill(204);
|
||||
}
|
||||
|
||||
void draw()
|
||||
{
|
||||
background(0);
|
||||
lights();
|
||||
|
||||
if(mousePressed) {
|
||||
float fov = PI/3.0;
|
||||
float cameraZ = (height/2.0) / tan(PI * fov / 360.0);
|
||||
perspective(fov, float(width)/float(height),
|
||||
cameraZ/2.0, cameraZ*2.0);
|
||||
} else {
|
||||
ortho(-width/2, width/2, -height/2, height/2, -10, 10);
|
||||
}
|
||||
|
||||
translate(width/2, height/2, 0);
|
||||
rotateX(-PI/6);
|
||||
rotateY(PI/3);
|
||||
box(160);
|
||||
}
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 2.2 KiB |
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* Perspective.
|
||||
*
|
||||
* Move the mouse left and right to change the field of view (fov).
|
||||
* Click to modify the aspect ratio. The perspective() function
|
||||
* sets a perspective projection applying foreshortening, making
|
||||
* distant objects appear smaller than closer ones. The parameters
|
||||
* define a viewing volume with the shape of truncated pyramid.
|
||||
* Objects near to the front of the volume appear their actual size,
|
||||
* while farther objects appear smaller. This projection simulates
|
||||
* the perspective of the world more accurately than orthographic projection.
|
||||
* The version of perspective without parameters sets the default
|
||||
* perspective and the version with four parameters allows the programmer
|
||||
* to set the area precisely.
|
||||
*/
|
||||
|
||||
void setup() {
|
||||
size(640, 360, P3D);
|
||||
noStroke();
|
||||
}
|
||||
|
||||
void draw() {
|
||||
lights();
|
||||
background(204);
|
||||
float cameraY = height/2.0;
|
||||
float fov = mouseX/float(width) * PI/2;
|
||||
float cameraZ = cameraY / tan(fov / 2.0);
|
||||
float aspect = float(width)/float(height);
|
||||
if (mousePressed) {
|
||||
aspect = aspect / 2.0;
|
||||
}
|
||||
perspective(fov, aspect, cameraZ/10.0, cameraZ*10.0);
|
||||
|
||||
translate(width/2+30, height/2, 0);
|
||||
rotateX(-PI/6);
|
||||
rotateY(PI/3 + mouseY/float(height) * PI);
|
||||
box(45);
|
||||
translate(0, 0, -50);
|
||||
box(30);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
import processing.core.*;
|
||||
|
||||
import java.applet.*;
|
||||
import java.awt.*;
|
||||
import java.awt.image.*;
|
||||
import java.awt.event.*;
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
import java.text.*;
|
||||
import java.util.*;
|
||||
import java.util.zip.*;
|
||||
import java.util.regex.*;
|
||||
|
||||
public class Perspective extends PApplet {
|
||||
|
||||
/**
|
||||
* Perspective.
|
||||
*
|
||||
* Move the mouse left and right to change the field of view (fov).
|
||||
* Click to modify the aspect ratio. The perspective() function
|
||||
* sets a perspective projection applying foreshortening, making
|
||||
* distant objects appear smaller than closer ones. The parameters
|
||||
* define a viewing volume with the shape of truncated pyramid.
|
||||
* Objects near to the front of the volume appear their actual size,
|
||||
* while farther objects appear smaller. This projection simulates
|
||||
* the perspective of the world more accurately than orthographic projection.
|
||||
* The version of perspective without parameters sets the default
|
||||
* perspective and the version with four parameters allows the programmer
|
||||
* to set the area precisely.
|
||||
*/
|
||||
|
||||
public void setup() {
|
||||
size(640, 360, P3D);
|
||||
noStroke();
|
||||
}
|
||||
|
||||
public void draw() {
|
||||
lights();
|
||||
background(204);
|
||||
float cameraY = height/2.0f;
|
||||
float fov = mouseX/PApplet.parseFloat(width) * PI/2;
|
||||
float cameraZ = cameraY / tan(fov / 2.0f);
|
||||
float aspect = PApplet.parseFloat(width)/PApplet.parseFloat(height);
|
||||
if (mousePressed) {
|
||||
aspect = aspect / 2.0f;
|
||||
}
|
||||
perspective(fov, aspect, cameraZ/10.0f, cameraZ*10.0f);
|
||||
|
||||
translate(width/2+30, height/2, 0);
|
||||
rotateX(-PI/6);
|
||||
rotateY(PI/3 + mouseY/PApplet.parseFloat(height) * PI);
|
||||
box(45);
|
||||
translate(0, 0, -50);
|
||||
box(30);
|
||||
}
|
||||
|
||||
|
||||
static public void main(String args[]) {
|
||||
PApplet.main(new String[] { "Perspective" });
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* Perspective.
|
||||
*
|
||||
* Move the mouse left and right to change the field of view (fov).
|
||||
* Click to modify the aspect ratio. The perspective() function
|
||||
* sets a perspective projection applying foreshortening, making
|
||||
* distant objects appear smaller than closer ones. The parameters
|
||||
* define a viewing volume with the shape of truncated pyramid.
|
||||
* Objects near to the front of the volume appear their actual size,
|
||||
* while farther objects appear smaller. This projection simulates
|
||||
* the perspective of the world more accurately than orthographic projection.
|
||||
* The version of perspective without parameters sets the default
|
||||
* perspective and the version with four parameters allows the programmer
|
||||
* to set the area precisely.
|
||||
*/
|
||||
|
||||
void setup() {
|
||||
size(640, 360, P3D);
|
||||
noStroke();
|
||||
}
|
||||
|
||||
void draw() {
|
||||
lights();
|
||||
background(204);
|
||||
float cameraY = height/2.0;
|
||||
float fov = mouseX/float(width) * PI/2;
|
||||
float cameraZ = cameraY / tan(fov / 2.0);
|
||||
float aspect = float(width)/float(height);
|
||||
if (mousePressed) {
|
||||
aspect = aspect / 2.0;
|
||||
}
|
||||
perspective(fov, aspect, cameraZ/10.0, cameraZ*10.0);
|
||||
|
||||
translate(width/2+30, height/2, 0);
|
||||
rotateX(-PI/6);
|
||||
rotateY(PI/3 + mouseY/float(height) * PI);
|
||||
box(45);
|
||||
translate(0, 0, -50);
|
||||
box(30);
|
||||
}
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 2.2 KiB |
Reference in New Issue
Block a user