[ Video ]
[ About ]
球体から棘が生える。
[ 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 |
#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; ofMesh sphere_mesh, draw_sphere_mesh; float noise_param; }; |
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(255); ofEnableDepthTest(); auto ico_sphere = ofIcoSpherePrimitive(150, 4); this->sphere_mesh = ico_sphere.getMesh(); this->noise_param = ofRandom(1000); } //-------------------------------------------------------------- void ofApp::update() { this->noise_param += 0.005; this->draw_sphere_mesh = this->sphere_mesh; for (auto& vertex : this->draw_sphere_mesh.getVertices()) { auto noise_value = ofNoise(glm::vec4(vertex * 0.025, noise_param)); auto noise_param = (noise_value < 0.7 ? 1 : ofMap(noise_value, 0.7, 1, 1, 8)); noise_param = std::pow(1.5, noise_param); auto noise_radius = 150 * noise_param; vertex = glm::normalize(vertex) * noise_radius; } } //-------------------------------------------------------------- void ofApp::draw() { this->cam.begin(); ofRotateX(180); ofRotateY(ofGetFrameNum() * 0.5); ofRotateX(ofGetFrameNum() * 0.5); ofSetColor(0); this->draw_sphere_mesh.draw(); ofSetColor(255); this->draw_sphere_mesh.drawWireframe(); this->cam.end(); } //-------------------------------------------------------------- int main() { ofSetupOpenGL(720, 720, OF_WINDOW); ofRunApp(new ofApp()); } |