Hi,
I’m trying to create this kind of motion of the leaves rotating in a tube and also following a path:
http://www.youtube.com/watch?v=nJam5Auwj1E
I’m rotating the particles/leaves simple by using cos(x)/sin(y) around a certain radius. This looks nice and works okay. Though I don’t understand how I can add the forces which make all particles follow the leader like in that movie.
Here is my code. I’ve got a “Dust” class which is a particle and a DustCloud which is the group of particles:
Dust
#include "Dust.h"
Dust::Dust(float fX, float fY, float fZ) {
pos.set(fX, fY, fZ);
angle = 0;
angle_inc = ofRandom(0,0.08);
radius = ofRandom(60,90.0f);
start_x = move_pos.x = fX;
start_y = move_pos.y = fY;
start_z = fZ;
move_pos.z = fZ;
vel = ofRandom(0.05,0.08);
}
float Dust::getStartZ() {
return start_z;
}
void Dust::update() {
vel += accel;
vel.limit(30);
move_pos += vel;
//pos.z += vel.z;
pos.z = move_pos.z;
angle += angle_inc;
pos.x = move_pos.x + cos(angle) * radius;
pos.y = move_pos.y + sin(angle) * radius;
}
void Dust::draw() {
glPushMatrix();
ofSetColor(0xFF00CC);
glTranslatef(pos.x, pos.y, pos.z);
ofCircle(0,0,4);
glPopMatrix();
}
void Dust::setPosition(ofxVec3f oPos) {
move_pos = oPos;
}
void Dust::arrive(Dust* pParent) {
/*
ofxVec3f target = pParent->getPosition();
ofxVec3f desired_vel = target - pos;
float dist = desired_vel.length();
desired_vel.normalize();
float max_vel = 80;
float arrive_dist = 40;
if (dist <= arrive_dist) {
desired_vel *= ((max_vel * dist / arrive_dist));
}
else {
desired_vel *= max_vel;
}
if (dist > 10) {
desired_vel -= vel;
addForce(desired_vel);
}
*/
}
ofxVec3f Dust::getPosition() {
return move_pos;
}
void Dust::addForce(ofxVec3f oForce) {
accel += oForce;
}
DustCloud
#include "DustCloud.h"
DustCloud::DustCloud() {
float z = 0;
angle_z = 0;
for(int i = 0; i < 60; ++i) {
dusts.push_back(new Dust(
ofRandom(300,320)
,ofRandom(300,330)
,z
));
if (i > 0) {
springs.push_back(new DustSpring(
dusts[i]
,dusts[i-1]
,20
));
}
z-= ofRandom(10,30);
}
}
void DustCloud::update() {
for (int i = 0; i < dusts.size(); ++i) {
dusts[i]->update();
}
}
vector<Dust*> DustCloud::getDusts() {
return dusts;
}
void DustCloud::draw() {
for(int i = 0; i < dusts.size(); ++i) {
dusts[i]->draw();
}
}
Roxlu