DESIGNING 3D systems is often only slightly more difficult than conceiving 2D systems. Illustrated below is the transition from 2D to 3D for a sample Processing program.

TIME TO GET DIRTY with programming 3D visuals. We will take the Processing example from the Object-Oriented Programming lesson and convert it into 3D.

STEP 1:
First, we will take a look at the previous OOP Motion example.


view source

STEP 2:
First, we will create two new variables: xmag and ymag. These variables will represent the magnitude of the rotation that we want to apply to our visuals. newXmag and newYmag are used to buffer the values before we apply them, just so everything is rotated evenly. Note the order in which objects are drawn, and how the commands used to position them are sequenced. The ordering becomes significant when rotation is involved because it will affect the axis on which objects are rotated. newXmag and newYmag are defined in the mouseDragged function. Drag the mouse around to see the effect.


view source

STEP 3:
The next step is to change the rect functions into box functions, and add a third position and velocity property to the Objects, z, vZ. You will also want to define the z-boundary of the bounding box so that the Objects bounce off those walls too.


view source