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

Centering the coordinate system


By default, in openFrameworks (and in most computer programs dealing with 2D graphics), the center of the screen coordinate system is placed in the top-left corner of the screen. The horizontal axis is directed to the right and the vertical axis is directed downwards. The measurement unit is the pixel.

For a screen with size 1280 × 720 pixels, the top-left corner has the coordinates (0, 0) and the bottom-right corner has the coordinates (1280-1, 720-1) = (1279, 719), as shown in the following screenshot:

This shows the default coordinate system

We are planning to implement generative graphics, which is situated around the screen center. To make the code easier, it's a good approach to move the coordinate system origin to the screen center by adding the following lines to the ofApp::draw() function:

ofPushMatrix();
ofTranslate( ofGetWidth() / 2, ofGetHeight() / 2 );
//----
//...       We will place our drawing code here
//----
ofPopMatrix();

The ofPushMatrix() function...