Skip to content

Instantly share code, notes, and snippets.

@kashimAstro
Created May 6, 2016 15:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kashimAstro/8f5b3b5eef1927d4f0fc63c8a6b3f5ff to your computer and use it in GitHub Desktop.
Save kashimAstro/8f5b3b5eef1927d4f0fc63c8a6b3f5ff to your computer and use it in GitHub Desktop.
Menger sponge CPU ofMesh
#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