Book Image

OpenFrameworks Essentials

Book Image

OpenFrameworks Essentials

Overview of this book

Table of Contents (19 chapters)
openFrameworks Essentials
Credits
Foreword
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Drawing a wireframe sphere


Let's start working with 3D by creating a sphere surface and drawing it as a wireframe model.

Tip

A wireframe model is a type of graphical representation of a 3D object on the screen where only its edges are drawn. It appeared in the early era of 3D graphics as a simple way to draw objects in 3D. Now, it is used in 3D modeling software to control the structure of the created objects and as a special effect in films, games, and experimental graphics.

We will achieve this using the ofSpherePrimitive class in the following way:

  1. Add the sphere object definition to the ofApp class, as follows:

    ofSpherePrimitive sphere;
  2. Initialize the sphere in setup():

    sphere.set(250, 20);

    Here, the first argument, 250, is the radius of the sphere. The second argument, 20, is the resolution of the sphere. The resulting spherical surface will have 20 meridians and 20 - 1 = 19 parallels.

    Tip

    To obtain a smoother sphere, increase 20 to a larger value, for example, to 40.

  3. Draw the sphere using the...