#include "ofApp.h"
//--------------------------------------------------------------
void ofApp::setup() {
ofSetFrameRate(60);
ofSetWindowTitle("openframeworks");
ofBackground(239);
ofEnableDepthTest();
this->len = 8;
for (auto x = -200; x <= 200; x += this->len) {
for (auto y = -200; y <= 200; y += this->len) {
for (auto z = -200; z <= 200; z += this->len) {
this->box_location_list.push_back(glm::vec3(x, y, z));
this->alpah_param_list.push_back(0);
}
}
}
this->frame_mesh.setMode(ofPrimitiveMode::OF_PRIMITIVE_LINES);
}
//--------------------------------------------------------------
void ofApp::update() {
ofSeedRandom(39);
this->face_mesh.clear();
this->frame_mesh.clear();
auto noise_location = glm::vec3(
ofMap(ofNoise(ofRandom(1000), ofGetFrameNum() * 0.01), 0, 1, -200, 200),
ofMap(ofNoise(ofRandom(1000), ofGetFrameNum() * 0.01), 0, 1, -200, 200),
ofMap(ofNoise(ofRandom(1000), ofGetFrameNum() * 0.01), 0, 1, -200, 200));
for (int i = 0; i < this->box_location_list.size(); i++) {
auto distance = glm::distance(this->box_location_list[i], noise_location);
if (distance < 25) {
this->alpah_param_list[i] = 100;
}
else {
this->alpah_param_list[i] = this->alpah_param_list[i] > 0 ? this->alpah_param_list[i] - 1 : 0;
}
}
for (int i = 0; i < this->box_location_list.size(); i++) {
if (this->alpah_param_list[i] > 0) {
this->setBoxToMesh(this->face_mesh, this->frame_mesh, this->box_location_list[i], this->len, ofColor(39, this->alpah_param_list[i] > 50 ? 255 : ofMap(this->alpah_param_list[i], 50, 0, 255, 0)));
}
}
}
//--------------------------------------------------------------
void ofApp::draw() {
this->cam.begin();
ofRotateY(ofGetFrameNum() * 0.25);
ofRotateX(ofGetFrameNum() * 0.15);
this->face_mesh.drawFaces();
this->frame_mesh.drawWireframe();
this->cam.end();
}
//--------------------------------------------------------------
void ofApp::setBoxToMesh(ofMesh& face_target, ofMesh& frame_target, glm::vec3 location, float size, ofColor color) {
this->setBoxToMesh(face_target, frame_target, location, size, size, size, color);
}
//--------------------------------------------------------------
void ofApp::setBoxToMesh(ofMesh& face_target, ofMesh& frame_target, glm::vec3 location, float height, float width, float depth, ofColor color) {
int index = face_target.getVertices().size();
face_target.addVertex(location + glm::vec3(width * -0.5 * 0.99, height * 0.5 * 0.99, depth * -0.5 * 0.99));
face_target.addVertex(location + glm::vec3(width * 0.5 * 0.99, height * 0.5 * 0.99, depth * -0.5 * 0.99));
face_target.addVertex(location + glm::vec3(width * 0.5 * 0.99, height * 0.5 * 0.99, depth * 0.5 * 0.99));
face_target.addVertex(location + glm::vec3(width * -0.5 * 0.99, height * 0.5 * 0.99, depth * 0.5 * 0.99));
face_target.addVertex(location + glm::vec3(width * -0.5 * 0.99, height * -0.5 * 0.99, depth * -0.5 * 0.99));
face_target.addVertex(location + glm::vec3(width * 0.5 * 0.99, height * -0.5 * 0.99, depth * -0.5 * 0.99));
face_target.addVertex(location + glm::vec3(width * 0.5 * 0.99, height * -0.5 * 0.99, depth * 0.5 * 0.99));
face_target.addVertex(location + glm::vec3(width * -0.5 * 0.99, height * -0.5 * 0.99, depth * 0.5 * 0.99));
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);
for (int i = 0; i < 8; i++) {
face_target.addColor(color);
frame_target.addColor(ofColor(239));
}
}
//--------------------------------------------------------------
int main() {
ofSetupOpenGL(710, 720, OF_WINDOW);
ofRunApp(new ofApp());
}