[ Video ]
[ About ]
初期の位置に戻ろうとするBoxと反発力があるSphereを配置。
縦・横・奥で19*19*19=6,859個のBoxがあります。(20*20*20のつもりがループ条件をミスしてますね)。Boxはクルクルと個々の動きが分かりやすくて良いですね。
手元のマシンではリアルタイムは厳しかったので、画像ファイルをフレームごとに書き出して、後でOpenCVを使って動画にエンコードしました。この辺りも興味ある方おりましたら、blog書きますのでInstagram / Twitter等でメッセージ下さい。
[ 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 31 32 33 |
#pragma once #include "ofMain.h" #include "ofxBullet.h" class ofApp : public ofBaseApp { public: ~ofApp(); 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; ofLight light; ofxBulletWorldRigid world; vector<ofxBulletBox*> boxes; vector<ofColor> bxes_color; vector<ofVec3f> boxes_location; ofVec3f hater_location; }; |
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 |
#include "ofApp.h" //-------------------------------------------------------------- ofApp::~ofApp() { for (ofxBulletBox* tmp : this->boxes) { delete tmp; } this->boxes.clear(); } //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(60); ofEnableDepthTest(); ofBackground(255); ofSetWindowTitle("Insta"); this->world.setup(); this->world.setGravity(ofVec3f(0.0, 0.0, 0.0)); float size = 15; for (float x = -150; x < 150; x += size) { for (float y = -150; y < 150; y += size) { for (float z = -150; z < 150; z += size) { ofxBulletBox* box = new ofxBulletBox(); box->create(this->world.world, ofVec3f(x, y, z), 1.0, size, size, size); box->setRestitution(1.0); box->add(); this->boxes.push_back(box); ofColor color; color.setHsb(ofRandom(255), 255, 255); this->bxes_color.push_back(color); this->boxes_location.push_back(ofVec3f(x, y, z)); } } } this->light.setPosition(ofVec3f(0, 0, 512)); ofEnableLighting(); this->light.enable(); } //-------------------------------------------------------------- void ofApp::update() { ofVec3f diff; for (int i = 0; i < this->boxes.size(); i++) { diff = this->boxes_location[i] - this->boxes[i]->getPosition(); diff *= 10; this->boxes[i]->applyCentralForce(diff); } float x = ofMap(ofNoise(ofGetFrameNum() * 0.01), 0, 1, -500, 500); float y = ofMap(ofNoise((ofGetFrameNum() + 100) * 0.01), 0, 1, -500, 500); float z = ofMap(ofNoise((ofGetFrameNum() + 200) * 0.01), 0, 1, -500, 500); this->hater_location = ofVec3f(x, y, z); for (int i = 0; i < this->boxes.size(); i++) { diff = this->boxes[i]->getPosition() - this->hater_location; if (diff.length() < 150) { diff *= ofMap(diff.length(), 0, 150, 100, 0); this->boxes[i]->applyCentralForce(diff); } } this->world.update(); } //-------------------------------------------------------------- void ofApp::draw() { this->cam.begin(); float len = 50; for (int i = 0; i < this->boxes.size(); i++) { ofSetColor(this->bxes_color[i]); this->boxes[i]->draw(); //ofDrawLine(this->boxes[i]->getPosition(), this->boxes_location[i]); } ofSetColor(0); ofDrawSphere(this->hater_location, 50); this->cam.end(); } //======================================================================== int main() { ofSetupOpenGL(720, 720, OF_WINDOW); ofRunApp(new ofApp()); } |
[ Link ]
https://github.com/junkiyoshi/Insta20180116
WebCamのimageにmask https://t.co/7MHcqDiX0N #openframeworks pic.twitter.com/q16RdGJx6L
— junkiyoshi (@junkiyoshi) 2018年1月6日