[ Video ]
[ About ]
3次元の座標4点を結んで四角形(?)を生成
Connect the coordinates(3D) of 4 points with a line.
[ 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; float noise_seed; }; |
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 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(60); ofSetWindowTitle("openFrameworks"); ofBackground(39); ofSetColor(239); ofEnableDepthTest(); this->noise_seed = 0; } //-------------------------------------------------------------- void ofApp::update() { ofSeedRandom(10); if (ofGetFrameNum() % 60 < 45) { this->noise_seed += ofMap(ofGetFrameNum() % 60, 0, 45, 0.03, 0); } } //-------------------------------------------------------------- void ofApp::draw() { this->cam.begin(); ofRotateY(ofGetFrameNum() * 0.2); int span = 240; int range = 80; for (int x = -ofGetWidth() * 0.5; x <= ofGetWidth() * 0.5; x += span) { for (int y = -ofGetHeight() * 0.5; y <= ofGetHeight() * 0.5; y += span) { for (int z = -ofGetHeight() * 0.5; z <= ofGetHeight() * 0.5; z += span) { ofPushMatrix(); ofTranslate(x, y, z); ofFill(); glm::vec3 top_point, prev_point; int number_of_point = 4; for (int i = 0; i < number_of_point; i++) { glm::vec3 point = glm::vec3( ofMap(ofNoise(ofRandom(10000), this->noise_seed), 0, 1, -range * 0.5, range * 0.5), ofMap(ofNoise(ofRandom(10000), this->noise_seed), 0, 1, -range * 0.5, range * 0.5), ofMap(ofNoise(ofRandom(10000), this->noise_seed), 0, 1, -range * 0.5, range * 0.5)); ofDrawSphere(point, 5); if (i != 0) { ofDrawLine(prev_point, point); } else { top_point = point; } prev_point = point; } ofDrawLine(top_point, prev_point); ofPopMatrix(); } } } this->cam.end(); } //-------------------------------------------------------------- int main() { ofSetupOpenGL(720, 720, OF_WINDOW); ofRunApp(new ofApp()); } |