[ Video ]
[ About ]
球体上の点をランダムに移動させて近接の3点で三角形を描写。ofMesh使うと描写が早い!
Triangles on 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 |
#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 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(60); ofSetWindowTitle("openframeworks"); ofBackground(0); ofEnableBlendMode(ofBlendMode::OF_BLENDMODE_ADD); } //-------------------------------------------------------------- void ofApp::update() { ofSeedRandom(39); this->mesh.clear(); for (auto i = 0; i < 700; i++) { auto location = glm::vec3( ofMap(ofNoise(ofRandom(1000), ofGetFrameNum() * 0.0005), 0, 1, -300, 300), ofMap(ofNoise(ofRandom(1000), ofGetFrameNum() * 0.0005), 0, 1, -300, 300), ofMap(ofNoise(ofRandom(1000), ofGetFrameNum() * 0.0005), 0, 1, -300, 300)); location = glm::normalize(location) * 300; this->mesh.addVertex(location); } 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 < 40) { 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.25); ofRotateX(ofGetFrameNum() * 0.125); ofSetColor(255); for (auto& location : this->mesh.getVertices()) { ofDrawSphere(location, 2); } this->mesh.drawWireframe(); ofSetColor(255, 64); this->mesh.drawFaces(); this->cam.end(); } //-------------------------------------------------------------- int main() { ofSetupOpenGL(720, 720, OF_WINDOW); ofRunApp(new ofApp()); } |