[ Video ]
[ About ]
指の動きに反応してPaticleが生成されます。
particle creation by finger velocity.
[ 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 |
#pragma once #include "ofMain.h" #include "ofxBox2d.h" // Leap Motion SDK #include "Leap.h" #pragma comment(lib, "Leap.lib") 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; // Box2d ofxBox2d box2d; vector<shared_ptr<ofxBox2dCircle>> circles; vector<ofColor> circles_color; vector<float> circles_life; // Leap Motion Leap::Controller leap; }; |
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 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(60); ofBackground(0); ofSetWindowTitle("Insta"); ofSetCircleResolution(60); this->box2d.init(); this->box2d.setGravity(0, 0); this->box2d.createBounds(); this->box2d.setFPS(60); this->box2d.registerGrabbing(); } //-------------------------------------------------------------- void ofApp::update() { Leap::Frame frame = leap.frame(); for (Leap::Hand hand : frame.hands()) { for (Leap::Finger finger : hand.fingers()) { ofVec2f velocity = ofVec2f(finger.tipVelocity().x, -finger.tipVelocity().y); if (velocity.length() > 250) { this->circles.push_back(shared_ptr<ofxBox2dCircle>(new ofxBox2dCircle)); this->circles.back().get()->setPhysics(3.0, 0.53, 0.1); this->circles.back().get()->setup(this->box2d.getWorld(), finger.tipPosition().x + ofGetWidth() / 2, ofGetHeight() / 2 - finger.tipPosition().y, 8); this->circles.back().get()->addForce(velocity, 1.0); ofColor line_color; line_color.setHsb(ofGetFrameNum() % 255, 255, 255); this->circles_color.push_back(line_color); this->circles_life.push_back(255); } } } this->box2d.update(); for (int i = 0; i < this->circles.size(); i++) { if (this->circles_life[i] < 0) { this->circles[i].get()->destroy(); this->circles.erase(this->circles.begin() + i); this->circles_color.erase(this->circles_color.begin() + i); this->circles_life.erase(this->circles_life.begin() + i); } } } //-------------------------------------------------------------- void ofApp::draw() { ofFill(); for (int i = 0; i < this->circles.size(); i++) { ofSetColor(this->circles_color[i], this->circles_life[i]); ofDrawCircle(this->circles[i].get()->getPosition(), 8); this->circles_life[i] -= 2.f; } } //-------------------------------------------------------------- int main() { ofSetupOpenGL(720, 720, OF_WINDOW); ofRunApp(new ofApp()); } |