[ Video ]
[ About ]
Random walker crating random walker 3D Edition.
[ 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  | 
						#pragma once #include "ofMain.h" #include "Actor.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; 	vector<glm::vec3> noise_seed_list; 	vector<glm::vec3> noise_location_list; 	vector<glm::vec3> location_list; 	vector<vector<int>> next_index_list; 	vector<unique_ptr<Actor>> actor_list; };  | 
					
| 
					 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  | 
						#include "ofApp.h"	 //-------------------------------------------------------------- void ofApp::setup() { 	ofSetFrameRate(60); 	ofSetWindowTitle("openFrameworks"); 	ofBackground(239); 	ofSetLineWidth(2); 	auto span = 20; 	for (int x = -300; x <= 300; x += span) { 		for (int y = -300; y <= 300; y += span) { 			for (int z = -300; z <= 300; z += span) { 				this->location_list.push_back(glm::vec3(x, y, z)); 			} 		} 	} 	for (auto& location : this->location_list) { 		vector<int> next_index = vector<int>(); 		int index = -1; 		for (auto& other : this->location_list) { 			index++; 			if (location == other) { continue; } 			float distance = glm::distance(location, other); 			if (distance <= span) { 				next_index.push_back(index); 			} 		} 		this->next_index_list.push_back(next_index); 	} 	for (int i = 0; i < 2; i++) { 		this->noise_seed_list.push_back(glm::vec3(ofRandom(1000), ofRandom(1000), ofRandom(1000))); 		this->noise_location_list.push_back(glm::vec3()); 	} } //-------------------------------------------------------------- void ofApp::update() { 	int frame_span = 15; 	int prev_index_size = 0; 	for (int i = 0; i < this->noise_seed_list.size(); i++) { 		this->noise_location_list[i] = glm::vec3( 			ofMap(ofNoise(this->noise_seed_list[i].x, ofGetFrameNum() * 0.008), 0, 1, -350, 350), 			ofMap(ofNoise(this->noise_seed_list[i].y, ofGetFrameNum() * 0.008), 0, 1, -350, 350), 			ofMap(ofNoise(this->noise_seed_list[i].z, ofGetFrameNum() * 0.008), 0, 1, -350, 350)); 		for (int k = 0; k < this->location_list.size(); k++) { 			auto distance = glm::distance(this->noise_location_list[i], this->location_list[k]); 			if (distance < 10) { 				this->actor_list.push_back(make_unique<Actor>(k)); 			} 		} 	} 	for (auto& actor : this->actor_list) { 		actor->update(frame_span, this->location_list, this->next_index_list); 	} 	for (int i = this->actor_list.size() - 1; i >= 0; i--) { 		if (this->actor_list[i]->isDead()) { 			this->actor_list.erase(this->actor_list.begin() + i); 		} 	} } //-------------------------------------------------------------- void ofApp::draw() { 	this->cam.begin(); 	ofRotate(90); 	ofRotateY(180); 	ofRotateX(ofGetFrameNum() * 0.5); 	for (auto& actor : this->actor_list) { 		actor->draw(); 	} 	for (auto& noise_location : this->noise_location_list) { 		ofDrawSphere(noise_location, 10); 	} 	this->cam.end(); } //-------------------------------------------------------------- int main() { 	ofSetupOpenGL(720, 720, OF_WINDOW); 	ofRunApp(new ofApp()); }  | 
					
| 
					 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21  | 
						#pragma once #include "ofMain.h" class Actor { public: 	Actor(vector<glm::vec3>& location_list); 	Actor(int select_index); 	void update(int& frame_span, vector<glm::vec3>& location_list, vector<vector<int>>& next_index_list); 	void draw(); 	bool isDead(); private: 	int select_index; 	int next_index; 	int life; 	glm::vec3 location; 	std::deque<glm::vec3> log; };  | 
					
| 
					 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  | 
						#include "Actor.h" //-------------------------------------------------------------- Actor::Actor(vector<glm::vec3>& location_list) { 	this->select_index = ofRandom(location_list.size()); 	this->next_index = this->select_index; 	this->life = 300; } //-------------------------------------------------------------- Actor::Actor(int select_index) { 	this->select_index = select_index; 	this->next_index = this->select_index; 	this->life = 300; } //-------------------------------------------------------------- void Actor::update(int& frame_span, vector<glm::vec3>& location_list, vector<vector<int>>& next_index_list) { 	if (ofGetFrameNum() % frame_span == 0) { 		this->select_index = this->next_index; 		this->next_index = next_index_list[this->select_index][(int)ofRandom(next_index_list[this->select_index].size())]; 	} 	auto param = ofGetFrameNum() % frame_span; 	auto distance = location_list[this->next_index] - location_list[this->select_index]; 	this->location = location_list[this->select_index] + distance / frame_span * param; 	this->log.push_front(this->location); 	while (this->log.size() > 100) { this->log.pop_back(); } 	this->life--; } //-------------------------------------------------------------- void Actor::draw() { 	this->life < 100 ? ofSetColor(ofMap(this->life, 0, 100, 239, 39)) : ofSetColor(39); 	ofFill(); 	ofDrawSphere(this->log.front(), 3); 	ofNoFill(); 	ofBeginShape(); 	for (auto& l : this->log) { 		ofVertex(l); 	} 	ofEndShape(); } //-------------------------------------------------------------- bool Actor::isDead() { 	return this->life < 0; }  |