[ Video ]
[ About ]
ラインによる円柱。
Line of cylinder.
[ 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 face, frame; }; |
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 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(60); ofSetWindowTitle("openframeworks"); ofBackground(239); ofEnableDepthTest(); this->frame.setMode(ofPrimitiveMode::OF_PRIMITIVE_LINES); } //-------------------------------------------------------------- void ofApp::update() { this->face.clear(); this->frame.clear(); auto radius = 300; auto deg_span = 9; for (auto deg_start = 0; deg_start < 360; deg_start += deg_span + 1) { auto deg = deg_start; auto noise_value = ofNoise(radius * cos(deg_start * DEG_TO_RAD) * 0.002, radius * sin(deg_start * DEG_TO_RAD) * 0.002, ofGetFrameNum() * 0.008); auto max_height = ofMap(noise_value, 0.25, 0.75, 0, 1000); if (noise_value < 0.25) { max_height = 0; } else if (noise_value > 0.75) { max_height = 1000; } for (auto height = 0; height < max_height; height += 10) { int index = this->face.getNumVertices() - 2; this->face.addVertex(glm::vec3(radius * cos((deg) * DEG_TO_RAD), height, radius * sin((deg) * DEG_TO_RAD))); this->face.addVertex(glm::vec3(radius * cos((deg + deg_span) * DEG_TO_RAD), height, radius * sin((deg + deg_span) * DEG_TO_RAD))); this->frame.addVertex(glm::vec3(radius * cos(deg * DEG_TO_RAD), height, radius * sin(deg * DEG_TO_RAD))); this->frame.addVertex(glm::vec3(radius * cos((deg + deg_span) * DEG_TO_RAD), height, radius * sin((deg + deg_span) * DEG_TO_RAD))); if (height > 0) { this->face.addIndex(index); this->face.addIndex(index + 1); this->face.addIndex(index + 3); this->face.addIndex(index); this->face.addIndex(index + 2); this->face.addIndex(index + 3); this->frame.addIndex(index); this->frame.addIndex(index + 2); this->frame.addIndex(index + 1); this->frame.addIndex(index + 3); } else if (height == 0) { this->frame.addIndex(this->frame.getNumVertices() - 2); this->frame.addIndex(this->frame.getNumVertices() - 1); } deg += 5; } if (max_height > 0) { this->frame.addIndex(this->frame.getNumVertices() - 2); this->frame.addIndex(this->frame.getNumVertices() - 1); } } } //-------------------------------------------------------------- void ofApp::draw() { this->cam.begin(); ofTranslate(0, -500, 0); ofSetColor(39); this->face.drawFaces(); ofSetColor(139, 139, 239); this->frame.drawWireframe(); this->cam.end(); } //-------------------------------------------------------------- int main() { ofSetupOpenGL(720, 720, OF_WINDOW); ofRunApp(new ofApp()); } |