Drawing 3D primitives
In the previous chapter, you learned about drawing basic 2D shapes. Processing also has some 3D primitives, by default—a box and a sphere. In this recipe, we'll take a look at how you can draw them.
How to do it...
I'm not going to write the code for the setup()
function, in this recipe. You probably know, by now, how to use it. Import the OpenGL library, just as you did in the Understanding 3D space recipe and create a window with a resolution of 640 x 480 pixels. Don't forget to add the OPENGL
parameter to the size()
function.
Add the following piece of code to the draw()
function. We reuse the pushMatrix()
, popMatrix()
, and translate()
functions from the previous example. We are going to add the rotateY()
function to rotate our 3D primitives. These primitives are drawn to the screen with the box()
and sphere()
functions. The sphereDetail()
function is used to manipulate the shape of the sphere.
background( 255 ); lights(); float angleY = radians( frameCount ); ...