How do you save the particle in the launchParticle() and use the array for particle system? (make sure clear() it first)

//

#include “ofApp.h”

Particle::Particle() {

// initialize particle with some reasonable values first;

//

velocity.set(0, 0, 0);

acceleration.set(0, 0, 0);

position.set(0, 0, 0);

lifespan = 5;

birthtime = 0;

radius = .5;

damping = .99;

mass = 1;

}

void Particle::draw() {

ofSetColor(ofColor::blue);

ofDrawSphere(position, radius);

}

// write your own integrator here… (hint: it’s only 3 lines of code)

//

void Particle::integrate() {

// (1) update position from velocity and time interval

// (2) update velocity (based on acceleration

// (3) multiply final result by the damping factor to sim drag

//

//continue code

float time = 1/ofGetFrameRate();

position.set(position + velocity * time);

velocity.set(velocity + acceleration * time);

velocity.set(velocity * damping);

}

void ofApp::launchParticle() {

// Create initialize a new particle with values from sliders

//

Particle particle;

particle.velocity.x = velocity->x;

particle.velocity.y = velocity->y;

particle.velocity.z = velocity->z;

particle.acceleration.set(0, -gravity, 0);

particle.damping = damping;

particle.radius = radius;

cout << "vel: " << particle.velocity << endl;

cout << "accel: " << particle.acceleration << endl;

cout << "damp: " << damping << endl;

cout << "rad: " << radius << endl;

// save your particle here - you can use an array

// but make sure to clear() it first as we are using it for

// just one particle.

// continue code here

}

//--------------------------------------------------------------

void ofApp::setup(){

cam.setDistance(10);

cam.setNearClip(.1);

cam.setFov(65.5); // approx equivalent to 28mm in 35mm format

ofSetVerticalSync(true);

framerate = ofGetFrameRate();

// some simple sliders to play with parameters

//

gui.setup();

gui.add(velocity.setup(“Initial Velocity”, ofVec3f(0, 20, 0), ofVec3f(0, 0, 0), ofVec3f(100, 100, 100)));

gui.add(damping.setup(“Damping”, .99, .1, 1.0));

gui.add(gravity.setup(“Gravity”, 10, 1, 20));

gui.add(radius.setup(“Radius”, .5, .1, 1.0));

bHide = false;

}

//--------------------------------------------------------------

void ofApp::update() {

//

// need to call integrate() method in your particles here

// - loop through your

//

//continue code

}

//--------------------------------------------------------------

void ofApp::draw(){

ofSetBackgroundColor(ofColor::black);

// draw the GUI

if (!bHide) gui.draw();

cam.begin();

// draw a grid

//

ofPushMatrix();

ofRotate(90, 0, 0, 1);

ofSetLineWidth(1);

ofSetColor(ofColor::dimGrey);

ofDrawGridPlane();

ofPopMatrix();

// draw particle(s) here…

//

//continue code here

cam.end();

}

//--------------------------------------------------------------

void ofApp::keyPressed(int key){

switch (key) {

case ‘C’:

case ‘c’:

if (cam.getMouseInputEnabled()) cam.disableMouseInput();

else cam.enableMouseInput();

break ;

case ‘F’:

case ‘f’:

ofToggleFullscreen();

break ;

case ’ ':

launchParticle();

break ;

}

}

//--------------------------------------------------------------

void ofApp::keyReleased(int key){

}

//--------------------------------------------------------------

void ofApp::mouseMoved(int x, int y ){

}

//--------------------------------------------------------------

void ofApp::mouseDragged(int x, int y, int button){

}

//--------------------------------------------------------------

void ofApp::mousePressed(int x, int y, int button){

}

//--------------------------------------------------------------

void ofApp::mouseReleased(int x, int y, int button){

}

//--------------------------------------------------------------

void ofApp::mouseEntered(int x, int y){

}

//--------------------------------------------------------------

void ofApp::mouseExited(int x, int y){

}

//--------------------------------------------------------------

void ofApp::windowResized(int w, int h){

}

//--------------------------------------------------------------

void ofApp::gotMessage(ofMessage msg){

}

//--------------------------------------------------------------

void ofApp::dragEvent(ofDragInfo dragInfo){

}

#pragma once

#include “ofMain.h”

#include “ofxGui.h”

class Particle {

public :

Particle();

ofVec3f position;

ofVec3f velocity;

ofVec3f acceleration;

float damping;

float mass;

float lifespan;

float radius;

float birthtime;

void integrate();

void draw();

};

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);

void launchParticle();

ofEasyCam cam;

float framerate;

vector particles;

// some simple sliders to play with parameters

//

bool bHide;

ofxFloatSlider gravity;

ofxFloatSlider damping;

ofxFloatSlider radius;

ofxVec3Slider velocity;

ofxPanel gui;

};

Hi, you need to store the particles in a std::vector ( dynamic array container).
so in ofApp.h where it says
vector particles;
change it for
vector<Particle> particles;

the in the launchParticle function replace the line that says

Particle particle;

for

particles.push_back(Particle());// this adds a new particle at the end of the vector.
Particle &particle = particles.back(); // this just creates a reference so you dont have to change the rest of your code.