[ Video ]
[ About ]
Day 24 Printer.
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 |
#pragma once #include "ofMain.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 windowResized(int w, int h) {}; void dragEvent(ofDragInfo dragInfo) {}; void gotMessage(ofMessage msg) {}; ofEasyCam cam; int size; vector<glm::vec2> locations; vector<ofColor> colors; }; |
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 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(60); ofSetWindowTitle("openframeworks"); ofBackground(0); ofEnableDepthTest(); ofSetLineWidth(3); auto mat = cv::imread("lena.png"); this->size = 4; for (int x = 0; x < mat.cols; x += this->size) { for (int y = 0; y < mat.rows; y += this->size) { cv::Vec3b mat_color = mat.at<cv::Vec3b>(y, x); ofColor color = ofColor(mat_color[2], mat_color[1], mat_color[0]); this->colors.push_back(color); this->locations.push_back(glm::vec2(x - ofGetWidth() * 0.5, ofGetHeight() - y - ofGetHeight() * 0.5)); } } } //-------------------------------------------------------------- void ofApp::update() { } //-------------------------------------------------------------- void ofApp::draw() { this->cam.begin(); int i = 0; for (; i < ((ofGetFrameNum() * 50) % this->locations.size()); i++) { ofSetColor(this->colors[i]); ofDrawRectangle(this->locations[i], this->size, this->size); } ofDrawSphere(glm::vec3(0, 0, 300), 10); ofDrawLine(glm::vec3(0, 0, 300), glm::vec3(this->locations[i], 0)); this->cam.end(); } //======================================================================== int main() { ofSetupOpenGL(512, 512, OF_WINDOW); ofRunApp(new ofApp()); } |
[ Link ]