Simple 3D drawing
For simple 3D drawing in openFrameworks, follow these steps:
Add the
ofEnableDepthTest()
function call in the beginning of thetestApp::draw()
function to enable z-buffering. If you omit it, all the graphics objects will be rendered without respect to their z coordinate in correspondence with the graphical primitives' rendering order.Draw primitives as follows:
The
ofLine( x1, y1, z1, x2, y2, z2 )
function draws a line segment between points (x1
,y1
,z1
) and (x2
,y2
,z2
). There is an overloaded version of the function,ofLine( p1, p2 )
, wherep1
andp2
have typeofPoint
. Use theofSetColor()
andofSetLineWidth()
functions to adjust its rendering properties of color and line width.Note
In Chapter 2, Drawing in 2D, we used the
ofPoint
class to represent 2D points using its fieldsx
andy
. Actually,ofPoint
has a third fieldz
, which, by default, is equal to zero. SoofPoint
can represent points in 3D. Just declareofPoint p
and work with valuesp.x
,p.y
, andp.z
.The
ofTriangle...