Introduction to 3D graphics with openFrameworks
3D graphics is based on using the three-axes coordinate system (X, Y, Z). The X and Y coordinates are directed in exactly the same way as in 2D's case, and the additional Z axis is perpendicular to the screen plane and directed at us.
Note
Actually, openFrameworks draws everything as 3D graphics. When we draw anything using 2D drawing commands, just as we did in the previous chapters, openFrameworks uses Z as being equal to zero.
Most of openFrameworks' 2D drawing functions that we already know have their similar 3D counterparts. For example, consider the commands:
ofLine( 10, 20, 30, 40, 50, 60 ); ofTriangle( 100, 200, 300, 400, 500, 600, 700, 800, 900 );
These will draw a line segment between the points with coordinates (10
, 20
, 30
) and (40
, 50
, 60
) and a triangle with vertices (100
, 200
, 300
), (400
, 500
, 600
), and (700
, 800
, 900
).
Tip
To simplify the code, you can use the ofPoint
class, which represents a 3D point or vector. It has the fields x...