[ Video ]
[ About ]
滝のようなBoxの流れを作って、それぞれの色をJPEGファイルからX, Y座標を元に拾ってきています。
本当は箱の中にBoxをため込んで最終的にイラストが見えるようなものにしたかったのですが、処理スピードの問題で断念しました。
[ 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 |
#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; ofImage img; ofPixels pixels; }; |
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 |
#include "ofApp.h" //-------------------------------------------------------------- ofApp::~ofApp() { for (ofxBulletBox* tmp : this->boxes) { delete tmp; } this->boxes.clear(); } //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(60); ofEnableDepthTest(); ofBackground(0); ofSetWindowTitle("Insta"); this->world.setup(); this->world.setGravity(ofVec3f(0.0, 64.0, 0)); ofEnableLighting(); this->light.enable(); this->img.loadImage("he.jpg"); this->pixels = this->img.getPixelsRef(); } //-------------------------------------------------------------- void ofApp::update() { for (int i = 0; i < 10; i++) { ofxBulletBox* box = new ofxBulletBox(); float size = ofRandom(5, 15); box->create(this->world.world, ofVec3f(ofRandom(-256, 256), -300, 0), 1.0, size, size, size); box->setRestitution(0.5); box->add(); this->boxes.push_back(box); } this->world.update(); } //-------------------------------------------------------------- void ofApp::draw() { this->cam.begin(); ofRotateX(180); this->light.setPosition(this->cam.getPosition()); for (int i = this->boxes.size() - 1; i >= 0; i--) { if (this->boxes[i]->getPosition().y > ofGetHeight() / 2) { delete this->boxes[i]; this->boxes.erase(this->boxes.begin() + i); continue; } int x = this->boxes[i]->getPosition().x + 256; int y = this->boxes[i]->getPosition().y + 256; if (x >= 0 && x < 512 && y >= 0 && y < 512) { ofSetColor(this->pixels.getColor(x, y)); this->boxes[i]->draw(); } } this->cam.end(); } //======================================================================== int main() { ofSetupOpenGL(720, 720, OF_WINDOW); ofRunApp(new ofApp()); } |