[ Video ]
[ About ]
飛び出る球体
Thorn of sphere.
[ Source ]
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 |
#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 mouseEntered(int x, int y) {}; void mouseExited(int x, int y) {}; void windowResized(int w, int h) {}; void dragEvent(ofDragInfo dragInfo) {}; void gotMessage(ofMessage msg) {}; vector<ofMeshFace> triangles; ofEasyCam cam; }; |
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 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(60); ofSetWindowTitle("openFrameworks"); ofBackground(239); ofSetLineWidth(2); ofEnableDepthTest(); auto ico_sphere = ofIcoSpherePrimitive(300, 2); this->triangles = ico_sphere.getMesh().getUniqueFaces(); } //-------------------------------------------------------------- void ofApp::update() { } //-------------------------------------------------------------- void ofApp::draw() { this->cam.begin(); ofRotateY(ofGetFrameNum() * 0.8); ofRotateX(ofGetFrameNum() * 0.3); auto threshold = 0.65f; for (auto& triangle : this->triangles) { auto base_location_a = glm::vec3(triangle.getVertex(0).x, triangle.getVertex(0).y, triangle.getVertex(0).z); auto base_location_b = glm::vec3(triangle.getVertex(1).x, triangle.getVertex(1).y, triangle.getVertex(1).z); auto base_location_c = glm::vec3(triangle.getVertex(2).x, triangle.getVertex(2).y, triangle.getVertex(2).z); auto base_avg = (base_location_a + base_location_b + base_location_c) / 3; // 隣接する図形同士で重なる部分が出てくるので調整値の分だけ縮める base_location_a = (base_location_a - base_avg) * 0.95 + base_avg; base_location_b = (base_location_b - base_avg) * 0.95 + base_avg; base_location_c = (base_location_c - base_avg) * 0.95 + base_avg; auto noise_value = ofNoise(base_avg.x * 0.005, base_avg.y * 0.005, base_avg.z * 0.005, ofGetFrameNum() * 0.0025); if (noise_value >= threshold) { auto tmp_location_a = glm::normalize(base_location_a) * ofMap(noise_value, threshold, 1.0, 300, 450); auto tmp_location_b = glm::normalize(base_location_b) * ofMap(noise_value, threshold, 1.0, 300, 450); auto tmp_location_c = glm::normalize(base_location_c) * ofMap(noise_value, threshold, 1.0, 300, 450); ofFill(); ofSetColor(239); ofBeginShape(); ofVertex(tmp_location_a); ofVertex(tmp_location_b); ofVertex(tmp_location_c); ofEndShape(true); ofBeginShape(); ofVertex(base_location_a); ofVertex(base_location_b); ofVertex(tmp_location_b); ofVertex(tmp_location_a); ofEndShape(true); ofBeginShape(); ofVertex(base_location_b); ofVertex(base_location_c); ofVertex(tmp_location_c); ofVertex(tmp_location_b); ofEndShape(true); ofBeginShape(); ofVertex(base_location_c); ofVertex(base_location_a); ofVertex(tmp_location_a); ofVertex(tmp_location_c); ofEndShape(true); ofNoFill(); ofSetColor(39); ofBeginShape(); ofVertex(tmp_location_a); ofVertex(tmp_location_b); ofVertex(tmp_location_c); ofEndShape(true); ofBeginShape(); ofVertex(base_location_a); ofVertex(base_location_b); ofVertex(tmp_location_b); ofVertex(tmp_location_a); ofEndShape(true); ofBeginShape(); ofVertex(base_location_b); ofVertex(base_location_c); ofVertex(tmp_location_c); ofVertex(tmp_location_b); ofEndShape(true); ofBeginShape(); ofVertex(base_location_c); ofVertex(base_location_a); ofVertex(tmp_location_a); ofVertex(tmp_location_c); ofEndShape(true); } else { ofFill(); ofSetColor(239); ofBeginShape(); ofVertex(base_location_a); ofVertex(base_location_b); ofVertex(base_location_c); ofEndShape(true); ofNoFill(); ofSetColor(39); ofBeginShape(); ofVertex(base_location_a); ofVertex(base_location_b); ofVertex(base_location_c); ofEndShape(true); } } this->cam.end(); } //-------------------------------------------------------------- int main() { ofSetupOpenGL(720, 720, OF_WINDOW); ofRunApp(new ofApp()); } |