upload
This commit is contained in:
parent
27682266f3
commit
75dd4f9bb3
42
attractor.cpp
Normal file
42
attractor.cpp
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
#include "attractor.h"
|
||||||
|
|
||||||
|
Attractor::Attractor()
|
||||||
|
{
|
||||||
|
x = 0;
|
||||||
|
y = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Attractor::~Attractor()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
float Attractor::getY() {
|
||||||
|
return y;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
float Attractor::getX() {
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Attractor::setX(float xNew) {
|
||||||
|
x = xNew;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Attractor::setY(float yNew) {
|
||||||
|
y = yNew;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Attractor::setup(float xSetup, float ySetup) {
|
||||||
|
x = xSetup;
|
||||||
|
y = ySetup;
|
||||||
|
}
|
||||||
|
|
34
attractor.h
Normal file
34
attractor.h
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
//
|
||||||
|
// attractor.h
|
||||||
|
// particleSystem
|
||||||
|
//
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
|
||||||
|
class Attractor {
|
||||||
|
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
Attractor();
|
||||||
|
~Attractor();
|
||||||
|
|
||||||
|
|
||||||
|
float getX();
|
||||||
|
float getY();
|
||||||
|
|
||||||
|
void setX(float x);
|
||||||
|
void setY(float y);
|
||||||
|
|
||||||
|
void setup(float x, float y);
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
//ofVec2f direction
|
||||||
|
float x;
|
||||||
|
float y;
|
||||||
|
|
||||||
|
float force;
|
||||||
|
};
|
60
ofApp.h
Normal file
60
ofApp.h
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "ofMain.h"
|
||||||
|
#include "particle.h"
|
||||||
|
#include "ofxOsc.h"
|
||||||
|
#include "ofxGui.h"
|
||||||
|
|
||||||
|
//OSC Reciever PORT & HOST IP
|
||||||
|
#define PORT 12345
|
||||||
|
#define HOST "172.20.10.2"
|
||||||
|
|
||||||
|
class ofApp : public ofBaseApp {
|
||||||
|
|
||||||
|
public:
|
||||||
|
void setup();
|
||||||
|
void update();
|
||||||
|
void draw();
|
||||||
|
void reset();
|
||||||
|
|
||||||
|
void keyPressed(int key);
|
||||||
|
void keyReleased(int key);
|
||||||
|
void mouseMoved(int x, int y);
|
||||||
|
void mousePressed(int x, int y, int button);
|
||||||
|
void mouseReleased(int x, int y, int button);
|
||||||
|
|
||||||
|
ofxXmlSettings default;
|
||||||
|
ofxXmlSettings attractor;
|
||||||
|
ofxXmlSettings rain;
|
||||||
|
ofxXmlSettings brunig;
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
// OSC Receiver
|
||||||
|
|
||||||
|
particleMode currentMode;
|
||||||
|
string currentModeDisp;
|
||||||
|
|
||||||
|
string oscMsg;
|
||||||
|
ofxOscReceiver receiver;
|
||||||
|
float timeSent, timeReceived;
|
||||||
|
|
||||||
|
int nBlobs;
|
||||||
|
int blobCount;
|
||||||
|
int num;
|
||||||
|
float history;
|
||||||
|
ofFbo fbo;
|
||||||
|
|
||||||
|
float xOfCentroid;
|
||||||
|
float yOfCentroid;
|
||||||
|
|
||||||
|
vector<Particle*> system;
|
||||||
|
vector<Particle>sys;
|
||||||
|
vector<Attractor*> attractors;
|
||||||
|
|
||||||
|
float birthCount;
|
||||||
|
double time;
|
||||||
|
|
||||||
|
bool varSystem;
|
||||||
|
bool trails;
|
||||||
|
};
|
211
particle.cpp
Normal file
211
particle.cpp
Normal file
@ -0,0 +1,211 @@
|
|||||||
|
|
||||||
|
// particle.cpp
|
||||||
|
// particleSystem
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "particle.h"
|
||||||
|
#include "ofApp.h"
|
||||||
|
|
||||||
|
Particle::Particle()
|
||||||
|
{
|
||||||
|
uniqueVal = ofRandom(-10000, 10000);
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
void Particle::setup(particleMode newMode) {
|
||||||
|
mode = newMode;
|
||||||
|
age = 0.0;
|
||||||
|
//maxLife = 30.0;
|
||||||
|
frc = ofVec2f(0, 0);
|
||||||
|
//size = ofRandom(4.0, 0.01);
|
||||||
|
size = .5;
|
||||||
|
maxLife = 0.99;
|
||||||
|
mass = ofRandom(100, 250);
|
||||||
|
if (mode == PARTICLE_MODE_DEFAULT) {
|
||||||
|
effect.loadFile("xml/default.xml");
|
||||||
|
int velMin = effect.getValue("default:velMin", 0);
|
||||||
|
int velMax = effect.getValue("default:velMax", 0);
|
||||||
|
int lifeMax = effect.getValue("default:maxLife", 0);
|
||||||
|
setVel(velMin, velMax);
|
||||||
|
pos.x = ofRandomWidth();
|
||||||
|
pos.y = ofRandomHeight();
|
||||||
|
}
|
||||||
|
else if (mode == PARTICLE_MODE_RADIAL) {
|
||||||
|
effect.loadFile("xml/radial.xml");
|
||||||
|
int velMin = effect.getValue("radial:velMin", 0);
|
||||||
|
int velMax = effect.getValue("radial:velMax", 0);
|
||||||
|
setVel(velMin, velMax);
|
||||||
|
pos.x = ofGetWidth()/2;
|
||||||
|
pos.y = ofGetHeight()/2;
|
||||||
|
}
|
||||||
|
else if (mode == PARTICLE_MODE_RAIN) {
|
||||||
|
effect.loadFile("xml/rain.xml");
|
||||||
|
vel.x = ofRandom(-40, 40);
|
||||||
|
vel.y = ofRandom(-40, 40);
|
||||||
|
pos.x = ofRandomWidth();
|
||||||
|
pos.y = ofRandomHeight();
|
||||||
|
drag = ofRandom(0.97, 0.99);
|
||||||
|
vel.y = fabs(vel.y) * 6.0;
|
||||||
|
}
|
||||||
|
else if (mode == PARTICLE_MODE_ATTRACTOR) {
|
||||||
|
effect.loadFile("xml/rain.xml");
|
||||||
|
vel.x = ofRandom(-40, 40);
|
||||||
|
vel.y = ofRandom(-40, 40);
|
||||||
|
pos.x = ofRandomWidth();
|
||||||
|
pos.y = ofRandomHeight();
|
||||||
|
}
|
||||||
|
else if (mode == PARTICLE_MODE_DETRACTOR) {
|
||||||
|
effect.loadFile("xml/rain.xml");
|
||||||
|
vel.x = ofRandom(-40, 40);
|
||||||
|
vel.y = ofRandom(-40, 40);
|
||||||
|
pos.x = ofRandomWidth();
|
||||||
|
pos.y = ofRandomHeight();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
|
drag = ofRandom(0.95, 0.998);
|
||||||
|
}
|
||||||
|
|
||||||
|
tex.load("img/br.png");
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
void Particle::update(float deltaT, vector<Attractor*>* attractors,vector<Particle*> system) {
|
||||||
|
if (mode == PARTICLE_MODE_DEFAULT) {
|
||||||
|
|
||||||
|
}
|
||||||
|
else if (mode == PARTICLE_MODE_RAIN) {
|
||||||
|
float wind = ofSignedNoise(pos.x * 0.003, pos.y * 0.0006, ofGetElapsedTimef() * 0.6);
|
||||||
|
|
||||||
|
frc.x = wind * 0.25 + ofSignedNoise(uniqueVal, pos.y * 0.08) * 0.6;
|
||||||
|
frc.y = ofSignedNoise(uniqueVal, pos.x * 0.06, ofGetElapsedTimef()*0.2) * 0.09 + 0.18;
|
||||||
|
|
||||||
|
vel *= drag;
|
||||||
|
vel += frc * 0.2;
|
||||||
|
|
||||||
|
if (pos.y + vel.y > ofGetHeight()) {
|
||||||
|
pos.y -= ofGetHeight();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (mode == PARTICLE_MODE_ATTRACTOR) {
|
||||||
|
|
||||||
|
ofVec2f force;
|
||||||
|
counterOfActiveAttractors = 0;
|
||||||
|
for (int i = 0; i < attractors->size(); i++) {
|
||||||
|
if (attractors->at(i)->getX() == 0 && attractors->at(i)->getY() == 0) {
|
||||||
|
vel += force;
|
||||||
|
vel = mass * vel.getNormalized();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
counterOfActiveAttractors++;
|
||||||
|
force.set(attractors->at(i)->getX() - pos.x, attractors->at(i)->getY() - pos.y);
|
||||||
|
|
||||||
|
if (force.length() < 250) {
|
||||||
|
force = 40 * force.getNormalized();
|
||||||
|
size = size + ofRandom(.03, 0.01);
|
||||||
|
vel += force;
|
||||||
|
vel = mass * vel.getNormalized();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
force = 0 * force.getNormalized();
|
||||||
|
vel += force;
|
||||||
|
vel = mass * vel.getNormalized();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (mode == PARTICLE_MODE_DETRACTOR) {
|
||||||
|
ofVec2f force;
|
||||||
|
counterOfActiveAttractors = 0;
|
||||||
|
for (int i = 0; i < attractors->size(); i++) {
|
||||||
|
if (attractors->at(i)->getX() == 0 && attractors->at(i)->getY() == 0) {
|
||||||
|
//force = 0 * force.getNormalized();
|
||||||
|
vel += force;
|
||||||
|
vel = mass * vel.getNormalized();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
counterOfActiveAttractors++;
|
||||||
|
force.set(attractors->at(i)->getX() - pos.x, attractors->at(i)->getY() - pos.y);
|
||||||
|
|
||||||
|
if (force.length() < 600) {
|
||||||
|
force.normalize();
|
||||||
|
size = size + ofRandom(.01, 0.01);
|
||||||
|
|
||||||
|
vel += -force*2000;
|
||||||
|
vel = mass * vel.getNormalized();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
force = 0 * force.getNormalized();
|
||||||
|
vel += force;
|
||||||
|
vel = mass * vel.getNormalized();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//Update particle pos
|
||||||
|
age += deltaT* .5;
|
||||||
|
pos += (vel * deltaT);
|
||||||
|
|
||||||
|
// *** COLLISION *** COLLISION *** COLLISION *** COLLISION *** COLLISION *** COLLISION
|
||||||
|
|
||||||
|
//if (position.x <= 0 || position.x >= ofGetWidth()) {
|
||||||
|
//vel.x = -vel.x;
|
||||||
|
//position += (vel * deltaT);
|
||||||
|
//}
|
||||||
|
//else if (position.y <= 0 || position.y >= ofGetHeight()) {
|
||||||
|
//vel.y = -vel.y;
|
||||||
|
//position += (vel * deltaT);
|
||||||
|
//}
|
||||||
|
//else {
|
||||||
|
//position += (vel * deltaT);
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
void Particle::draw() {
|
||||||
|
|
||||||
|
color.set(getAgeNorm() * 241,241/ getAgeNorm() ,219);
|
||||||
|
|
||||||
|
ofSetColor(color, (1 - getAgeNorm()) * 255);
|
||||||
|
if (mode == PARTICLE_MODE_BRUNIG) {
|
||||||
|
tex.setColor(color);
|
||||||
|
tex.draw(pos.x, pos.y, size);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ofDrawCircle(pos.x, pos.y, size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//------------------------------------------------------------------
|
||||||
|
void Particle::setMode(particleMode newMode) {
|
||||||
|
mode = newMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
float Particle::getAgeNorm() {
|
||||||
|
return age / maxLife;
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
void Particle::setVel(float min, float max) {
|
||||||
|
vel.x = ofRandom(min,max);
|
||||||
|
vel.y = ofRandom(min,max);
|
||||||
|
}
|
||||||
|
|
||||||
|
float Particle::getMaxLife() {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
float Particle::getY() {
|
||||||
|
return pos.y;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
float Particle::getX() {
|
||||||
|
return pos.x;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
63
particle.h
Normal file
63
particle.h
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "ofMain.h"
|
||||||
|
#include "ofxXmlSettings.h"
|
||||||
|
#include "attractor.h"
|
||||||
|
|
||||||
|
enum particleMode{
|
||||||
|
PARTICLE_MODE_DEFAULT,
|
||||||
|
PARTICLE_MODE_ATTRACTOR,
|
||||||
|
PARTICLE_MODE_RAIN,
|
||||||
|
PARTICLE_MODE_RADIAL,
|
||||||
|
PARTICLE_MODE_DETRACTOR,
|
||||||
|
PARTICLE_MODE_POLY,
|
||||||
|
PARTICLE_MODE_BRUNIG
|
||||||
|
};
|
||||||
|
|
||||||
|
class Particle{
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
Particle();
|
||||||
|
|
||||||
|
void setup(particleMode newMode);
|
||||||
|
|
||||||
|
void update(float deltaT, vector<Attractor*>* attractors, vector<Particle*> system);
|
||||||
|
void setMode(particleMode newMode);
|
||||||
|
particleMode mode;
|
||||||
|
|
||||||
|
void draw();
|
||||||
|
void reset(ofVec2f _pos);
|
||||||
|
|
||||||
|
float getX();
|
||||||
|
float getY();
|
||||||
|
|
||||||
|
void setVel(float min, float max);
|
||||||
|
|
||||||
|
float getAgeNorm();
|
||||||
|
float getMaxLife();
|
||||||
|
|
||||||
|
|
||||||
|
ofxXmlSettings effect;
|
||||||
|
|
||||||
|
int counterOfActiveAttractors;
|
||||||
|
|
||||||
|
ofVec2f vel;
|
||||||
|
ofVec2f pos;
|
||||||
|
ofVec2f frc;
|
||||||
|
|
||||||
|
float scale;
|
||||||
|
float drag;
|
||||||
|
float uniqueVal;
|
||||||
|
|
||||||
|
float maxLife;
|
||||||
|
float age;
|
||||||
|
|
||||||
|
float size;
|
||||||
|
float mass;
|
||||||
|
|
||||||
|
int blobCounterInParticle;
|
||||||
|
|
||||||
|
ofColor color;
|
||||||
|
ofImage tex;
|
||||||
|
};
|
Loading…
x
Reference in New Issue
Block a user