#include "ofApp.h"
//--------------------------------------------------------------
void ofApp::setup() {
ofSetFrameRate(60);
ofSetWindowTitle("openFrameworks");
ofBackground(0);
ofSetLineWidth(1);
ofEnableDepthTest();
this->frame.setMode(ofPrimitiveMode::OF_PRIMITIVE_LINES);
int span = 60;
for (int x = -240; x <= 240; x += span) {
for (int y = -240; y <= 240; y += span) {
for (int z = -240; z <= 240; z += span) {
this->location_list.push_back(glm::vec3(x, y, z));
}
}
}
}
//--------------------------------------------------------------
void ofApp::update() {
ofSeedRandom(39);
this->face.clear();
this->frame.clear();
float size = 30;
for (int i = 0; i < this->location_list.size(); i++) {
this->setBoxToMesh(this->face, this->frame, this->location_list[i], size);
}
}
//--------------------------------------------------------------
void ofApp::draw() {
this->cam.begin();
ofRotateY(ofGetFrameNum() * 0.333333);
this->face.draw();
this->frame.drawWireframe();
for (int i = 0; i < this->frame.getNumVertices(); i++) {
ofSetColor(this->frame.getColor(i));
ofDrawSphere(this->frame.getVertex(i), 2);
}
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 face_index = face_target.getNumVertices();
int frame_index = frame_target.getNumVertices();
vector<glm::vec3> vertices;
vertices.push_back(glm::vec3(width * -0.5, height * 0.5, depth * -0.5));
vertices.push_back(glm::vec3(width * 0.5, height * 0.5, depth * -0.5));
vertices.push_back(glm::vec3(width * 0.5, height * 0.5, depth * 0.5));
vertices.push_back(glm::vec3(width * -0.5, height * 0.5, depth * 0.5));
vertices.push_back(glm::vec3(width * -0.5, height * -0.5, depth * -0.5));
vertices.push_back(glm::vec3(width * 0.5, height * -0.5, depth * -0.5));
vertices.push_back(glm::vec3(width * 0.5, height * -0.5, depth * 0.5));
vertices.push_back(glm::vec3(width * -0.5, height * -0.5, depth * 0.5));
ofColor color;
ofSeedRandom(39);
auto seed = glm::vec3(ofRandom(1000), ofRandom(2000, 3000), ofRandom(4000, 5000));
for (auto& vertex : vertices) {
face_target.addVertex(location + vertex * 0.99);
frame_target.addVertex(location + vertex);
color.setHsb(
ofMap(ofNoise(glm::vec4((location + vertex) * 0.0035, seed.x + ofGetFrameNum() * 0.005)), 0, 1, 168, 255),
ofMap(ofNoise(glm::vec4((location + vertex) * 0.0035, seed.y + ofGetFrameNum() * 0.005)), 0, 1, 100, 255),
ofMap(ofNoise(glm::vec4((location + vertex) * 0.0035, seed.z + ofGetFrameNum() * 0.005)), 0, 1, 100, 255));
face_target.addColor(color);
color.setHsb(ofMap(ofNoise(glm::vec4((location + vertex) * 0.0035, seed.x + ofGetFrameNum() * 0.005)), 0, 1, 168, 255), 255, 255);
frame_target.addColor(color);
}
face_target.addIndex(face_index + 0); face_target.addIndex(face_index + 1); face_target.addIndex(face_index + 2);
face_target.addIndex(face_index + 0); face_target.addIndex(face_index + 2); face_target.addIndex(face_index + 3);
face_target.addIndex(face_index + 4); face_target.addIndex(face_index + 5); face_target.addIndex(face_index + 6);
face_target.addIndex(face_index + 4); face_target.addIndex(face_index + 6); face_target.addIndex(face_index + 7);
face_target.addIndex(face_index + 0); face_target.addIndex(face_index + 4); face_target.addIndex(face_index + 1);
face_target.addIndex(face_index + 4); face_target.addIndex(face_index + 5); face_target.addIndex(face_index + 1);
face_target.addIndex(face_index + 1); face_target.addIndex(face_index + 5); face_target.addIndex(face_index + 6);
face_target.addIndex(face_index + 6); face_target.addIndex(face_index + 2); face_target.addIndex(face_index + 1);
face_target.addIndex(face_index + 2); face_target.addIndex(face_index + 6); face_target.addIndex(face_index + 7);
face_target.addIndex(face_index + 7); face_target.addIndex(face_index + 3); face_target.addIndex(face_index + 2);
face_target.addIndex(face_index + 3); face_target.addIndex(face_index + 7); face_target.addIndex(face_index + 4);
face_target.addIndex(face_index + 4); face_target.addIndex(face_index + 0); face_target.addIndex(face_index + 3);
frame_target.addIndex(frame_index + 0); frame_target.addIndex(frame_index + 1);
frame_target.addIndex(frame_index + 1); frame_target.addIndex(frame_index + 2);
frame_target.addIndex(frame_index + 2); frame_target.addIndex(frame_index + 3);
frame_target.addIndex(frame_index + 3); frame_target.addIndex(frame_index + 0);
frame_target.addIndex(frame_index + 4); frame_target.addIndex(frame_index + 5);
frame_target.addIndex(frame_index + 5); frame_target.addIndex(frame_index + 6);
frame_target.addIndex(frame_index + 6); frame_target.addIndex(frame_index + 7);
frame_target.addIndex(frame_index + 7); frame_target.addIndex(frame_index + 4);
frame_target.addIndex(frame_index + 0); frame_target.addIndex(frame_index + 4);
frame_target.addIndex(frame_index + 1); frame_target.addIndex(frame_index + 5);
frame_target.addIndex(frame_index + 2); frame_target.addIndex(frame_index + 6);
frame_target.addIndex(frame_index + 3); frame_target.addIndex(frame_index + 7);
}
//--------------------------------------------------------------
int main() {
ofSetupOpenGL(720, 720, OF_WINDOW);
ofRunApp(new ofApp());
}