[ Video ]
[ About ]
Leap Motionというセンサーで、手の状態やジェスチャー情報を取得しています。
手が50%以上開いた状態だと、手の加速度を反映した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 32 33 34 35 |
#pragma once #include "ofMain.h" #include "Particle.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 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<Particle*> particles; 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 |
#include "ofApp.h" //-------------------------------------------------------------- ofApp::~ofApp() { for (int i = this->particles.size() - 1; i > -1; i--) { delete this->particles[i]; this->particles.erase(this->particles.begin() + i); } } //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(60); ofBackground(0); ofSetWindowTitle("Insta"); ofEnableBlendMode(ofBlendMode::OF_BLENDMODE_ADD); } //-------------------------------------------------------------- void ofApp::update(){ Leap::Frame frame = leap.frame(); for (Leap::Hand hand : frame.hands()) { if (hand.grabStrength() < 0.5) { ofVec2f velocity = ofVec2f(hand.palmVelocity().x, hand.palmVelocity().y); velocity.limit(5); this->particles.push_back(new Particle(ofVec2f(hand.palmPosition().x, hand.palmPosition().y - ofGetHeight() / 5), velocity)); } } for (int i = this->particles.size() - 1; i > -1; i--) { this->particles[i]->update(); if (this->particles[i]->isDead()) { delete this->particles[i]; this->particles.erase(this->particles.begin() + i); } } } //-------------------------------------------------------------- void ofApp::draw(){ this->cam.begin(); for (Particle* p : this->particles) { p->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 21 |
#pragma once #include "ofMain.h" class Particle { public: Particle(); Particle(ofVec2f location, ofVec2f velocity); ~Particle(); void update(); void draw(); bool isDead(); private: ofVec2f location; ofVec2f velocity; float body_size; ofColor body_color; int alpha; }; |
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 |
#include "Particle.h" Particle::Particle() : Particle(ofVec2f(0, 0), ofVec2f(0, 0)) { } Particle::Particle(ofVec2f location, ofVec2f velocity) { this->location = location; this->velocity = velocity; this->alpha = 255; this->body_size = velocity.length() * 7; this->body_color.setHsb(ofRandom(255), 255, 255); } Particle::~Particle() { } void Particle::update() { this->location += this->velocity; this->alpha -= 3; } void Particle::draw() { ofSetColor(this->body_color, this->alpha); ofEllipse(this->location, this->body_size, this->body_size); } bool Particle::isDead() { return this->alpha < 0; } |
[ Link ]
Leap Motion
https://github.com/junkiyoshi/Insta20171015