Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.