Processing 3

sploshtribeΛογισμικό & κατασκευή λογ/κού

14 Δεκ 2013 (πριν από 3 χρόνια και 6 μήνες)

47 εμφανίσεις

Processing
3
:
3D,
camera,
transformations




In order to work with 3D in Processing you need to supply a third parameter to the size function. There are two
options. If you use Processing’s built
-
in JAVA2D mode then the third parameter will be P3D. If you
wish to use
OPENGL then that will be the third parameter, but you must also import the library
:
import processing.opengl.*;

at
the beginning of the program. There are some nice 3D examples you might want to look at. Recall that the positive
z
-
axis is point
ing towards you.




Create a sketch that contains 3D objects. For now you might want to use a
box

and a
sphere
. Try experimenting with
the translate function to place them (remember that the translate function moves the origin).




Create a camera. The
default

camera
is

camera(width/2.0, height/2.0, (height/2.0) / tan(PI*60.0 / 360.0), width/2.0,
height/2.0, 0, 0, 1, 0)
. The first three coordinates give the position of the viewer (which will be in the middle of the
screen

with an adjusted z
-
value), the next th
ree give the position of the center of the screen (in this case the middle
for the (x,y) and flat against the screen) and the last three give the vector which is pointing up (in this case the y
-
axis). Experiment with setting the camera to different positio
ns.




Now put several 3D objects in your scene and practice positioning them by using
translate

and
rotate


and
scale

functions

and the
push

and
pop

functions. Try having an idea of how the scene should look before you begin coding
and then see if you can r
ealize your idea.




Add a shape to your scene that you create with vertices and the
beginShape

and
endShape

functions.



NOTE: Assignment 1 is due next Friday in class.