//-------------------------------------------------------------- void ofApp::update(){ for(int i = 0; i < m_particles.size(); ){ //NB. we are not necessarily incrementing i every time m_particles[i].update(); if(m_particles[i].getSize() < 2){ m_particles.erase(m_particles.begin() + i); //this is how erase from a vector object // the vector is shorter }else{ i++; //no particle has been removed so we need to increment as normal } } if(m_isMouseDown){ ofVec2f pos( mouseX - ofGetWidth()/2 , mouseY - ofGetHeight()/2); float speed = ofRandom(10,40); if(m_particles.size() < g_maxNumParticles){ for(int i = 0; i < 10; i++)m_particles.push_back(particle(pos, speed)); } } }
static int init(int argc, char **argv) { GLenum res; glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA); glutInitWindowSize(WIN_WIDTH_I, WIN_HEIGHT_I); glutInitWindowPosition(100, 100); win_num = glutCreateWindow("Tutorial 01"); init_callbacks(); // Must be done after glut is initialized! res = glewInit(); if (res != GLEW_OK) { fprintf(stderr, "Error: '%s'\n", glewGetErrorString(res)); return -1; } glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0.0f, WIN_WIDTH_F, WIN_HEIGHT_F, 0.0f, 0.0f, 1.0f); glMatrixMode(GL_MODELVIEW); glDisable(GL_DEPTH_TEST); particles = particle(); start_thread_pool(); return 0; }
//-------------------------------------------------------------- void testApp::setup(){ ofSetVerticalSync(true); // PARTICLES int num = 500; p.assign(num, particle()); resetParticles(); // BLOB #ifdef _USE_LIVE_VIDEO vidGrabber.setVerbose(true); vidGrabber.initGrabber(320,240); #else vidPlayer.loadMovie("fingers.mov"); vidPlayer.play(); #endif colorImg.allocate(320,240); grayImage.allocate(320,240); grayBg.allocate(320,240); grayDiff.allocate(320,240); bLearnBakground = true; threshold = 80; }
AMagnetTile::AMagnetTile() : ATile() { PrimaryActorTick.bCanEverTick = true; ConstructorHelpers::FObjectFinder<UStaticMesh> mesh( *FName( "/Game/Models/Magnet" ).ToString() ); TileMesh->SetStaticMesh( mesh.Object ); TileMesh->SetMobility( EComponentMobility::Static ); BoxCollision->SetBoxExtent( FVector( 40.0f ) ); ConstructorHelpers::FObjectFinder<UParticleSystem> particle( *FName( "/Game/Particles/P_Magnet" ).ToString() ); magnetParticle = CreateDefaultSubobject<UParticleSystemComponent>( TEXT( "Magnet particle" ) ); magnetParticle->SetTemplate( particle.Object ); magnetParticle->AttachTo( GetRootComponent() ); magnetParticle->SetVisibility( false ); auto pc = Cast<UPrimitiveComponent>( RootComponent ); pc->SetWorldScale3D( FVector( 1.0f , 1.0f , 1.0f ) ); delegate.BindUFunction( this , TEXT( "OnBeginHit" ) ); BoxCollision->OnComponentHit.Add( delegate ); ConstructorHelpers::FObjectFinder<USoundWave> magnetSoundFile( TEXT( "/Game/Sound/S_MagnetLoop" ) ); magnetSound = CreateDefaultSubobject<UAudioComponent>( TEXT( "Magnet Sound" ) ); magnetSound->SetSound( magnetSoundFile.Object ); magnetSound->bAutoActivate = false; magnetSound->AttachTo( BoxCollision ); }
MayaPointPrimitiveWriter::MayaPointPrimitiveWriter( double iFrame, MDagPath & iDag, Alembic::AbcGeom::OObject & iParent, Alembic::Util::uint32_t iTimeIndex, const JobArgs & iArgs) : mIsAnimated(false), mDagPath(iDag) { MFnParticleSystem particle(mDagPath); MString name = particle.name(); name = util::stripNamespaces(name, iArgs.stripNamespace); Alembic::AbcGeom::OPoints obj(iParent, name.asChar(), iTimeIndex); mSchema = obj.getSchema(); Alembic::Abc::OCompoundProperty cp; Alembic::Abc::OCompoundProperty up; if (AttributesWriter::hasAnyAttr(particle, iArgs)) { cp = mSchema.getArbGeomParams(); up = mSchema.getUserProperties(); } mAttrs = AttributesWriterPtr(new AttributesWriter(cp, up, obj, particle, iTimeIndex, iArgs)); MObject object = iDag.node(); if (iTimeIndex != 0 && util::isAnimated(object)) mIsAnimated = true; write(iFrame); }
void ParticleSwarm::init(const std::string& file, const float values[][3], unsigned int size, unsigned int rev) { this->file = file; this->rev = rev; limits.resize(size); for(unsigned int j = 0; j < size; ++j) { limits[j].min = limits[j].max = values[j][1]; limits[j].add(values[j][2]); ASSERT(limits[j].isInside(values[j][0])); // start value not in value range! } if(!file.empty()) { InBinaryFile stream(file); if(stream.exists()) { unsigned int fileRev, fileDim, fileParticleCount; stream >> fileRev >> fileDim >> fileParticleCount; if(rev == fileRev && fileDim == size && fileParticleCount == particles.size()) { stream >> *this; ASSERT(particles[0].position.size() == size); ASSERT(particles[0].velocity.size() == size); ASSERT(particles[0].bestPosition.size() == size); for(unsigned int i = 0; i < particles.size(); ++i) { Particle& particle(particles[i]); particle.bestFitness = minimize ? std::numeric_limits<float>::max() : std::numeric_limits<float>::min(); particle.rated = false; } bestParticleIndex = 0; currentParticleIndex = particles.size() - 1; return; }
void testApp::setup(){ // this number describes how many bins are used // on my machine, 2 is the ideal number (2^2 = 4x4 pixel bins) // if this number is too high, binning is not effective // because the screen is not subdivided enough. if // it's too low, the bins take up so much memory as to // become inefficient. int binPower = 3; particleSystem.setup(ofGetWidth(), ofGetHeight(), binPower); kParticles = 10; float padding = 0; float maxVelocity = .5; for(int i = 0; i < kParticles * 1024; i++) { float x = ofRandom(padding, ofGetWidth() - padding); float y = ofRandom(padding, ofGetHeight() - padding); float xv = ofRandom(-maxVelocity, maxVelocity); float yv = ofRandom(-maxVelocity, maxVelocity); Particle particle(x, y, xv, yv); particleSystem.add(particle); } ofBackground(0, 0, 0); timeStep = 1; lineOpacity = 128; pointOpacity = 255; isMousePressed = false; slowMotion = false; particleNeighborhood = 4; particleRepulsion = 1; centerAttraction = .01; }
//-------------------------------------------------------------- void AnimationParticlesMega2::createParticles() { if (m_resolution.x>0.0 && m_resolution.y>0.0 && !m_isParticlesInit) { int binPower = 3; particleSystem.setup(m_resolution.x, m_resolution.y, binPower); kParticles = 16; float padding = 0; float maxVelocity = .5; if (m_particlesPos) { delete[] m_particlesPos; m_particlesPos = 0; } if (m_particlesColor) { delete[] m_particlesColor; m_particlesColor = 0; } m_particlesPos = new ofVec3f[kParticles * 1024]; m_particlesColor = new ofFloatColor[kParticles * 1024]; for(int i = 0; i < kParticles * 1024; i++) { float x = ofRandom(padding, ofGetWidth() - padding); float y = ofRandom(padding, ofGetHeight() - padding); float xv = ofRandom(-maxVelocity, maxVelocity); float yv = ofRandom(-maxVelocity, maxVelocity); m_particlesPos[i].set(x,y); m_particlesColor[i].set( ofRandom(0.0f,1.0f) ); Particle particle(m_particlesPos+i, m_particlesColor+i, xv, yv); particleSystem.add(particle); } m_particlesVbo.setVertexData(m_particlesPos, kParticles * 1024, GL_DYNAMIC_DRAW); m_particlesVbo.setColorData(m_particlesColor, kParticles * 1024, GL_DYNAMIC_DRAW); timeStep = 1; lineOpacity = 128; pointOpacity = 255; isMousePressed = false; slowMotion = false; particleNeighborhood = 4; particleRepulsion = 1; centerAttraction = .01; m_isParticlesInit = true; } }
void emitTail(thor::EmissionInterface& system) { // Create initial direction with random vector length and angle thor::PolarVector2f velocity(thor::random(30.f, 70.f), thor::random(0.f, 360.f)); // Create particle at position of explosion, with emitter-specific color and at 80% initial scale thor::Particle particle(tailDuration); particle.position = mPosition; particle.color = mColor; particle.scale *= 0.8f; // A tail contains 25 particles with different speeds and scales. // The largest particles move fastest, leading to a comet-like tail effect. for (sf::Int64 i = 0; i < 25; ++i) { // Decrease scale continuously particle.scale *= 0.95f; // Decrease speed continuously velocity.r *= 0.96f; particle.velocity = velocity; // Add adapted particle to particle system system.emitParticle(particle); } }
//-------------------------------------------------------------- void ofApp::setup(){ //背景和图片设置 ofBackground( 0 , 0 , 0 ) ; image.loadImage ( "Elizabeth May.png" ) ; // 声音设置 mySound.loadSound("Kraftwerk - The Robots-2.mp3"); mySound.play(); //程序运行快慢设置 sampling = 2 ; //检索来自加载图像的像素 unsigned char * pixels = image.getPixels() ; int w = image.width ; int h = image.height ; //偏移中心的粒子子画面 int xOffset = (ofGetWidth() - w ) /2 ; int yOffset = (ofGetHeight() - h ) /2 ; //通过每一行像素的循环 for ( int x = 0 ; x < w ; x+=sampling ) { //通过每一列像素的循环 for ( int y = 0 ; y < h ; y+=sampling ) { //像素颜色设置 int index = ( y * w + x ) * 3 ; ofColor color ; color.r = pixels[index] ; color.g = pixels[index+1] ; color.b = pixels[index+2] ; particles.push_back( particle ( ofPoint ( x + xOffset , y + yOffset ) , color ) ) ; } } //像素弹起和下落的速度 ofSetFrameRate( 40 ) ; numParticles = ( image.width * image.height ) / sampling ; //弹起和下落相关值的设置 cursorMode = 0 ; forceRadius = 64 ; friction = 0.89 ; springFactor = 0.19 ; springEnabled = true ; //声音从最开始暂停 mySound.play(); mySound.setPaused(true); }
//-------------------------------------------------------------- void ofApp::mouseDragged(int x, int y, int button){ ofVec2f vel; vel.x = x - ofGetPreviousMouseX(); vel.y = y - ofGetPreviousMouseY(); Particle particle(ofVec2f(x, y), vel*0.3); particleList.push_back(particle); }
ParticlePath::ParticlePath(const Curve &particleCurve, unsigned int particleNumber): curve(particleCurve), number(particleNumber) { particles.reserve(number); srand (1); for(int i=0; i<number; ++i){ Particle particle((rand()%100+i*0.05)); particles.push_back(particle); } }
b2Body* GameCanvas::spawnLetter(char letter) { font.getGlyph(letter, fontSize, false); b2Body *body = world.CreateBody(&bodyDef); body->CreateFixture(&fixtureDef); LetterParticle particle(body, letter); letters.push_back(particle); return body; }
void ofApp::createParticles() { particle p = particle(); //set particles to be represented as tthe variable "p" p.changeAlpha();//call the change alpha function in the class p.particleLocation = blobLocation;//set the particle location to the blob location and pass it to the class p.particleRadius = scaledVol*30.0f;//set the radius of the particles to be what the recorded volume level is scaledVolInt = (int) p.particleRadius;//convert the float numbers of volume to be ints (makes it easier to work with) p.particleVelocity.x = scaledVolInt*(ofRandom(-2,2));//set the x velocity to be the currect scalled volume times 2 or -2 p.particleVelocity.y = scaledVolInt*(ofRandom(2,-2));//set the y velocity to be the currect scalled volume times -2 or 2 particles.push_back(p); }
//buildVector. populates the vector with particles void buildVector(){ int i; std::vector<particle>::iterator it; for (i = 0; i < numParticles; i++){ it = particles.begin(); particles.insert (it, particle()); } }
void add_particle(vec2 pos, vec2 vel, colour c, float s0, float s1, float s2, int max_t) { if (particle* p = g_particles.push_back(particle())) { p->bb.min = pos - 0.01f; p->bb.max = pos + 0.01f; p->vel = vel; p->s0 = s0; p->s1 = s1; p->s2 = s2; p->c = c; p->max_t = max_t; } }
void ParticleComponent::emitParticle() { Particle particle(mParticleLifetime()); particle.position = mParticlePosition() + getWorldPosition(); particle.velocity = mParticleVelocity(); particle.rotation = mParticleRotation(); particle.rotationSpeed = mParticleRotationSpeed(); particle.scale = mParticleScale(); particle.color = mParticleColor(); particle.textureIndex = mParticleTextureIndex(); mParticles.push_back(particle); }
uint32 FixEmitter(SnoFile<Actor>& actor) { if (1 || actor->x014_AppearanceSno.name() == "Emitter") { if (!actor->x080_MsgTriggeredEvents.size()) return actor->x000_Header.id; auto& name = actor->x080_MsgTriggeredEvents[0].x004_TriggerEvent.x02C_SNOName; if (name.type() != "Particle") return actor->x000_Header.id; SnoFile<Particle> particle(name.name()); if (!particle) return actor->x000_Header.id; if (!Actor::name(particle->x338_ActorSno)) return actor->x000_Header.id; //printf("Fixing emitter: %s -> %s\n", actor.name().c_str(), Actor::name(particle->x338_ActorSno)); return particle->x338_ActorSno; } }
//-------------------------------------------------------------- void ofApp::setup(){ ofSetWindowShape(1280, 720); //ofSetFullscreen(true); screenFbo.allocate(1280, 720); ofSetFrameRate(120); ofSetBackgroundAuto(false); ofSetBackgroundAuto(true); ofBackground(0); drawPoint = false; // tell the program to not draw the point at first //CAMERA setup//////////////////////////////////////////////////////////////////////////////////////////////////////////// grabber.setDeviceID(0); //grab our first cam device grabber.setDesiredFrameRate(120); //set framerate for cam grabber.initGrabber(1280, 720); //set our incoming size //CAMERA end///////////////////////////////////////////////////////////////////////////////////////////////////////////// //OPENCV setup//////////////////////////////////////////////////////////////////////////////////////////////////////////// image.allocate(grabber.width, grabber.height); //allocate our CV ColorImage with w/h based off cam greyImage.allocate(grabber.width, grabber.height); //same for other CV Images greyBackground.allocate(grabber.width, grabber.height); //same greyProcessed.allocate(grabber.width,grabber.height); //same maxBlobs = 1; //number of blobs allowed for the program to detect blobCenters.resize(maxBlobs); //set the size or our vector based off the numbe of blobs blobLocation = ofPoint(0,0); //OPENCV end///////////////////////////////////////////////////////////////////////////////////////////////////////////// // VISUALS setup////////////////////////////////////////////////////////////////////////////////////////////////////////// particleLoc = ofPoint(0,0); maxParticles = 1000;//max number of particles allowed in the vector fboTimer = 4;//set the FBO clear time to 4 //particles setup particle p = particle(); particles.push_back(p); //VISUALS end//////////////////////////////////////////////////////////////////////////////////////////////////////////// // AUDIO setup/////////////////////////////////////////////////////////////////////////////////////////////////////////// int bufferSize = 400;//size of the audio buffer micInput.setup(this, 0, 2, 44100, bufferSize, 4);//initialize the program to read mic input micInput.setDeviceID(3); audioFreq.assign(bufferSize, 0.0); volHistory.assign(400, 0.0); bufferCounter = 0; drawCounter = 0; smoothedVol = 0.0; scaledVol = 0.0;//scaled volume in float numbers scaledVolInt = 0;// scaled volume in integers //AUDIO end///////////////////////////////////////////////////////////////////////////////////////////////////////////// }
int kmparticle_id(int id) { particle_t* p = particle(id); if(p == NULL) { return -1; } HASH_DEL(particles, p); remove_body(p->body); free(p); return 0; }
void ParticleEmitter::update(float elapsedTime, const ParticleSystemPtr& system) { m_elapsedTime += elapsedTime; // check if finished if(m_duration > 0 && m_elapsedTime >= m_duration + m_delay) { m_finished = true; return; } if(!m_active && m_elapsedTime > m_delay) m_active = true; if(!m_active) return; int nextBurst = std::floor((m_elapsedTime - m_delay) * m_burstRate) + 1; const ParticleType *type = m_particleType.get(); for(int b = m_currentBurst; b < nextBurst; ++b) { // every burst created at same position. float pRadius = stdext::random_range(type->pMinPositionRadius, type->pMaxPositionRadius); float pAngle = stdext::random_range(type->pMinPositionAngle, type->pMaxPositionAngle); Point pPosition = m_position + Point(pRadius * std::cos(pAngle), pRadius * std::sin(pAngle)); for(int p = 0; p < m_burstCount; ++p) { float pDuration = stdext::random_range(type->pMinDuration, type->pMaxDuration); // particles initial velocity float pVelocityAbs = stdext::random_range(type->pMinVelocity, type->pMaxVelocity); float pVelocityAngle = stdext::random_range(type->pMinVelocityAngle, type->pMaxVelocityAngle); PointF pVelocity(pVelocityAbs * std::cos(pVelocityAngle), pVelocityAbs * std::sin(pVelocityAngle)); // particles initial acceleration float pAccelerationAbs = stdext::random_range(type->pMinAcceleration, type->pMaxAcceleration); float pAccelerationAngle = stdext::random_range(type->pMinAccelerationAngle, type->pMaxAccelerationAngle); PointF pAcceleration(pAccelerationAbs * std::cos(pAccelerationAngle), pAccelerationAbs * std::sin(pAccelerationAngle)); ParticlePtr particle(new Particle(pPosition, type->pStartSize, type->pFinalSize, pVelocity, pAcceleration, pDuration, type->pIgnorePhysicsAfter, type->pColors, type->pColorsStops, type->pCompositionMode, type->pTexture)); system->addParticle(particle); } } m_currentBurst = nextBurst; }
void ofApp::checkParticles() { particle p = particle(); if(particles.size() == maxParticles)//if the size of the Vector is equal to the maximum set size then erase the oldest { particles.erase(particles.begin());//erase the oldest } if(p.particleAlpha == 0)//if particle alpha is 0 { particles.erase(particles.begin());//delete the particles that have had their alpha reduced to zero } }
void RBezierParticles::add() { if (count() < mCount) { mVertices.insert(mVertices.end(), 3, 0.0f); mStartVertices.insert(mStartVertices.end(), 3, 0.0f); mEndVertices.insert(mEndVertices.end(), 3, 0.0f); mControlVertices.insert(mControlVertices.end(), 3, 0.0f); mStartTimes.push_back(RTime()); mLifeTimes.push_back(0.0f); RParticle p = particle(count()-1); reset(p); } }
void testApp::setup(){ kParticles = 8; float padding = 256; float maxVelocity = .5; for(int i = 0; i < kParticles * 1024; i++) { float x = ofRandom(padding, ofGetWidth() - padding); float y = ofRandom(padding, ofGetHeight() - padding); float xv = ofRandom(-maxVelocity, maxVelocity); float yv = ofRandom(-maxVelocity, maxVelocity); Particle particle(x, y, xv, yv); particleSystem.add(particle); } particleSystem.setTimeStep(1); ofBackground(0, 0, 0); }
void ParticleManager::reset(int particleNum, sf::Vector2u windowSize) { particles.clear(); std::random_device rd; std::default_random_engine gen(rd()); std::uniform_int_distribution<> disX(0, windowSize.x); std::uniform_int_distribution<> disY(0, windowSize.y); particleVertices.setPrimitiveType(sf::Points); particleVertices.resize(particleNum); for (int i = 0; i < particleNum; ++i) { Particle particle(&particleVertices[i], sf::Vector2f(disX(gen), disY(gen))); particles.push_back(particle); } }
void particleEmitter::addParticles(){ // get a starting line ofPoint from = points[ (int) ofRandom(-.4f, 2.4f) ];; ofPoint to = points[ (int) ofRandom(-.4f, 2.4f) ]; while( to == from) to = points[ (int) ofRandom(-.4f, 2.4f) ]; int amount = ofRandom(10,30); for(int i=0; i<amount; i++){ ofPoint pos = myLerp(from, to, ofRandom(0,1) ); ofPoint dir = pos - points[3]; int rNum = ofRandom(10,25); for(int ii=0; ii<rNum; ii++) particles.push_back( particle(pos, dir) ); } }
void operator()( const tbb::blocked_range3d<int, int, int>& range ) const { for( int s = range.pages().begin(); s != range.pages().end(); ++s ) { for( int x = range.rows().begin(); x != range.rows().end() && x < eval_base_.offset_x() + eval_base_.head_area_height() - s - 1; ++x ) { for( int y = range.cols().begin(); y != range.cols().end() && y < eval_base_.offset_y() + eval_base_.image().rows - s - 1; ++y ) { int best_direction; double probability = FindBestDirection( x, y, s, eval_base_, best_direction ); if( probability > max_probability_ ) { HeadPoseParticle particle( x, y, s, best_direction ); best_particle_ = particle; max_probability_ = probability; } } } } }
void operator()() const { for( int s = evaluator_.s_min_; s <= evaluator_.s_max_; ++s ) { for( int x = eval_base_.offset_x(); x < eval_base_.offset_x() + eval_base_.image().cols - s; ++x ) { for( int y = eval_base_.offset_y(); y < eval_base_.offset_y() + eval_base_.head_area_height() - s; ++y ) { int best_direction; double probability = FindBestDirection( x, y, s, eval_base_, best_direction ); if( probability > max_probability_ ) { HeadPoseParticle particle( x, y, s, best_direction ); best_particle_ = particle; max_probability_ = probability; } } } } }
//-------------------------------------------------------------- void particleSystem::update(ofVec2f _force){ for (int i = 0; i < 10; i++) { Particle particle(pos,vel); particleList.push_back(particle); } for (int i = 0; i < particleList.size(); i++) { particleList[i].resetForces(); particleList[i].applyForce(_force); particleList[i].update(); } while (particleList.size() > 1000) { particleList.erase(particleList.begin()); } }
void UniversalEmitter::operator() (EmissionInterface& system, sf::Time dt) { const std::size_t nbParticles = computeParticleCount(dt); for (std::size_t i = 0; i < nbParticles; ++i) { // Create particle and specify parameters Particle particle( mParticleLifetime() ); particle.position = mParticlePosition(); particle.velocity = mParticleVelocity(); particle.rotation = mParticleRotation(); particle.rotationSpeed = mParticleRotationSpeed(); particle.scale = mParticleScale(); particle.color = mParticleColor(); particle.textureIndex = mParticleTextureIndex(); system.emitParticle(particle); } }