-
-
Save jbl0ndie/34dd30b251f197464527 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include "ofMain.h" | |
ofMesh generatePieMesh( float radius, float segments ) { | |
// Create our mesh. | |
ofMesh mesh; | |
mesh.setMode( OF_PRIMITIVE_TRIANGLE_FAN ); | |
// Add the center point | |
mesh.addVertex( ofVec3f::zero() ); | |
// Say it is the first point | |
mesh.addIndex( 0 ); | |
// Add the outer points rc1 had i< segments and it missed the last segment | |
for ( float i = 0; i <= segments; ++i ) { | |
// Use our matrix to plot the points. | |
// Because I can't be bothered doing the trig :) | |
ofMatrix4x4 matrix; | |
// This is done backwards | |
// 1. Move to the outside | |
matrix.translate( 0.0f, radius, 0.0f ); | |
// 2. Make a segment the size of one segment | |
matrix.rotate( (360 / segments) * (i / segments), 0.0, 0.0, 1.0 ); | |
// 3. Invert the scale so it works clockwise | |
matrix.scale( 1.0, -1.0, 1.0 ); | |
// Create a point at zero and multiply it by our matrix | |
ofVec3f p = ofVec3f::zero() * matrix; | |
// Add the point | |
mesh.addVertex( p ); | |
// Set the point index | |
mesh.addIndex( i + 1 ); | |
} | |
return mesh; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "ofApp.h" | |
#include "generatePieMesh.h" | |
//-------------------------------------------------------------- | |
void ofApp::setup(){ | |
numClones = 72; | |
// Pre-generate a pi | |
pie = generatePieMesh( 650.0, numClones ); | |
} | |
//-------------------------------------------------------------- | |
void ofApp::draw(){ | |
// Example 2 | |
// ========= | |
ofPushMatrix(); // Background wheel matrix | |
ofPushStyle(); | |
ofTranslate(ofGetWindowWidth()/2, ofGetWindowHeight()/2); | |
ofSetColor(0); // Set back wheel to black | |
// Draw the requisite no of clones, rotating and spacing them out | |
for (int i=0; i<numClones/2; i++) { | |
glRotatef(2 *(360 / numClones), 0, 0, 1); | |
pie.draw(); | |
} | |
ofPopStyle(); | |
ofPopMatrix(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include "ofMain.h" | |
class ofApp : public ofBaseApp{ | |
public: | |
void setup(); | |
void draw(); | |
ofMesh pie; | |
float numClones; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment