#include "ofApp.h"
//--------------------------------------------------------------
void ofApp::setup() {
ofSetFrameRate(60);
ofSetWindowTitle("openframeworks");
ofBackground(239);
ofSetLineWidth(2);
ofEnableDepthTest();
this->frame.setMode(ofPrimitiveMode::OF_PRIMITIVE_LINES);
}
//--------------------------------------------------------------
void ofApp::update() {
this->face.clear();
this->frame.clear();
auto span = 15;
auto max_height = 300;
auto threshold = (int)ofGetFrameNum() % 480 - 30;
for (auto x = -300; x <= 300; x += span) {
for (auto y = -300; y <= 300; y += span) {
auto len = ofMap(ofNoise(x * 0.005, y * 0.005, -300, ofGetFrameNum() * 0.01), 0, 1, 0, max_height);
this->setBoxToMesh(this->face, this->frame, glm::vec3(x, y, -300 + len * 0.5), span, span, len);
len = max_height - len;
this->setBoxToMesh(this->face, this->frame, glm::vec3(x, y, 300 - len * 0.5), span, span, len);
}
}
}
//--------------------------------------------------------------
void ofApp::draw() {
this->cam.begin();
ofRotateX(270);
ofRotateZ(ofGetFrameNum() * 0.5);
ofSetColor(239);
this->face.draw();
ofSetColor(39);
this->frame.drawWireframe();
this->cam.end();
}
//--------------------------------------------------------------
void ofApp::setBoxToMesh(ofMesh& face_target, ofMesh& frame_target, glm::vec3 location, float size) {
this->setBoxToMesh(face_target, frame_target, location, size, size, size);
}
//--------------------------------------------------------------
void ofApp::setBoxToMesh(ofMesh& face_target, ofMesh& frame_target, glm::vec3 location, float height, float width, float depth) {
int index = face_target.getVertices().size();
face_target.addVertex(location + glm::vec3(width * -0.5 * 0.999, height * 0.5 * 0.999, depth * -0.5 * 0.999));
face_target.addVertex(location + glm::vec3(width * 0.5 * 0.999, height * 0.5 * 0.999, depth * -0.5 * 0.999));
face_target.addVertex(location + glm::vec3(width * 0.5 * 0.999, height * 0.5 * 0.999, depth * 0.5 * 0.999));
face_target.addVertex(location + glm::vec3(width * -0.5 * 0.999, height * 0.5 * 0.999, depth * 0.5 * 0.999));
face_target.addVertex(location + glm::vec3(width * -0.5 * 0.999, height * -0.5 * 0.999, depth * -0.5 * 0.999));
face_target.addVertex(location + glm::vec3(width * 0.5 * 0.999, height * -0.5 * 0.999, depth * -0.5 * 0.999));
face_target.addVertex(location + glm::vec3(width * 0.5 * 0.999, height * -0.5 * 0.999, depth * 0.5 * 0.999));
face_target.addVertex(location + glm::vec3(width * -0.5 * 0.999, height * -0.5 * 0.999, depth * 0.5 * 0.999));
face_target.addIndex(index + 0); face_target.addIndex(index + 1); face_target.addIndex(index + 2);
face_target.addIndex(index + 0); face_target.addIndex(index + 2); face_target.addIndex(index + 3);
face_target.addIndex(index + 4); face_target.addIndex(index + 5); face_target.addIndex(index + 6);
face_target.addIndex(index + 4); face_target.addIndex(index + 6); face_target.addIndex(index + 7);
face_target.addIndex(index + 0); face_target.addIndex(index + 4); face_target.addIndex(index + 1);
face_target.addIndex(index + 4); face_target.addIndex(index + 5); face_target.addIndex(index + 1);
face_target.addIndex(index + 1); face_target.addIndex(index + 5); face_target.addIndex(index + 6);
face_target.addIndex(index + 6); face_target.addIndex(index + 2); face_target.addIndex(index + 1);
face_target.addIndex(index + 2); face_target.addIndex(index + 6); face_target.addIndex(index + 7);
face_target.addIndex(index + 7); face_target.addIndex(index + 3); face_target.addIndex(index + 2);
face_target.addIndex(index + 3); face_target.addIndex(index + 7); face_target.addIndex(index + 4);
face_target.addIndex(index + 4); face_target.addIndex(index + 0); face_target.addIndex(index + 3);
frame_target.addVertex(location + glm::vec3(width * -0.5, height * 0.5, depth * -0.5));
frame_target.addVertex(location + glm::vec3(width * 0.5, height * 0.5, depth * -0.5));
frame_target.addVertex(location + glm::vec3(width * 0.5, height * 0.5, depth * 0.5));
frame_target.addVertex(location + glm::vec3(width * -0.5, height * 0.5, depth * 0.5));
frame_target.addVertex(location + glm::vec3(width * -0.5, height * -0.5, depth * -0.5));
frame_target.addVertex(location + glm::vec3(width * 0.5, height * -0.5, depth * -0.5));
frame_target.addVertex(location + glm::vec3(width * 0.5, height * -0.5, depth * 0.5));
frame_target.addVertex(location + glm::vec3(width * -0.5, height * -0.5, depth * 0.5));
frame_target.addIndex(index + 0); frame_target.addIndex(index + 1);
frame_target.addIndex(index + 1); frame_target.addIndex(index + 2);
frame_target.addIndex(index + 2); frame_target.addIndex(index + 3);
frame_target.addIndex(index + 3); frame_target.addIndex(index + 0);
frame_target.addIndex(index + 4); frame_target.addIndex(index + 5);
frame_target.addIndex(index + 5); frame_target.addIndex(index + 6);
frame_target.addIndex(index + 6); frame_target.addIndex(index + 7);
frame_target.addIndex(index + 7); frame_target.addIndex(index + 4);
frame_target.addIndex(index + 0); frame_target.addIndex(index + 4);
frame_target.addIndex(index + 1); frame_target.addIndex(index + 5);
frame_target.addIndex(index + 2); frame_target.addIndex(index + 6);
frame_target.addIndex(index + 3); frame_target.addIndex(index + 7);
}
//--------------------------------------------------------------
int main() {
ofSetupOpenGL(1280, 720, OF_WINDOW);
ofRunApp(new ofApp());
}