[ Video ]
[ About ]
100フレーム後に死ぬランダムウォーク。3次元版。
100 frame random workers. 3D edition.
[ 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 26 27 28 29 30 |
#pragma once #include "ofMain.h" #include "Actor.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) {}; ofEasyCam cam; vector<glm::vec3> location_list; vector<vector<int>> next_index_list; vector<unique_ptr<Actor>> actor_list; }; |
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 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(60); ofSetWindowTitle("openFrameworks"); ofBackground(0); ofSetLineWidth(1); ofEnableDepthTest(); auto span = 40; for (int x = -200; x <= 200; x += span) { for (int y = -200; y <= 200; y += span) { for (int z = -200; z <= 200; z += span) { this->location_list.push_back(glm::vec3(x, y, z)); } } } for (auto& location : this->location_list) { vector<int> next_index = vector<int>(); int index = -1; for (auto& other : this->location_list) { index++; if (location == other) { continue; } float distance = glm::distance(location, other); if (distance <= span) { next_index.push_back(index); } } this->next_index_list.push_back(next_index); } } //-------------------------------------------------------------- void ofApp::update() { int frame_span = 15; int prev_index_size = 0; this->actor_list.push_back(make_unique<Actor>(this->location_list, this->next_index_list)); for (auto& actor : this->actor_list) { actor->update(frame_span, this->location_list, this->next_index_list); } for (int i = this->actor_list.size() - 1; i >= 0; i--) { if (this->actor_list[i]->isDead()) { this->actor_list.erase(this->actor_list.begin() + i); } } } //-------------------------------------------------------------- void ofApp::draw() { this->cam.begin(); ofRotate(90); ofRotateY(180); ofRotateX(ofGetFrameNum() * 0.5); for (auto& actor : this->actor_list) { actor->draw(); } this->cam.end(); } //-------------------------------------------------------------- int main() { ofSetupOpenGL(720, 720, OF_WINDOW); ofRunApp(new ofApp()); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
#pragma once #include "ofMain.h" class Actor { public: Actor(vector<glm::vec3>& location_list, vector<vector<int>>& next_index_list); void update(int& frame_span, vector<glm::vec3>& location_list, vector<vector<int>>& next_index_list); void draw(); bool isDead(); private: int select_index; int next_index; int life; glm::vec3 location; std::deque<glm::vec3> log; }; |