Last active
May 21, 2024 10:55
-
-
Save tado/d95a1d66c92505cb4b535e704cdce42d to your computer and use it in GitHub Desktop.
openFrameworks 3D vector animation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "ofApp.h" | |
void ofApp::setup() { | |
} | |
void ofApp::update() { | |
for (int i = 0; i < location.size(); i++) { | |
location[i] += velocity[i]; | |
if (location[i].x < 0 || location[i].x > ofGetWidth()) { | |
velocity[i].x *= -1; | |
} | |
if (location[i].y < 0 || location[i].y > ofGetHeight()) { | |
velocity[i].y *= -1; | |
} | |
if (location[i].z < -500 || location[i].z > 500) { | |
velocity[i].z *= -1; | |
} | |
} | |
} | |
void ofApp::draw() { | |
for (int i = 0; i < location.size(); i++) { | |
ofDrawCircle(location[i], 5); | |
} | |
ofDrawBitmapStringHighlight( | |
"Num = " + ofToString(location.size()), 20, 20); | |
ofDrawBitmapStringHighlight( | |
"FPS = " + ofToString(ofGetFrameRate()), 20, 40); | |
} | |
void ofApp::mouseDragged(int x, int y, int button) { | |
glm::vec3 loc = glm::vec3(x, y, 0); | |
location.push_back(loc); | |
glm::vec3 vel = glm::vec3(ofRandom(-2, 2), ofRandom(-2, 2), ofRandom(-10, 10)); | |
velocity.push_back(vel); | |
if (location.size() > NUM) { | |
location.erase(location.begin()); | |
velocity.erase(velocity.begin()); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include "ofMain.h" | |
class ofApp : public ofBaseApp { | |
public: | |
void setup(); | |
void update(); | |
void draw(); | |
void mouseDragged(int x, int y, int button); | |
static const int NUM = 1000; | |
vector<glm::vec3> location; | |
vector<glm::vec3> velocity; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment