[ Video ]
[ About ]
回転するボックス
Rotating 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 33 34 35 36  | 
						#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 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; 	int size; 	int span; 	int speed; 	vector<glm::vec3> axis; 	int axis_index; 	int col; 	int direction; 	vector<glm::vec3> 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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81  | 
						#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { 	ofSetFrameRate(60); 	ofSetWindowTitle("openframeworks"); 	ofBackground(239); 	ofSetColor(39); 	ofEnableDepthTest(); 	ofSetLineWidth(2); 	this->size = 100; 	this->span = this->size * 1.5; 	ofColor color; 	int hue = 0; 	for (int x = -this->span; x <= this->span; x += this->span) { 		color.setHsb(hue, 180, 255); 		hue += 85; 		for (int y = -this->span; y <= this->span; y += this->span) { 			for (int z = -this->span; z <= this->span; z += this->span) { 				this->locations.push_back(glm::vec3(x, y, z)); 				this->colors.push_back(color); 			} 		} 	} 	this->speed = 2; 	this->axis = { glm::vec3(1, 0,0), glm::vec3(0, 1,0) , glm::vec3(0, 0,1) }; 	this->axis_index = 0; 	this->col = 0; 	this->direction = 1; } //-------------------------------------------------------------- void ofApp::update() { 	if (ofGetFrameNum() % (90 / this->speed) == 0) { 		this->axis_index = ofRandom(3); 		this->col = (int)ofRandom(3) * this->span - this->span; 		this->direction = ofRandom(2) < 1 ? this->speed : -this->speed; 	} } //-------------------------------------------------------------- void ofApp::draw() { 	this->cam.begin(); 	int color_index = 0; 	for (auto& location : this->locations) { 		if ((this->axis_index == 0 && (int)location.x == this->col) || (this->axis_index == 1 && (int)location.y == this->col) || (this->axis_index == 2 && (int)location.z == this->col)) { 			auto rotation = glm::rotate(glm::mat4(), (float)DEG_TO_RAD * this->direction, this->axis[this->axis_index]); 			location = glm::vec4(location, 0) * rotation; 		} 		ofFill(); 		ofSetColor(this->colors[color_index++]); 		ofDrawBox(location, this->size * 0.99); 		ofNoFill(); 		ofSetColor(39); 		ofDrawBox(location, this->size); 	} 	this->cam.end(); } //-------------------------------------------------------------- int main() { 	ofSetupOpenGL(720, 720, OF_WINDOW); 	ofRunApp(new ofApp()); }  |