[ Video ]
[ About ]
昨日の動画のやつを改造して、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 28 29  | 
						#pragma once #include "ofMain.h" 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; 	ofLight light; 	ofImage note; 	ofSoundPlayer sound; 	vector<float> fft_smoothed; 	vector<vector<float>> log; 	int n_bands_to_get; };  | 
					
| 
					 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  | 
						#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { 	ofSetFrameRate(60); 	ofBackground(0); 	ofSetWindowTitle("Insta"); 	ofEnableDepthTest(); 	this->note.load("note.png"); 	this->sound.load("I_Did_That.mp3"); 	this->sound.play(); 	this->n_bands_to_get = 64; 	for (int j = 0; j < this->n_bands_to_get; j++) { 		this->fft_smoothed.push_back(0); 	} 	this->light.setPosition(ofVec3f(0, 0, 1024)); 	this->light.enable(); } //-------------------------------------------------------------- void ofApp::update() { 	ofSoundUpdate(); 	float* val = ofSoundGetSpectrum(this->n_bands_to_get); 	for (int i = 0; i < this->n_bands_to_get; i++) { 		this->fft_smoothed[i] *= 0.96f; 		if (this->fft_smoothed[i] < val[i]) { 			this->fft_smoothed[i] = val[i]; 		} 	} 	log.push_back(this->fft_smoothed); 	if (log.size() > 10) { 			this->log.erase(this->log.begin()); 	} } //-------------------------------------------------------------- void ofApp::draw() { 	this->cam.begin(); 	ofSetColor(200); 	this->note.resize(50, 50); 	this->note.draw(ofVec2f(-(this->note.getWidth() / 2), -(this->note.getHeight() / 2))); 	if (this->sound.getIsPlaying()) { 		float radius = 80; 		for (int l = this->log.size() - 1; l > -1 ; l--) 		{ 			for (int i = 0; i < this->n_bands_to_get; i++) { 				float deg = i * (360.f / this->n_bands_to_get); 				float height = this->log[l][i] * 50 * i / 3; 				float x = radius * cos(deg * DEG_TO_RAD); 				float y = radius * sin(deg * DEG_TO_RAD); 				ofVec3f point(x, y, height / 2); 				ofColor line_color; 				line_color.setHsb(255 - deg / 360 * 255, 255, 255); 				ofSetColor(line_color); 				ofDrawBox(point, 5, 5, height); 			} 			radius += 8; 		} 	} 	this->cam.end(); } //======================================================================== int main() { 	ofSetupOpenGL(720, 720, OF_WINDOW); 	ofRunApp(new ofApp()); }  |