Well, OK. But I’ve warned you, it’s all really basic boring stuff based on this chapter:
http://openframeworks.cc/ofBook/chapters/OOPs!.html
I stripped it down as it’s pretty wild at the moment as I’m learning.
// ofApp.h
Shape shapes[NSHAPES];
// ofApp.cpp
void ofApp::setup() {
for(int i = 0; i < NSHAPES; i++)
shapes[i].setup(i, ofGetWidth() / 2, ofGetHeight() / 2, SHAPE_SIZE - i * shapeSizeOffset, SHAPE_SIZE - i * shapeSizeOffset);
}
void ofApp::update() {
for(int i = 0; i < NSHAPES; i++) {
shapes[i].update();
shapes[i].bumpSize = 0.25 * lfo1value;
if(fmod(i, 2) == 0)
shapes[i].doRotate(angle);
else
shapes[i].doRotate(-angle);
}
}
void ofApp::draw() {
for(int i = 0; i < NSHAPES; i++)
shapes[i].draw();
}
// Shape.cpp
void Shape::setup(int id, float x, float y, float w, float h) {
this->id = id;
this->x = x;
this->y = y;
this->w = w;
this->h = h;
}
void Shape::update(float x, float y, float w, float h) {
this->x = x;
this->y = y;
this->w = w;
this->h = h;
}
void Shape::update() {
bumpSize = ofMap(sin(ofGetElapsedTimef()), -1, 1, 0.0, 0.25);
}
void Shape::draw() {
ofPushMatrix();
ofPushStyle();
ofTranslate(ofGetWidth() / 2, ofGetHeight() / 2);
ofRotate(currentRotation);
ofSetColor(currentColor);
ofDrawRectRounded(0, 0, w, h, cornerRadius);
ofDrawTriangle(0, -h/2, -w/2, h/2, w/2, h/2);
float bumpW = ofMap(bumpSize, 0.0, 1.0, 0.0, w / 2);
float bumpH = ofMap(bumpSize, 0.0, 1.0, 0.0, h / 2);
if (show_bump) {
ofDrawRectRounded(0, 0 - h / 2, bumpW, bumpH, cornerRadiusBumps);
ofDrawRectRounded(0, h / 2, bumpW, bumpH, cornerRadiusBumps);
ofDrawRectRounded(0 - w / 2, 0, bumpW, bumpH, cornerRadiusBumps);
ofDrawRectRounded(w / 2, 0, bumpW, bumpH, cornerRadiusBumps);
}
ofPopStyle();
ofPopMatrix();
}
This produces the results expected, drawing many of basic shapes on top of one another with slight rotations resulting in one weird shape. Reading that under the hood “…The ofPath class uses tessellation to turn its paths into openGL-ready shapes …” (ofTessellator.h line 11), left me wondering …
Should I clamp things like an LFO or the angle used to apply rotation cause they are causing trouble down the line?
Can I do try-catch or similar to avoid a crash and skip the frame?
Aaany hints how I could solve this are much appreciated 