[ Video ]
[ About ]
昨日のヤツを3Dに改造。
Gradation triangles 3D.
[ Source ]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
#pragma once #include "ofMain.h" class ofApp : public ofBaseApp { public: void setup(); void update(); void draw(); void keyPressed(int key) {}; void keyReleased(int key) {}; void mouseMoved(int x, int y) {}; void mouseDragged(int x, int y, int button) {}; void mousePressed(int x, int y, int button) {}; void mouseReleased(int x, int y, int button) {}; void windowResized(int w, int h) {}; void dragEvent(ofDragInfo dragInfo) {}; void gotMessage(ofMessage msg) {}; ofEasyCam cam; ofMesh mesh; }; |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(60); ofSetWindowTitle("openframeworks"); ofBackground(239); ofEnableDepthTest(); } //-------------------------------------------------------------- void ofApp::update() { ofSeedRandom(39); this->mesh.clear(); auto span = 60; for (auto x = -300; x <= 300; x += span) { for (auto y = -300; y <= 300; y += span) { for (auto z = -300; z <= 300; z += span) { auto location = glm::vec3( x + ofMap(ofNoise(ofRandom(1000), ofGetFrameNum() * 0.005), 0, 1, span * 0.5, span * -0.5), y + ofMap(ofNoise(ofRandom(1000), ofGetFrameNum() * 0.005), 0, 1, span * 0.5, span * -0.5), z + ofMap(ofNoise(ofRandom(1000), ofGetFrameNum() * 0.005), 0, 1, span * 0.5, span * -0.5)); this->mesh.addVertex(location); ofColor color; color.setHsb(ofRandom(255), 255, 255, 200); this->mesh.addColor(color); } } } for (int i = 0; i < this->mesh.getVertices().size(); i++) { auto location = this->mesh.getVertices()[i]; vector<int> near_index_list; for (int k = 0; k < this->mesh.getVertices().size(); k++) { auto other = this->mesh.getVertices()[k]; auto distance = glm::distance(location, other); if (distance < span * 0.85) { near_index_list.push_back(k); } } if (near_index_list.size() >= 3) { for (int k = 0; k < near_index_list.size() - 2; k++) { this->mesh.addIndex(near_index_list[k]); this->mesh.addIndex(near_index_list[k + 1]); this->mesh.addIndex(near_index_list[k + 2]); } } } } //-------------------------------------------------------------- void ofApp::draw() { this->cam.begin(); ofRotateY(ofGetFrameNum() * 0.2); this->mesh.draw(); this->mesh.drawWireframe(); this->mesh.drawVertices(); this->cam.end(); } //-------------------------------------------------------------- int main() { ofSetupOpenGL(720, 720, OF_WINDOW); ofRunApp(new ofApp()); } |