Created
May 6, 2016 15:17
-
-
Save kashimAstro/8f5b3b5eef1927d4f0fc63c8a6b3f5ff to your computer and use it in GitHub Desktop.
Menger sponge CPU ofMesh
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 "ofMain.h" | |
class Menger : public ofBaseApp{ | |
public: | |
ofEasyCam cam; | |
ofMesh mesh; | |
void setup() { | |
mesh = sponge(10,10,10,500,3,2); | |
} | |
void draw() { | |
ofSetWindowTitle(ofToString(ofGetFrameRate())); | |
ofBackgroundGradient(ofColor(100),ofColor(0),OF_GRADIENT_CIRCULAR); | |
ofEnableDepthTest(); | |
cam.begin(); | |
ofSetColor(0,0,200); | |
mesh.draw(); | |
ofSetColor(0); | |
ofSetLineWidth(2.5); | |
mesh.drawWireframe(); | |
cam.end(); | |
ofDisableDepthTest(); | |
} | |
ofVboMesh mh; | |
ofVboMesh sponge(float x, float y, float z, float s, int n, int t) { | |
if(n>0) { | |
n--; | |
float u = s/t; | |
for(float i=-u; i<=u; i+=u) | |
for(float j=-u; j<=u; j+=u) | |
for(float k=-u; k<=u; k+=u) | |
if(abs(i) + abs(j) + abs(k) >= 2*u){ | |
sponge(x+i, y+j, z+k, u, n, t); | |
} | |
} | |
else { | |
ofBoxPrimitive b; | |
b.set(s); | |
for(int i = 0;i < b.getMesh().getVertices().size();i++) | |
{ | |
b.getMesh().getVertices()[i] += ofVec3f(x,y,z); | |
} | |
ofMesh m; | |
m = b.getMesh(); | |
mh.append(m); | |
} | |
return mh; | |
} | |
}; | |
int main() | |
{ | |
ofSetupOpenGL(1280, 720, OF_WINDOW); | |
ofRunApp(new Menger()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment