Processing Intro #03 | P3D
Contents
- 3D
- P3D
- Peasy Cam
- 3D Objects
- PVector
- Declaration
- Functions
- Practice
3D
P3D
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | void setup(){ size( 500 , 500 ,P3D); stroke( 255 ); strokeWeight( 10 ); } void draw(){ background( 0 ); point(width/ 2 - 50 ,height/ 2 - 50 ,- 50 ); point(width/ 2 - 50 ,height/ 2 + 50 ,- 50 ); point(width/ 2 - 50 ,height/ 2 + 50 , 50 ); point(width/ 2 - 50 ,height/ 2 - 50 , 50 ); point(width/ 2 + 50 ,height/ 2 - 50 ,- 50 ); point(width/ 2 + 50 ,height/ 2 + 50 ,- 50 ); point(width/ 2 + 50 ,height/ 2 + 50 , 50 ); point(width/ 2 + 50 ,height/ 2 - 50 , 50 ); } |
Peasy Cam
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | import peasy.*; PeasyCam cam; void setup() { size( 500 , 500 ,P3D); strokeWeight( 10 ); stroke( 255 ); cam = new PeasyCam( this , 100 ); cam.setMinimumDistance( 50 ); cam.setMaximumDistance( 500 ); } void draw(){ background( 0 ); point(- 50 ,- 50 ,- 50 ); point(- 50 ,+ 50 ,- 50 ); point(- 50 ,+ 50 , 50 ); point(- 50 ,- 50 , 50 ); point(+ 50 ,- 50 ,- 50 ); point(+ 50 ,+ 50 ,- 50 ); point(+ 50 ,+ 50 , 50 ); point(+ 50 ,- 50 , 50 ); } |
3D Objects
- pushMatrix();
- popMatrix();
- translate(<x>,<y>,<z>);
- rotateX(<rad>);
- Box(<w>,<h>,<d>);
- Sphere(<r>);
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | import peasy.*; PeasyCam cam; void setup() { size( 500 , 500 ,P3D); stroke( 255 ); noFill(); cam = new PeasyCam( this , 200 ); cam.setMinimumDistance( 100 ); cam.setMaximumDistance( 400 ); } void draw(){ background( 0 ); pushMatrix(); translate( 50 , 0 , 0 ); box( 20 , 30 , 40 ); translate(- 100 , 0 , 0 ); sphere( 30 ); popMatrix(); } |
PVector
Declaration
<PVector name> = new PVector(<x>,<y>,<z>);
1 2 3 | PVector p; p = new PVector( 10 , 20 ); ellipse(p.x, p.y, 10 , 10 ); |