1月6日にアップロードした動画にzach liebermanさんからRetweet/Comment/Likeを頂きました!いやっほーい!
zachさんはopenFrameworksの開発者で、自身もSNSに色々作品を挙げられている人です。日本語だと下記の記事が詳しいでしょうか。
詩的なコード表現の追求:ザック・リーバーマン
http://dentsulab.tokyo/article/?p=674
凄い、嬉しかったので、取り急ぎ、自慢です。
クリエイティブ・コーディングによる生成物とソース
1月6日にアップロードした動画にzach liebermanさんからRetweet/Comment/Likeを頂きました!いやっほーい!
zachさんはopenFrameworksの開発者で、自身もSNSに色々作品を挙げられている人です。日本語だと下記の記事が詳しいでしょうか。
詩的なコード表現の追求:ザック・リーバーマン
http://dentsulab.tokyo/article/?p=674
凄い、嬉しかったので、取り急ぎ、自慢です。
[ Video ]
[ About ]
ofTrueTypeFontから文字の輪郭の座標を取得して、Sphereを設置しています。
それぞれのSphereは初期位置に戻ろうとする力が常に働いていますが、LeapMotionから取得した人差指の座標にはSphereに反発する力があり、反発する力の有効範囲に入ったSphereは初期位置からずれてしまいます。反発力の有効範囲外になれば元に戻ろうとする力だけになるので、初期位置に戻ります。
Leap Motion + ofxBulletなので、もう少し3Dが分かるようにしたかったのですが、あまり上手くいきませんでしたね。
[ 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 34 35 36 37 38 39 40 41 |
#pragma once #include "ofMain.h" #include "ofxBullet.h" // Leap Motion SDK #include "Leap.h" #pragma comment(lib, "Leap.lib") 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) {}; ofCamera cam; ofLight light; ofTrueTypeFont font; ofxBulletWorldRigid world; vector<ofxBulletSphere*> spheres; vector<ofColor> spheres_color; vector<ofVec3f> spheres_location; // Leap Motion Leap::Controller leap; ofVec3f finger_position; }; |
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 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
#include "ofApp.h" //-------------------------------------------------------------- ofApp::~ofApp() { for (ofxBulletSphere* tmp : this->spheres) { delete tmp; } this->spheres.clear(); } //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(60); ofEnableDepthTest(); ofBackground(0); ofSetWindowTitle("Insta"); this->cam.setPosition(ofVec3f(0, 3.f, -30.f)); this->cam.lookAt(ofVec3f(0, 0, 0), ofVec3f(0, -1, 0)); this->world.setup(); this->world.enableGrabbing(); this->world.setCamera(&this->cam); this->world.setGravity(ofVec3f(0.0, 0.0, 0.0)); this->font.loadFont("fonts/Kazesawa-Bold.ttf", 130, true, false, true); vector<string> words; words.push_back("JUN"); words.push_back("KIYOSHI"); for (int word_index = 0; word_index < words.size(); word_index++) { ofVec2f word_size = ofVec2f(this->font.stringWidth(words[word_index]), -this->font.stringHeight(words[word_index])); vector<ofTTFCharacter> char_paths = this->font.getStringAsPoints(words[word_index]); for (int path_index = 0; path_index < char_paths.size(); path_index++) { vector<ofPolyline> outline = char_paths[path_index].getOutline(); for (int outline_index = 0; outline_index < outline.size(); outline_index++) { outline[outline_index] = outline[outline_index].getResampledBySpacing(5); vector<ofPoint> vertices = outline[outline_index].getVertices(); for (int vertices_index = 0; vertices_index < vertices.size(); vertices_index++) { ofVec3f location = vertices[vertices_index] - word_size / 2; location.y = location.y + 150 * (word_index - 1); ofxBulletSphere* sphere = new ofxBulletSphere(); ofVec3f box_location = ofVec3f(location.x, location.y, location.z); float size = 2.5; sphere->create(this->world.world, box_location, 1.0, size); sphere->setRestitution(1.0); sphere->add(); this->spheres.push_back(sphere); ofColor color; color.setHsb(ofRandom(255), 255, 255); this->spheres_color.push_back(color); this->spheres_location.push_back(box_location); } } } } } //-------------------------------------------------------------- void ofApp::update() { ofVec3f diff; for (int i = 0; i < this->spheres.size(); i++) { diff = this->spheres_location[i] - this->spheres[i]->getPosition(); diff *= 10; this->spheres[i]->applyCentralForce(diff); } Leap::Frame frame = this->leap.frame(); for (Leap::Hand hand : frame.hands()) { if(hand.isRight()){ for (Leap::Finger finger : hand.fingers()) { if (finger.type() == Leap::Finger::Type::TYPE_INDEX) { float x = ofMap(finger.tipPosition().x, -200, 200, -ofGetWidth() / 2, ofGetWidth() / 2); float y = ofMap(finger.tipPosition().y, 300, 0, -ofGetHeight() / 2, ofGetHeight() / 2); float power = finger.tipPosition().z * -1; this->finger_position = ofVec3f(x, y, 0); ofVec3f diff; for (int i = 0; i < this->spheres.size(); i++) { diff = this->finger_position - this->spheres[i]->getPosition(); if (diff.length() < power) { diff *= 5; this->spheres[i]->applyCentralForce(-diff); } } } } } } this->world.update(); } //-------------------------------------------------------------- void ofApp::draw() { ofTranslate(ofGetWidth() / 2, ofGetHeight() / 2); ofDrawBox(this->finger_position, 5); float len = 50; for (int i = 0; i < this->spheres.size(); i++) { ofSetColor(this->spheres_color[i]); this->spheres[i]->draw(); ofDrawLine(this->spheres[i]->getPosition(), this->spheres_location[i]); } } //======================================================================== int main() { ofSetupOpenGL(720, 720, OF_WINDOW); ofRunApp(new ofApp()); } |
[ Video ]
[ About ]
引き続きofxBulletを使って3D物理演算です。
Boxの中にBoxが入っていますが、距離が近いもの同士で線で結ぶようにしました。お互いの距離が近いほど濃い色、遠くなれば薄くなります。
Particleを線で繋いでいく手法は良くやるのですが、物理演算と組み合わせるといつもと違う動きが見えて面白いです。あまり激しく動かすと壁をすり抜けて飛んでいくヤツがチラホラいますね(笑)
[ 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 |
#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) {}; ofCamera cam; ofLight light; ofxBulletWorldRigid world; ofxBulletCustomShape* boundsShape; vector<ofxBulletBox*> boxes; vector<ofColor> boxes_color; }; |
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 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
#include "ofApp.h" //-------------------------------------------------------------- ofApp::~ofApp() { delete this->boundsShape; for (ofxBulletBox* tmp : this->boxes) { delete tmp; } this->boxes.clear(); } //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(60); ofBackground(0); ofSetWindowTitle("Insta"); ofEnableDepthTest(); ofEnableBlendMode(ofBlendMode::OF_BLENDMODE_ADD); this->cam.setPosition(ofVec3f(0, 3.f, -30.f)); this->cam.lookAt(ofVec3f(0, 0, 0), ofVec3f(0, -1, 0)); this->world.setup(); this->world.enableGrabbing(); this->world.setCamera(&this->cam); this->world.setGravity(ofVec3f(0.0, 64.0, 0)); ofVec3f start_location; ofPoint dimens; float bounds_width = 400; float h_width = bounds_width * 0.5; float depth = 10.; float h_depth = depth * 0.5; this->boundsShape = new ofxBulletCustomShape(); this->boundsShape->create(world.world, ofVec3f(0, 0, 0), 10.); for (int i = 0; i < 6; i++) { if (i == 0) { // ground // start_location.set(0., h_width + h_depth, 0.); dimens.set(bounds_width, depth, bounds_width); } else if (i == 1) { // back wall // start_location.set(0, 0, h_width + h_depth); dimens.set(bounds_width, bounds_width, depth); } else if (i == 2) { // right wall // start_location.set(h_width + h_depth, 0, 0.); dimens.set(depth, bounds_width, bounds_width); } else if (i == 3) { // left wall // start_location.set(-h_width - h_depth, 0, 0.); dimens.set(depth, bounds_width, bounds_width); } else if (i == 4) { // ceiling // start_location.set(0, -h_width - h_depth, 0.); dimens.set(bounds_width, depth, bounds_width); } else if (i == 5) { // front wall // start_location.set(0, 0, -h_width - h_depth); dimens.set(bounds_width, bounds_width, depth); } btBoxShape* boxShape = ofBtGetBoxCollisionShape(dimens.x, dimens.y, dimens.z); this->boundsShape->addShape(boxShape, start_location); } this->boundsShape->add(); for (int i = 0; i < 512; i++) { ofxBulletBox* box = new ofxBulletBox(); float size = 10; box->create(this->world.world, ofVec3f(ofRandom(-100, 100), ofRandom(-100, 100), ofRandom(-100, 100)), 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->boxes_color.push_back(color); } this->light.setPosition(ofVec3f(0, 0, 512)); } //-------------------------------------------------------------- void ofApp::update() { if (!ofGetMousePressed()) { ofVec3f diff = ofVec3f(0, 0, 0) - boundsShape->getPosition(); diff *= 500.f; boundsShape->applyCentralForce(diff); } this->world.update(); } //-------------------------------------------------------------- void ofApp::draw() { ofTranslate(ofGetWidth() / 2, ofGetHeight() / 2); //ofEnableLighting(); //this->light.enable(); ofNoFill(); if (ofGetMousePressed()) { ofSetColor(255, 255, 0); } else { ofSetColor(255); } boundsShape->transformGL(); ofDrawBox(ofVec3f(0, 0, 0), 400); boundsShape->restoreTransformGL(); ofFill(); for (int i = 0; i < this->boxes.size(); i++) { ofSetColor(this->boxes_color[i], 128); ofDrawBox(this->boxes[i]->getPosition(), 3, 3, 3); for (int j = i + 1; j < this->boxes.size(); j++) { float distance = this->boxes[i]->getPosition().distanceSquared(this->boxes[j]->getPosition()); if (distance < 40 * 40) { ofSetColor(this->boxes_color[i], ofMap(distance, 0, 40 * 40, 255, 0)); ofDrawLine(this->boxes[i]->getPosition(), this->boxes[j]->getPosition()); } } } } //-------------------------------------------------------------- void ofApp::keyPressed(int key) { if (key == 'a') { this->world.setGravity(ofVec3f(0.0, 0.0, 0)); } if (key == 's') { this->world.setGravity(ofVec3f(0.0, 64.0, 0)); } } //======================================================================== int main() { ofSetupOpenGL(720, 720, OF_WINDOW); ofRunApp(new ofApp()); } |