[ Video ]
[ About ]
ドクターストレンジを見て、劇中のワープゲイトが作りたかった。
これじゃない感が凄い…けど、色々と頑張った。
Inspire from Dr.Strange.
[ 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 "ofFbo.h" #include "ofxBox2d.h" #include "opencv2/opencv.hpp" 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) {}; ofxBox2d box2d; ofFbo fbo; ofFbo mask; ofImage frame_img; int deg_max; vector<shared_ptr<ofxBox2dCircle>> circles; vector<ofColor> circles_color; vector<float> circles_life; cv::Mat frame; cv::VideoCapture cap; }; |
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 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(60); ofBackground(0); ofSetWindowTitle("Insta"); ofSetCircleResolution(60); ofSetLineWidth(2.5); ofEnableBlendMode(ofBlendMode::OF_BLENDMODE_ADD); this->box2d.init(); this->box2d.setGravity(0, 5); //this->box2d.createGround(ofVec2f(0, ofGetWidth()), ofVec2f(ofGetWidth(), ofGetHeight())); this->box2d.createBounds(); this->box2d.setFPS(60); this->box2d.registerGrabbing(); this->cap = cv::VideoCapture("move.mp4"); this->frame_img.allocate(this->cap.get(CV_CAP_PROP_FRAME_WIDTH), this->cap.get(CV_CAP_PROP_FRAME_HEIGHT), OF_IMAGE_COLOR); this->frame = cv::Mat(this->frame_img.getHeight(), this->frame_img.getWidth(), CV_MAKETYPE(CV_8UC3, this->frame_img.getPixels().getNumChannels()), this->frame_img.getPixels().getData(), 0); this->mask.allocate(this->frame_img.getWidth(), this->frame_img.getHeight(), GL_RGB); this->mask.begin(); ofFill(); ofColor(255); ofDrawCircle(ofGetWidth() / 2, ofGetHeight() / 3 * 2 - 190, 145); this->mask.end(); this->fbo.allocate(ofGetWidth(), ofGetHeight()); this->deg_max = 0; } //-------------------------------------------------------------- void ofApp::update() { if (ofGetFrameNum() % 4 == 0 && !ofGetMousePressed()){ float radius = 145; float power = 150; float tmp_deg = 0; for (int deg = 0; deg < this->deg_max; deg += 8) { tmp_deg = deg + ofGetFrameNum() * 3; 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(), radius * cos(tmp_deg * DEG_TO_RAD) + ofGetWidth() / 2, radius * sin(tmp_deg * DEG_TO_RAD) + ofGetHeight() / 3 * 2, 3); this->circles.back().get()->addForce(ofVec2f(power * cos((tmp_deg + 270) * DEG_TO_RAD), power * sin((tmp_deg + 270) * DEG_TO_RAD)), 1.0); ofColor color = ofColor(255, 255, 0); this->circles_color.push_back(color); this->circles_life.push_back(255); } if (this->deg_max < 340) { this->deg_max += 5; } } if(ofGetMousePressed() && this->deg_max >= 0){ this->deg_max -= 3; if (this->deg_max < 280){ this->deg_max = 0; } } 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); } } this->box2d.update(); this->fbo.begin(); ofFill(); ofClear(0); if (this->deg_max > 280) { this->cap >> this->frame; if (this->frame.empty()) { this->cap.set(cv::CAP_PROP_POS_FRAMES, 0); this->frame = cv::Mat(this->frame_img.getHeight(), this->frame_img.getWidth(), CV_MAKETYPE(CV_8UC3, this->frame_img.getPixels().getNumChannels()), this->frame_img.getPixels().getData(), 0); this->cap >> this->frame; } cv::cvtColor(this->frame, this->frame, CV_RGB2BGR); ofSetColor(255, ofMap(this->deg_max, 280, 300, 0, 128)); this->frame_img.update(); this->frame_img.getTextureReference().setAlphaMask(this->mask.getTexture()); this->frame_img.draw(0, 190); } for (int i = 0; i < this->circles.size(); i++) { ofSetColor(this->circles_color[i], this->circles_life[i] + 128); //ofDrawCircle(this->circles[i].get()->getPosition(), 3); ofDrawLine(this->circles[i].get()->getPosition(), this->circles[i].get()->getPosition() - this->circles[i].get()->getVelocity()); this->circles_life[i] -= 10.f; } this->fbo.end(); } //-------------------------------------------------------------- void ofApp::draw() { this->fbo.draw(0, 0); } //-------------------------------------------------------------- int main() { ofSetupOpenGL(512, 512, OF_WINDOW); ofRunApp(new ofApp()); } |