From 1a3a9b3be086a34efa841ec2af9416f1c1dcbdab Mon Sep 17 00:00:00 2001 From: Michael Hadley Date: Sun, 28 Feb 2016 19:52:08 -0600 Subject: [PATCH] Updates to code examples to match corresponding revisions in PR to ofBook --- 12_generativeMesh/01_basicMesh/src/ofApp.cpp | 17 ++-- .../addons.make | 0 .../bin/data/.gitkeep | 0 12_generativeMesh/02_meshIndices/src/main.cpp | 8 ++ .../02_meshIndices/src/ofApp.cpp | 55 ++++++++++++ 12_generativeMesh/02_meshIndices/src/ofApp.h | 13 +++ .../addons.make | 0 .../bin/data/.gitkeep | 0 .../bin/data/stars.png | Bin .../src/main.cpp | 0 .../src/ofApp.cpp | 14 ++- .../src/ofApp.h | 0 .../{04_mesh3d => 04_meshLines}/addons.make | 0 .../bin/data/.gitkeep | 0 .../bin/data/stars.png | Bin .../src/main.cpp | 0 .../src/ofApp.cpp | 12 ++- .../src/ofApp.h | 0 .../addons.make | 0 .../bin/data/.gitkeep | 0 .../bin/data/stars.png | Bin .../{04_mesh3d => 05_mesh3d}/src/main.cpp | 0 .../{04_mesh3d => 05_mesh3d}/src/ofApp.cpp | 14 ++- .../{04_mesh3d => 05_mesh3d}/src/ofApp.h | 0 .../06_mesh3dJitter/05_mesh3dJitter.VC.opendb | Bin 0 -> 54 bytes .../addons.make | 0 .../bin/data/.gitkeep | 0 .../bin/data/stars.png | Bin .../src/main.cpp | 0 .../src/ofApp.cpp | 41 +++------ .../src/ofApp.h | 0 .../07_meshOrbit/06_meshOrbit.VC.opendb | Bin 0 -> 54 bytes .../addons.make | 0 .../bin/data/.gitkeep | 0 .../bin/data/stars.png | Bin .../src/main.cpp | 0 .../src/ofApp.cpp | 63 ++++++------- .../src/ofApp.h | 0 .../08_meshDisplacement/addons.make | 0 .../08_meshDisplacement/bin/data/.gitkeep | 0 .../bin/data/stars.png | Bin .../src/main.cpp | 0 .../src/ofApp.cpp | 84 ++++++++---------- .../src/ofApp.h | 0 44 files changed, 196 insertions(+), 125 deletions(-) rename 12_generativeMesh/{02_meshFromImage => 02_meshIndices}/addons.make (100%) rename 12_generativeMesh/{02_meshFromImage => 02_meshIndices}/bin/data/.gitkeep (100%) create mode 100644 12_generativeMesh/02_meshIndices/src/main.cpp create mode 100644 12_generativeMesh/02_meshIndices/src/ofApp.cpp create mode 100644 12_generativeMesh/02_meshIndices/src/ofApp.h rename 12_generativeMesh/{03_meshLines => 03_meshFromImage}/addons.make (100%) rename 12_generativeMesh/{03_meshLines => 03_meshFromImage}/bin/data/.gitkeep (100%) rename 12_generativeMesh/{02_meshFromImage => 03_meshFromImage}/bin/data/stars.png (100%) rename 12_generativeMesh/{02_meshFromImage => 03_meshFromImage}/src/main.cpp (100%) rename 12_generativeMesh/{02_meshFromImage => 03_meshFromImage}/src/ofApp.cpp (61%) rename 12_generativeMesh/{02_meshFromImage => 03_meshFromImage}/src/ofApp.h (100%) rename 12_generativeMesh/{04_mesh3d => 04_meshLines}/addons.make (100%) rename 12_generativeMesh/{04_mesh3d => 04_meshLines}/bin/data/.gitkeep (100%) rename 12_generativeMesh/{03_meshLines => 04_meshLines}/bin/data/stars.png (100%) rename 12_generativeMesh/{03_meshLines => 04_meshLines}/src/main.cpp (100%) rename 12_generativeMesh/{03_meshLines => 04_meshLines}/src/ofApp.cpp (80%) rename 12_generativeMesh/{03_meshLines => 04_meshLines}/src/ofApp.h (100%) rename 12_generativeMesh/{05_mesh3dJitter => 05_mesh3d}/addons.make (100%) rename 12_generativeMesh/{05_mesh3dJitter => 05_mesh3d}/bin/data/.gitkeep (100%) rename 12_generativeMesh/{04_mesh3d => 05_mesh3d}/bin/data/stars.png (100%) rename 12_generativeMesh/{04_mesh3d => 05_mesh3d}/src/main.cpp (100%) rename 12_generativeMesh/{04_mesh3d => 05_mesh3d}/src/ofApp.cpp (78%) rename 12_generativeMesh/{04_mesh3d => 05_mesh3d}/src/ofApp.h (100%) create mode 100644 12_generativeMesh/06_mesh3dJitter/05_mesh3dJitter.VC.opendb rename 12_generativeMesh/{06_meshOrbit => 06_mesh3dJitter}/addons.make (100%) rename 12_generativeMesh/{06_meshOrbit => 06_mesh3dJitter}/bin/data/.gitkeep (100%) rename 12_generativeMesh/{05_mesh3dJitter => 06_mesh3dJitter}/bin/data/stars.png (100%) rename 12_generativeMesh/{05_mesh3dJitter => 06_mesh3dJitter}/src/main.cpp (100%) rename 12_generativeMesh/{05_mesh3dJitter => 06_mesh3dJitter}/src/ofApp.cpp (78%) rename 12_generativeMesh/{05_mesh3dJitter => 06_mesh3dJitter}/src/ofApp.h (100%) create mode 100644 12_generativeMesh/07_meshOrbit/06_meshOrbit.VC.opendb rename 12_generativeMesh/{07_meshDisplacement => 07_meshOrbit}/addons.make (100%) rename 12_generativeMesh/{07_meshDisplacement => 07_meshOrbit}/bin/data/.gitkeep (100%) rename 12_generativeMesh/{06_meshOrbit => 07_meshOrbit}/bin/data/stars.png (100%) rename 12_generativeMesh/{06_meshOrbit => 07_meshOrbit}/src/main.cpp (100%) rename 12_generativeMesh/{06_meshOrbit => 07_meshOrbit}/src/ofApp.cpp (74%) rename 12_generativeMesh/{06_meshOrbit => 07_meshOrbit}/src/ofApp.h (100%) create mode 100644 12_generativeMesh/08_meshDisplacement/addons.make create mode 100644 12_generativeMesh/08_meshDisplacement/bin/data/.gitkeep rename 12_generativeMesh/{07_meshDisplacement => 08_meshDisplacement}/bin/data/stars.png (100%) rename 12_generativeMesh/{07_meshDisplacement => 08_meshDisplacement}/src/main.cpp (100%) rename 12_generativeMesh/{07_meshDisplacement => 08_meshDisplacement}/src/ofApp.cpp (76%) rename 12_generativeMesh/{07_meshDisplacement => 08_meshDisplacement}/src/ofApp.h (100%) diff --git a/12_generativeMesh/01_basicMesh/src/ofApp.cpp b/12_generativeMesh/01_basicMesh/src/ofApp.cpp index 223a32c..4421a88 100644 --- a/12_generativeMesh/01_basicMesh/src/ofApp.cpp +++ b/12_generativeMesh/01_basicMesh/src/ofApp.cpp @@ -2,11 +2,14 @@ //-------------------------------------------------------------- void ofApp::setup(){ - -// mesh.setMode(OF_PRIMITIVE_POINTS); -// mesh.setMode(OF_PRIMITIVE_LINES); -// mesh.setMode(OF_PRIMITIVE_LINE_STRIP); + mesh.setMode(OF_PRIMITIVE_LINE_LOOP); + + // Alternate primitive modes to try: + //mesh.setMode(OF_PRIMITIVE_POINTS); + //mesh.setMode(OF_PRIMITIVE_LINES); + //mesh.setMode(OF_PRIMITIVE_LINE_STRIP); + mesh.enableColors(); ofVec3f top(100.0, 50.0, 0.0); @@ -14,13 +17,13 @@ void ofApp::setup(){ ofVec3f right(150.0, 150.0, 0.0); mesh.addVertex(top); - mesh.addColor(ofFloatColor(1.0, 0.0, 0.0)); + mesh.addColor(ofFloatColor(1.0, 0.0, 0.0)); // Red mesh.addVertex(left); - mesh.addColor(ofFloatColor(0.0, 1.0, 0.0)); + mesh.addColor(ofFloatColor(0.0, 1.0, 0.0)); // Green mesh.addVertex(right); - mesh.addColor(ofFloatColor(1.0, 1.0, 0.0)); + mesh.addColor(ofFloatColor(1.0, 1.0, 0.0)); // Blue ofBackground(0); } diff --git a/12_generativeMesh/02_meshFromImage/addons.make b/12_generativeMesh/02_meshIndices/addons.make similarity index 100% rename from 12_generativeMesh/02_meshFromImage/addons.make rename to 12_generativeMesh/02_meshIndices/addons.make diff --git a/12_generativeMesh/02_meshFromImage/bin/data/.gitkeep b/12_generativeMesh/02_meshIndices/bin/data/.gitkeep similarity index 100% rename from 12_generativeMesh/02_meshFromImage/bin/data/.gitkeep rename to 12_generativeMesh/02_meshIndices/bin/data/.gitkeep diff --git a/12_generativeMesh/02_meshIndices/src/main.cpp b/12_generativeMesh/02_meshIndices/src/main.cpp new file mode 100644 index 0000000..9e89ab5 --- /dev/null +++ b/12_generativeMesh/02_meshIndices/src/main.cpp @@ -0,0 +1,8 @@ +#include "ofMain.h" +#include "ofApp.h" + +int main( ){ + ofSetupOpenGL(150,125,OF_WINDOW); + ofRunApp(new ofApp()); + +} diff --git a/12_generativeMesh/02_meshIndices/src/ofApp.cpp b/12_generativeMesh/02_meshIndices/src/ofApp.cpp new file mode 100644 index 0000000..273d7d4 --- /dev/null +++ b/12_generativeMesh/02_meshIndices/src/ofApp.cpp @@ -0,0 +1,55 @@ +#include "ofApp.h" + +//-------------------------------------------------------------- +void ofApp::setup(){ + + mesh.setMode(OF_PRIMITIVE_LINES); + mesh.enableColors(); + mesh.enableIndices(); + + ofVec3f eyeLeftTop(50.0, 25.0, 0.0); + ofVec3f eyeLeftBottom(50.0, 50.0, 0.0); + ofVec3f eyeRightTop(100.0, 25.0, 0.0); + ofVec3f eyeRightBottom(100.0, 50.0, 0.0); + ofVec3f mouthLeft(50.0, 75.0, 0.0); + ofVec3f mouthMiddle(75.0, 100.0, 0.0); + ofVec3f mouthRight(100.0, 75.0, 0.0); + + mesh.addVertex(eyeLeftTop); + mesh.addVertex(eyeLeftBottom); + mesh.addIndex(0); + mesh.addIndex(1); + mesh.addColor(ofFloatColor(0.0, 1.0, 1.0)); + mesh.addColor(ofFloatColor(0.0, 1.0, 1.0)); + + mesh.addVertex(eyeRightTop); + mesh.addVertex(eyeRightBottom); + mesh.addIndex(2); + mesh.addIndex(3); + mesh.addColor(ofFloatColor(0.0, 1.0, 1.0)); + mesh.addColor(ofFloatColor(0.0, 1.0, 1.0)); + + mesh.addVertex(mouthLeft); + mesh.addVertex(mouthMiddle); + mesh.addVertex(mouthRight); + mesh.addIndex(4); + mesh.addIndex(5); + mesh.addIndex(5); + mesh.addIndex(6); + mesh.addColor(ofFloatColor(0.0, 1.0, 0.0)); + mesh.addColor(ofFloatColor(0.0, 1.0, 0.0)); + mesh.addColor(ofFloatColor(0.0, 1.0, 0.0)); + + ofBackground(0); +} + +//-------------------------------------------------------------- +void ofApp::update(){ + +} + +//-------------------------------------------------------------- +void ofApp::draw(){ + mesh.draw(); +} + diff --git a/12_generativeMesh/02_meshIndices/src/ofApp.h b/12_generativeMesh/02_meshIndices/src/ofApp.h new file mode 100644 index 0000000..c6ed9ad --- /dev/null +++ b/12_generativeMesh/02_meshIndices/src/ofApp.h @@ -0,0 +1,13 @@ +#pragma once + +#include "ofMain.h" + +class ofApp : public ofBaseApp{ + + public: + void setup(); + void update(); + void draw(); + + ofMesh mesh; +}; diff --git a/12_generativeMesh/03_meshLines/addons.make b/12_generativeMesh/03_meshFromImage/addons.make similarity index 100% rename from 12_generativeMesh/03_meshLines/addons.make rename to 12_generativeMesh/03_meshFromImage/addons.make diff --git a/12_generativeMesh/03_meshLines/bin/data/.gitkeep b/12_generativeMesh/03_meshFromImage/bin/data/.gitkeep similarity index 100% rename from 12_generativeMesh/03_meshLines/bin/data/.gitkeep rename to 12_generativeMesh/03_meshFromImage/bin/data/.gitkeep diff --git a/12_generativeMesh/02_meshFromImage/bin/data/stars.png b/12_generativeMesh/03_meshFromImage/bin/data/stars.png similarity index 100% rename from 12_generativeMesh/02_meshFromImage/bin/data/stars.png rename to 12_generativeMesh/03_meshFromImage/bin/data/stars.png diff --git a/12_generativeMesh/02_meshFromImage/src/main.cpp b/12_generativeMesh/03_meshFromImage/src/main.cpp similarity index 100% rename from 12_generativeMesh/02_meshFromImage/src/main.cpp rename to 12_generativeMesh/03_meshFromImage/src/main.cpp diff --git a/12_generativeMesh/02_meshFromImage/src/ofApp.cpp b/12_generativeMesh/03_meshFromImage/src/ofApp.cpp similarity index 61% rename from 12_generativeMesh/02_meshFromImage/src/ofApp.cpp rename to 12_generativeMesh/03_meshFromImage/src/ofApp.cpp index 9d1d784..280b361 100644 --- a/12_generativeMesh/02_meshFromImage/src/ofApp.cpp +++ b/12_generativeMesh/03_meshFromImage/src/ofApp.cpp @@ -2,13 +2,15 @@ //-------------------------------------------------------------- void ofApp::setup(){ - bool succ = true; - succ = image.load("stars.png"); - if (!succ) { + // Do a little extra error checking to see if the image was + // loaded properly. This is not in the chapter text. + bool wasImageLoaded = image.load("stars.png"); + if (!wasImageLoaded) { cerr << "loading image failed ...\n"; } mesh.setMode(OF_PRIMITIVE_POINTS); + mesh.enableColors(); float intensityThreshold = 150.0; int w = image.getWidth(); @@ -20,6 +22,8 @@ void ofApp::setup(){ if (intensity >= intensityThreshold) { ofVec3f pos(x, y, 0.0); mesh.addVertex(pos); + // When addColor(...), the mesh will automatically convert + // the ofColor to an ofFloatColor mesh.addColor(c); } } @@ -33,6 +37,8 @@ void ofApp::update(){ //-------------------------------------------------------------- void ofApp::draw(){ - ofBackground(0,0,255); + ofColor centerColor = ofColor(85, 78, 68); + ofColor edgeColor(0, 0, 0); + ofBackgroundGradient(centerColor, edgeColor, OF_GRADIENT_CIRCULAR); mesh.draw(); } diff --git a/12_generativeMesh/02_meshFromImage/src/ofApp.h b/12_generativeMesh/03_meshFromImage/src/ofApp.h similarity index 100% rename from 12_generativeMesh/02_meshFromImage/src/ofApp.h rename to 12_generativeMesh/03_meshFromImage/src/ofApp.h diff --git a/12_generativeMesh/04_mesh3d/addons.make b/12_generativeMesh/04_meshLines/addons.make similarity index 100% rename from 12_generativeMesh/04_mesh3d/addons.make rename to 12_generativeMesh/04_meshLines/addons.make diff --git a/12_generativeMesh/04_mesh3d/bin/data/.gitkeep b/12_generativeMesh/04_meshLines/bin/data/.gitkeep similarity index 100% rename from 12_generativeMesh/04_mesh3d/bin/data/.gitkeep rename to 12_generativeMesh/04_meshLines/bin/data/.gitkeep diff --git a/12_generativeMesh/03_meshLines/bin/data/stars.png b/12_generativeMesh/04_meshLines/bin/data/stars.png similarity index 100% rename from 12_generativeMesh/03_meshLines/bin/data/stars.png rename to 12_generativeMesh/04_meshLines/bin/data/stars.png diff --git a/12_generativeMesh/03_meshLines/src/main.cpp b/12_generativeMesh/04_meshLines/src/main.cpp similarity index 100% rename from 12_generativeMesh/03_meshLines/src/main.cpp rename to 12_generativeMesh/04_meshLines/src/main.cpp diff --git a/12_generativeMesh/03_meshLines/src/ofApp.cpp b/12_generativeMesh/04_meshLines/src/ofApp.cpp similarity index 80% rename from 12_generativeMesh/03_meshLines/src/ofApp.cpp rename to 12_generativeMesh/04_meshLines/src/ofApp.cpp index 76b9456..8bf5c85 100644 --- a/12_generativeMesh/03_meshLines/src/ofApp.cpp +++ b/12_generativeMesh/04_meshLines/src/ofApp.cpp @@ -2,13 +2,17 @@ //-------------------------------------------------------------- void ofApp::setup(){ - bool succ = true; - succ = image.load("stars.png"); - if (!succ) { + // Do a little extra error checking to see if the image was + // loaded properly. This is not in the chapter text. + bool wasImageLoaded = image.load("stars.png"); + if (!wasImageLoaded) { cerr << "loading image failed ...\n"; } image.resize(200, 200); + mesh.setMode(OF_PRIMITIVE_LINES); + mesh.enableColors(); + mesh.enableIndices(); float intensityThreshold = 150.0; int w = image.getWidth(); @@ -35,6 +39,8 @@ void ofApp::setup(){ ofVec3f vertb = mesh.getVertex(b); float distance = verta.distance(vertb); if (distance <= connectionDistance) { + // In OF_PRIMITIVE_LINES, every pair of vertices or indices will be + // connected to form a line mesh.addIndex(a); mesh.addIndex(b); } diff --git a/12_generativeMesh/03_meshLines/src/ofApp.h b/12_generativeMesh/04_meshLines/src/ofApp.h similarity index 100% rename from 12_generativeMesh/03_meshLines/src/ofApp.h rename to 12_generativeMesh/04_meshLines/src/ofApp.h diff --git a/12_generativeMesh/05_mesh3dJitter/addons.make b/12_generativeMesh/05_mesh3d/addons.make similarity index 100% rename from 12_generativeMesh/05_mesh3dJitter/addons.make rename to 12_generativeMesh/05_mesh3d/addons.make diff --git a/12_generativeMesh/05_mesh3dJitter/bin/data/.gitkeep b/12_generativeMesh/05_mesh3d/bin/data/.gitkeep similarity index 100% rename from 12_generativeMesh/05_mesh3dJitter/bin/data/.gitkeep rename to 12_generativeMesh/05_mesh3d/bin/data/.gitkeep diff --git a/12_generativeMesh/04_mesh3d/bin/data/stars.png b/12_generativeMesh/05_mesh3d/bin/data/stars.png similarity index 100% rename from 12_generativeMesh/04_mesh3d/bin/data/stars.png rename to 12_generativeMesh/05_mesh3d/bin/data/stars.png diff --git a/12_generativeMesh/04_mesh3d/src/main.cpp b/12_generativeMesh/05_mesh3d/src/main.cpp similarity index 100% rename from 12_generativeMesh/04_mesh3d/src/main.cpp rename to 12_generativeMesh/05_mesh3d/src/main.cpp diff --git a/12_generativeMesh/04_mesh3d/src/ofApp.cpp b/12_generativeMesh/05_mesh3d/src/ofApp.cpp similarity index 78% rename from 12_generativeMesh/04_mesh3d/src/ofApp.cpp rename to 12_generativeMesh/05_mesh3d/src/ofApp.cpp index 29634d3..6538374 100644 --- a/12_generativeMesh/04_mesh3d/src/ofApp.cpp +++ b/12_generativeMesh/05_mesh3d/src/ofApp.cpp @@ -2,13 +2,17 @@ //-------------------------------------------------------------- void ofApp::setup(){ - bool succ = true; - succ = image.load("stars.png"); - if (!succ) { + // Do a little extra error checking to see if the image was + // loaded properly. This is not in the chapter text. + bool wasImageLoaded = image.load("stars.png"); + if (!wasImageLoaded) { cerr << "loading image failed ...\n"; } image.resize(200, 200); + mesh.setMode(OF_PRIMITIVE_LINES); + mesh.enableColors(); + mesh.enableIndices(); float intensityThreshold = 150.0; int w = image.getWidth(); @@ -17,9 +21,9 @@ void ofApp::setup(){ for (int y=0; y= intensityThreshold) { float saturation = c.getSaturation(); + // Z-coordinate shift depends on the pixel's color saturation float z = ofMap(saturation, 0, 255, -100, 100); ofVec3f pos(x*4, y*4, z); mesh.addVertex(pos); @@ -36,6 +40,8 @@ void ofApp::setup(){ ofVec3f vertb = mesh.getVertex(b); float distance = verta.distance(vertb); if (distance <= connectionDistance) { + // In OF_PRIMITIVE_LINES, every pair of vertices or indices will be + // connected to form a line mesh.addIndex(a); mesh.addIndex(b); } diff --git a/12_generativeMesh/04_mesh3d/src/ofApp.h b/12_generativeMesh/05_mesh3d/src/ofApp.h similarity index 100% rename from 12_generativeMesh/04_mesh3d/src/ofApp.h rename to 12_generativeMesh/05_mesh3d/src/ofApp.h diff --git a/12_generativeMesh/06_mesh3dJitter/05_mesh3dJitter.VC.opendb b/12_generativeMesh/06_mesh3dJitter/05_mesh3dJitter.VC.opendb new file mode 100644 index 0000000000000000000000000000000000000000..bee198e8791999ae642fb56a6f47abb5ebc38ecd GIT binary patch literal 54 zcmWN@u?c`M006K&)WM|}s0a><^#P%RQaUO4z8wOoZpG= intensityThreshold) { float saturation = c.getSaturation(); + // Z-coordinate shift depends on the pixel's color saturation float z = ofMap(saturation, 0, 255, -100, 100); ofVec3f pos(x*4, y*4, z); mesh.addVertex(pos); mesh.addColor(c); + // Create "offsets" that will allow us to move the x, y and z + // coordinates of each vertex independently using noise + offsets.push_back(ofVec3f(ofRandom(0, 100000), ofRandom(0, 100000), ofRandom(0, 100000))); } } } @@ -39,33 +46,13 @@ void ofApp::setup(){ ofVec3f vertb = mesh.getVertex(b); float distance = verta.distance(vertb); if (distance <= connectionDistance) { + // In OF_PRIMITIVE_LINES, every pair of vertices or indices will be + // connected to form a line mesh.addIndex(a); mesh.addIndex(b); } } - } - - - - for (int x=0; x= intensityThreshold) { - float saturation = c.getSaturation(); - float z = ofMap(saturation, 0, 255, -100, 100); - ofVec3f pos(x*4, y*4, z); - mesh.addVertex(pos); - mesh.addColor(c); - - // And add this line: - // It will create a ofVec3f with 3 random values - // These will allow us to move the x, y and z coordinates of each vertex independently - offsets.push_back(ofVec3f(ofRandom(0,100000), ofRandom(0,100000), ofRandom(0,100000))); - } - } - } - + } } //-------------------------------------------------------------- diff --git a/12_generativeMesh/05_mesh3dJitter/src/ofApp.h b/12_generativeMesh/06_mesh3dJitter/src/ofApp.h similarity index 100% rename from 12_generativeMesh/05_mesh3dJitter/src/ofApp.h rename to 12_generativeMesh/06_mesh3dJitter/src/ofApp.h diff --git a/12_generativeMesh/07_meshOrbit/06_meshOrbit.VC.opendb b/12_generativeMesh/07_meshOrbit/06_meshOrbit.VC.opendb new file mode 100644 index 0000000000000000000000000000000000000000..bee198e8791999ae642fb56a6f47abb5ebc38ecd GIT binary patch literal 54 zcmWN@u?c`M006K&)WM|}s0a><^#P%RQaUO4z8wOoZpG= intensityThreshold) { float saturation = c.getSaturation(); + // Z-coordinate shift depends on the pixel's color saturation float z = ofMap(saturation, 0, 255, -100, 100); - ofVec3f pos(x*4, y*4, z); + ofVec3f pos(x * 4, y * 4, z); mesh.addVertex(pos); mesh.addColor(c); + // Create "offsets" that will allow us to move the x, y and z + // coordinates of each vertex independently using noise + offsets.push_back(ofVec3f(ofRandom(0, 100000), ofRandom(0, 100000), ofRandom(0, 100000))); } } } @@ -39,35 +46,23 @@ void ofApp::setup(){ ofVec3f vertb = mesh.getVertex(b); float distance = verta.distance(vertb); if (distance <= connectionDistance) { + // In OF_PRIMITIVE_LINES, every pair of vertices or indices will be + // connected to form a line mesh.addIndex(a); mesh.addIndex(b); } } - } - - - - for (int x=0; x= intensityThreshold) { - float saturation = c.getSaturation(); - float z = ofMap(saturation, 0, 255, -100, 100); - ofVec3f pos(x*4, y*4, z); - mesh.addVertex(pos); - mesh.addColor(c); - - // And add this line: - // It will create a ofVec3f with 3 random values - // These will allow us to move the x, y and z coordinates of each vertex independently - offsets.push_back(ofVec3f(ofRandom(0,100000), ofRandom(0,100000), ofRandom(0,100000))); - } - } - } - + } + // We need the "center" of our mesh - this is what we rotate around meshCentroid = mesh.getCentroid(); + + // Now that we know our centroid, we need to know the polar coordinates (distance and angle) + // of each vertex relative to that center point. + // We've found the distance between points before, but what about the angle...? + // atan2(y, x) takes an x and y value and returns the angle relative to the + // origin (0,0). If we want the angle between two points (x1, y1) and (x2, y2) + // then we just need to use atan2(y2-y1, x2-x1). for (int i=0; i= intensityThreshold) { float saturation = c.getSaturation(); + // Z-coordinate shift depends on the pixel's color saturation float z = ofMap(saturation, 0, 255, -100, 100); - ofVec3f pos(x*4, y*4, z); + ofVec3f pos(x * 4, y * 4, z); mesh.addVertex(pos); mesh.addColor(c); + // Create "offsets" that will allow us to move the x, y and z + // coordinates of each vertex independently using noise + offsets.push_back(ofVec3f(ofRandom(0, 100000), ofRandom(0, 100000), ofRandom(0, 100000))); } } } @@ -39,48 +46,31 @@ void ofApp::setup(){ ofVec3f vertb = mesh.getVertex(b); float distance = verta.distance(vertb); if (distance <= connectionDistance) { + // In OF_PRIMITIVE_LINES, every pair of vertices or indices will be + // connected to form a line mesh.addIndex(a); mesh.addIndex(b); } } - } - - - - for (int x=0; x= intensityThreshold) { - float saturation = c.getSaturation(); - float z = ofMap(saturation, 0, 255, -100, 100); - ofVec3f pos(x*4, y*4, z); - mesh.addVertex(pos); - mesh.addColor(c); - - // And add this line: - // It will create a ofVec3f with 3 random values - // These will allow us to move the x, y and z coordinates of each vertex independently - offsets.push_back(ofVec3f(ofRandom(0,100000), ofRandom(0,100000), ofRandom(0,100000))); - } - } - } - + } + // We need the "center" of our mesh - this is what we rotate around meshCentroid = mesh.getCentroid(); - for (int i=0; i