Exemplo n.º 1
0
void testApp::setupData() {

    // GENERATING RANDOM VALUES
    int delta = iMaxRandomParticles * ((100.0-iDeltaRandomParticles)/100.0);
    data.generateRandomValues(delta, iMaxRandomParticles);
    
    // GETTING THE VALUES
    ppos = data.getPersonalPositives();
    pneu = data.getPersonalNeutrals();
    pneg = data.getPersonalNegatives();
    personalMinParticleSize = getMinParticleSize(ppos+pneu+pneg);
    
    npos = data.getNeighborhoodPositives();
    nneu = data.getNeighborhoodNeutrals();
    nneg = data.getNeighborhoodNegatives();
    neighborhoodMinParticleSize = getMinParticleSize(npos+nneu+nneg);
    
    cpos = data.getCityPositives();
    cneu = data.getCityNeutrals();
    cneg = data.getCityNegatives();
    cityMinParticleSize = getMinParticleSize(cpos+cneu+cneg);
    
    // LOGGING THE DATA
    string datalog = "- DATA --------------------------------------------- \n";
    datalog += "personal     (" + ofToString(ppos+pneu+pneg) + "): ";
    datalog += ofToString(ppos) + " / " + ofToString(pneu) + " / " + ofToString(pneg) + "\n";
    datalog += "neighborhood (" + ofToString(npos+nneu+nneg) + "): ";
    datalog += ofToString(npos) + " / " + ofToString(nneu) + " / " + ofToString(nneg) + "\n";
    datalog += "city         (" + ofToString(cpos+cneu+cneg) + "): ";
    datalog += ofToString(cpos) + " / " + ofToString(cneu) + " / " + ofToString(cneg) + "\n";
    datalog += "---------------------------------------------------- \n";
    ofLog(OF_LOG_NOTICE, datalog);

    // CLEARING VECTORS
    // the joints must be destroyed before the bodies they attach
    for(int j = 0; j < b2dJoints.size(); j++) {
        b2dJoints[j].destroy();
    }
    for(int i = 0; i < b2dParticles.size(); i++) {
        b2dParticles[i].destroy();
    }
    b2dJoints.clear();
    b2dParticles.clear();
    
    // ADDING PARTICLES
    isAddingParticles = true;
    addingStartTime = time(0);
    
    addParticles(PERSONAL, NEGATIVE, pneg);
    addParticles(NEIGHBORHOOD, NEGATIVE, nneg);
    addParticles(CITY, NEGATIVE, cpos);
    
}
Exemplo n.º 2
0
void ScenarioTest::doAutoTest()
{
    isStating = false;
    statCount = 0;
    totalStatTime = 0.0f;
    minFrameRate = -1.0f;
    maxFrameRate = -1.0f;
    
    // remove all nodes
    while (_spriteArray.size() > 0) {
        removeSprites();
    }
    while (_parsysArray.size() > 0) {
        removeParticleSystem();
    }
    
    // add nodes
    auto caseInfo = autoTestCounts[autoTestIndex];
    _particleNumber = 0;
    addNewSprites(caseInfo.spriteCount);
    addParticleSystem(caseInfo.particleSystemCount);
    addParticles(caseInfo.particleCount);

    schedule(CC_SCHEDULE_SELECTOR(ScenarioTest::beginStat), DELAY_TIME);
    schedule(CC_SCHEDULE_SELECTOR(ScenarioTest::endStat), DELAY_TIME + STAT_TIME);
}
Exemplo n.º 3
0
void ParticleEmitter::updateEmitterPositions()
{
	_updatingEmitterPositions = true;
	for (unsigned i = 0; i < _emitterPositions.size(); i++)
	{
		const D3DXVECTOR3 &currPosition = _emitterPositions[i].first;
		unsigned numParticles           = _emitterPositions[i].second;

		_origin = currPosition;
		addParticles(numParticles);
	}
	_updatingEmitterPositions = false;
}
Exemplo n.º 4
0
	float Group::addParticles(const Vector3D& start,const Vector3D& end,const Vector3D& velocity,float step,float offset)
	{
		if ((step <= 0.0f)||(offset < 0.0f))
			return 0.0f;

		Vector3D displacement = end - start;
		float totalDist = displacement.getNorm();

		while(offset < totalDist)
		{
			Vector3D position = start;
			position += displacement * (offset / totalDist);
			addParticles(1,position,velocity,NULL,NULL);
			offset += step;
		}

		return offset - totalDist;
	}
Exemplo n.º 5
0
float Group::addParticles(const Vector3D& start, const Vector3D& end, Emitter* emitter, float step, float offset)
{
	if( (step <= 0.0f) || (offset < 0.0f) )
		return 0.0f;

	Vector3D displacement = end - start;
	float totalDist = displacement.GetLength();

	while(offset < totalDist)
	{
		Vector3D position = start;
		position += displacement * offset / totalDist;
		addParticles(1, position, Vector3D(0,0,0), NULL, emitter);
		offset += step;
	}

	return offset - totalDist;
}
Exemplo n.º 6
0
void ParticleEmitter::updateEmitterEntities()
{
	_updatingEmitterEntities = true;
	for (EmitterEntityList::iterator it = _emitterEntities.begin();
		 it != _emitterEntities.end(); )
	{
		const EntityPtr &currEntity = it->first;
		unsigned numParticles       = it->second;

		if (!currEntity || currEntity->isDead())
			it = _emitterEntities.erase(it);
		else
		{
			_origin = currEntity->getPos();
			addParticles(numParticles);
			++it;
		}
	}
	_updatingEmitterEntities = false;
}
Exemplo n.º 7
0
/*
 =======================================================================================================================
 =======================================================================================================================
 */
void CDialogTextures::BuildTree() {
    CWaitCursor cursor;
    m_treeTextures.DeleteAllItems();
    bool rootItems = m_chkHideRoot.GetCheck() == 0;

    idTimer timer;

    timer.Start();

    addMaterials( rootItems );
    // _D3XP removed
    //addModels( rootItems );
    addScripts( rootItems );
    addSounds( rootItems );
    addGuis( rootItems );
    addParticles( rootItems );

    timer.Stop();

    common->Printf( "CDialogTextures::BuildTree() took %.0f milliseconds\n", timer.Milliseconds() );
}
Exemplo n.º 8
0
bool ExplosionEmitter::onDeath(const Event &event)
{
	EvEntityDie_data *eventData = event.getRawData<EvEntityDie_data>();
	Entity *entityToDie   = eventData->_entityToDie; 
	D3DXVECTOR3 position  = eventData->_deathPosition;

	// If you are a projectile that does radial damage, or if you
	// are an entity who is supposed to explode when dying, (e.g. if 
	// you are an airship) then play an explosion!
	if (entityToDie->getRadialDamage() > 0 || 
		entityToDie->getDeathMode() == Entity::death_explodes)
	{
		//// Center the explosion at the entity's bounding box's center.
		//const BoundingBox &boundingBox = entityToDie->getBoundingBox();
		//D3DXVECTOR3 boundingBoxCenter((boundingBox.min + boundingBox.max) / 2 + position);

		//_origin = boundingBoxCenter;
		_origin = position;
		addParticles(400);
	}

	return false;
}
Exemplo n.º 9
0
//--------------------------------------------------------------
// MARK: PARTICLES
//--------------------------------------------------------------
void testApp::initParticles() {
    
    GREEN     = ofColor(f4Green[0]*255,     f4Green[1]*255,     f4Green[2]*255,     f4Green[3]*255);
    YELLOW    = ofColor(f4Yellow[0]*255,    f4Yellow[1]*255,    f4Yellow[2]*255,    f4Yellow[3]*255);
    RED       = ofColor(f4Red[0]*255,       f4Red[1]*255,       f4Red[2]*255,       f4Red[3]*255);
    GRAY      = ofColor(f4Gray[0]*255,      f4Gray[1]*255,      f4Gray[2]*255,      f4Gray[3]*255);
    HIGHLIGHT = ofColor(f4Highlight[0]*255, f4Highlight[1]*255, f4Highlight[2]*255, f4Highlight[3]*255);     
    
    streetParticles.clear();    
    neighborhoodParticles.clear();
    cityParticles.clear();
    
    data.particlesMultiplier  = iParticlesMultiplier;
    data.maxParticlesPerPanel = iMaxParticlesPerPanel * 100;
    
    // logging the data
    string datalog = "\n";
    datalog += "- DATA --------------------------------------------- \n";
    datalog += "street       (";
    datalog += ofToString(data.getStreetPositives()+data.getStreetNeutrals()+data.getStreetNegatives()) + "): ";
    datalog += ofToString(data.getStreetPositives()) + " / ";
    datalog += ofToString(data.getStreetNeutrals()) + " / ";
    datalog += ofToString(data.getStreetNegatives()) + "\n";
    datalog += "neighborhood (";
    datalog += ofToString(data.getNeighborhoodPositives()+data.getNeighborhoodNeutrals()+data.getNeighborhoodNegatives()) + "): ";
    datalog += ofToString(data.getNeighborhoodPositives()) + " / ";
    datalog += ofToString(data.getNeighborhoodNeutrals()) + " / ";
    datalog += ofToString(data.getNeighborhoodNegatives()) + "\n";
    datalog += "city         (";
    datalog += ofToString(data.getCityPositives()+data.getCityNeutrals()+data.getCityNegatives()) + "): ";
    datalog += ofToString(data.getCityPositives()) + " / ";
    datalog += ofToString(data.getCityNeutrals()) + " / ";
    datalog += ofToString(data.getCityNegatives()) + "\n";
    datalog += "---------------------------------------------------- \n";
    ofLogNotice() << datalog;
    
    // ADDING street particles
    addParticles(streetParticles, iGhostParticles * 100,  GRAY,   *streetPath);
    addParticles(streetParticles, data.getStreetNegatives(), RED,    *streetPath);
    addParticles(streetParticles, data.getStreetNeutrals(),  YELLOW, *streetPath);
    addParticles(streetParticles, data.getStreetPositives(), GREEN,  *streetPath);
    
    // ADDING neighborhood particles
    addParticles(neighborhoodParticles, iGhostParticles * 100,  GRAY,   *neighborhoodPath);
    addParticles(neighborhoodParticles, data.getNeighborhoodNegatives(), RED,    *neighborhoodPath);
    addParticles(neighborhoodParticles, data.getNeighborhoodNeutrals(),  YELLOW, *neighborhoodPath);
    addParticles(neighborhoodParticles, data.getNeighborhoodPositives(), GREEN,  *neighborhoodPath);
    
    // ADDING city particles
    addParticles(cityParticles, iGhostParticles * 100,  GRAY,   *cityPath); // GHOSTS
    addParticles(cityParticles, data.getCityNegatives(), RED,    *cityPath);
    addParticles(cityParticles, data.getCityNeutrals(),  YELLOW, *cityPath);
    addParticles(cityParticles, data.getCityPositives(), GREEN,  *cityPath);
    
}
Exemplo n.º 10
0
//--------------------------------------------------------------
void testApp::update(){
    
    ofBackground(0);
    
    kinect.updateThreshPar(iFarThreshold, iNearThreshold);
    kinect.updateBlobPar(iMinBlobSize, iMaxBlobSize, iMaxNumBlobs);
    
    if(!bLockKinTilt) {
        kinect.setKinTiltAngle(false, fKin1TiltAngle);
        kinect.setKinTiltAngle(true, fKin2TiltAngle);
    }
    
    kinect.update();
    
    if(bResetData) {
        bResetData = false;
        setupData();
    }
    
    if( isAddingParticles ) {
        if(!hasAddedNeutrals && time(0)-addingStartTime > addingWaitTime ) {
            addParticles(PERSONAL, NEUTRAL, pneu);
            addParticles(NEIGHBORHOOD, NEUTRAL, nneu);
            addParticles(CITY, NEUTRAL, cneu);
            
            hasAddedNeutrals = true;
        }
        if(hasAddedNeutrals && time(0)-addingStartTime > (addingWaitTime * 2)) {
            addParticles(PERSONAL, POSITIVE, ppos);
            addParticles(NEIGHBORHOOD, POSITIVE, npos);
            addParticles(CITY, POSITIVE, cpos);
            
            isAddingParticles = false;
            hasAddedNeutrals = false;
        }
    }
    

    // CONVERT TOP AND BOTTOM ANCHORS INTO POSITIVES AND NEGATIVES ATTRACTION POINTS
    for(int i = 0; i < b2dParticles.size(); i++) {
        Data * customData = (Data*)b2dParticles[i].getData();        
        switch(customData->scope) {
            case PERSONAL:
                if(customData->type == NEGATIVE) {
                    b2dParticles[i].addAttractionPoint(personalAnchorBottom.getPosition(), fAttractionForce);
                    b2dParticles[i].addRepulsionForce(personalCenter, fAttractionForce);
                } else if(customData->type == NEUTRAL) {
                    b2dParticles[i].addAttractionPoint(personalCenter, fAttractionForce);                    
                } else if(customData->type == POSITIVE) {
                    b2dParticles[i].addAttractionPoint(personalAnchorTop.getPosition(), fAttractionForce);
                    b2dParticles[i].addRepulsionForce(personalCenter, fAttractionForce);
                }
                break;
            case NEIGHBORHOOD:
                if(customData->type == NEGATIVE) {
                    b2dParticles[i].addAttractionPoint(neighborhoodAnchorBottom.getPosition(), fAttractionForce);
                    b2dParticles[i].addRepulsionForce(neighborhoodCenter, fAttractionForce);
                } else if(customData->type == NEUTRAL) {
                    b2dParticles[i].addAttractionPoint(neighborhoodCenter, fAttractionForce);                    
                } else if(customData->type == POSITIVE) {
                    b2dParticles[i].addAttractionPoint(neighborhoodAnchorTop.getPosition(), fAttractionForce);
                    b2dParticles[i].addRepulsionForce(neighborhoodCenter, fAttractionForce);
                }
                break;
            case CITY:
                if(customData->type == NEGATIVE) {
                    b2dParticles[i].addAttractionPoint(cityAnchorBottom.getPosition(), fAttractionForce);
                    b2dParticles[i].addRepulsionForce(cityCenter, fAttractionForce);
                } else if(customData->type == NEUTRAL) {
                    b2dParticles[i].addAttractionPoint(cityCenter, fAttractionForce);                    
                } else if(customData->type == POSITIVE) {
                    b2dParticles[i].addAttractionPoint(cityAnchorTop.getPosition(), fAttractionForce);
                    b2dParticles[i].addRepulsionForce(cityCenter, fAttractionForce);
                }
                break;
        }
    }
    
    box2d.wakeupShapes();    
    box2d.update();	

    
    // MARK: BLOBS BOXES

    
    // destroy dead blobs/boxes
    for(map<int, ofxBox2dRect>::iterator it = b2dBlobs.begin(); it != b2dBlobs.end(); it++) {
        if( kinect.foundBlobsMap.find((*it).first) == kinect.foundBlobsMap.end() ) {
            ((*it).second).destroy();
            b2dBlobs.erase(it);
        }
    }
    
    // update and add blobs/boxes
    for(int i = 0; i < kinect.activeBlobsIds.size(); i++) {
        
        // search for the key on the map
        int theKey = kinect.activeBlobsIds[i];
        ofxBlob b = kinect.foundBlobsMap[theKey];
        map<int, ofxBox2dRect>::iterator it = b2dBlobs.find(theKey);

        // if it's already on it, update box
        if( it != b2dBlobs.end() ) {
            // inverting blob x
            float x = ofMap(b.centroid.x, 1.0f, 0.0f, 0.0f, 1.0f);
            b2dBlobs[theKey].setPosition(x * FBO_W, b.centroid.y * FBO_H);
        }
        
        // else, add box to the map and the world 
        else {
            ofxBox2dRect r;
            r.setPhysics(fDensity, fBounce, fFriction);
            // inverting blob x
            float x = ofMap(b.centroid.x, 1.0f, 0.0f, 0.0f, 1.0f);
            r.setup(box2d.getWorld(), x * FBO_W, b.centroid.y * FBO_H, 
                    b.boundingRect.width * FBO_W, b.boundingRect.height * FBO_H);
            
            b2dBlobs[theKey] = r;
        }
    }
    
    
    
// MARK: UPDATE ATTRACTION FORCE
//    for(int i = 0; i < b2dParticles.size(); i++) {        
//        Data * customData = (Data*)b2dParticles[i].getData();        
//        b2dParticles[i].addAttractionPoint(customData->attractionPoint, fAttractionForce);
//    }
    
}
void mapLagrangian(const meshToMesh& interp)
{
    // Determine which particles are in meshTarget
    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    const polyMesh& meshSource = interp.srcRegion();
    const polyMesh& meshTarget = interp.tgtRegion();
    const labelListList& sourceToTarget = interp.srcToTgtCellAddr();

    const pointField& targetCc = meshTarget.cellCentres();

    fileNameList cloudDirs
    (
        readDir
        (
            meshSource.time().timePath()/cloud::prefix,
            fileName::DIRECTORY
        )
    );

    forAll(cloudDirs, cloudI)
    {
        // Search for list of lagrangian objects for this time
        IOobjectList objects
        (
            meshSource,
            meshSource.time().timeName(),
            cloud::prefix/cloudDirs[cloudI]
        );

        IOobject* positionsPtr = objects.lookup(word("positions"));

        if (positionsPtr)
        {
            Info<< nl << "    processing cloud " << cloudDirs[cloudI] << endl;

            // Read positions & cell
            passiveParticleCloud sourceParcels
            (
                meshSource,
                cloudDirs[cloudI],
                false
            );
            Info<< "    read " << sourceParcels.size()
                << " parcels from source mesh." << endl;

            // Construct empty target cloud
            passiveParticleCloud targetParcels
            (
                meshTarget,
                cloudDirs[cloudI],
                IDLList<passiveParticle>()
            );

            particle::TrackingData<passiveParticleCloud> td(targetParcels);

            label sourceParticleI = 0;

            // Indices of source particles that get added to targetParcels
            DynamicList<label> addParticles(sourceParcels.size());

            // Unmapped particles
            labelHashSet unmappedSource(sourceParcels.size());


            // Initial: track from fine-mesh cell centre to particle position
            // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            // This requires there to be no boundary in the way.


            forAllConstIter(Cloud<passiveParticle>, sourceParcels, iter)
            {
                bool foundCell = false;

                // Assume that cell from read parcel is the correct one...
                if (iter().cell() >= 0)
                {
                    const labelList& targetCells =
                        sourceToTarget[iter().cell()];

                    // Particle probably in one of the targetcells. Try
                    // all by tracking from their cell centre to the parcel
                    // position.

                    forAll(targetCells, i)
                    {
                        // Track from its cellcentre to position to make sure.
                        autoPtr<passiveParticle> newPtr
                        (
                            new passiveParticle
                            (
                                meshTarget,
                                targetCc[targetCells[i]],
                                targetCells[i]
                            )
                        );
                        passiveParticle& newP = newPtr();

                        label facei = newP.track(iter().position(), td);

                        if (facei < 0 && newP.cell() >= 0)
                        {
                            // Hit position.
                            foundCell = true;
                            addParticles.append(sourceParticleI);
                            targetParcels.addParticle(newPtr.ptr());
                            break;
                        }
                    }
                }

                if (!foundCell)
                {
                    // Store for closer analysis
                    unmappedSource.insert(sourceParticleI);
                }

                sourceParticleI++;
            }
Exemplo n.º 12
0
	void Group::addParticles(Emitter* emitter,float deltaTime)
	{
		addParticles(emitter->updateNumber(deltaTime),Vector3D(),Vector3D(),emitter->getZone(),emitter,emitter->isFullZone());
	}
Exemplo n.º 13
0
	void Group::addParticles(const Vector3D& position,Emitter* emitter,float deltaTime)
	{
		addParticles(emitter->updateNumber(deltaTime),position,Vector3D(),NULL,emitter);
	}
Exemplo n.º 14
0
	void Group::addParticles(const Zone* zone,Emitter* emitter,float deltaTime,bool full)
	{
		addParticles(emitter->updateNumber(deltaTime),Vector3D(),Vector3D(),zone,emitter,full);
	}
Exemplo n.º 15
0
	void Group::addParticles(unsigned int nb,Emitter* emitter)
	{
		addParticles(nb,Vector3D(),Vector3D(),emitter->getZone(),emitter,emitter->isFullZone());
	}
Exemplo n.º 16
0
void Group::addParticles(uint32 number, Emitter* emitter)
{
	addParticles(number, Vector3D(0,0,0), Vector3D(0,0,0), emitter->getZone(), emitter, emitter->isFullZone());
}
Exemplo n.º 17
0
void testApp::addParticles(int scope, int type, int num) {
    addParticles(scope, type, num, fDensity, fBounce, fFriction);
}
Exemplo n.º 18
0
void ScenarioTest::performTests()
{
    auto listener = EventListenerTouchAllAtOnce::create();
    listener->onTouchesMoved = CC_CALLBACK_2(ScenarioTest::onTouchesMoved, this);
    _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);

    _particleNumber = _initParticleNum;

    // get the window size & origin position
    auto s = Director::getInstance()->getVisibleSize();
    auto origin = Director::getInstance()->getVisibleOrigin();

    // add tile map
    _map1 = TMXTiledMap::create("TileMaps/iso-test.tmx");
    _map1->setAnchorPoint( Vec2(0.5, 0.5) );
    _map1->setPosition(origin);
    this->addChild(_map1);

    _map2 = TMXTiledMap::create("TileMaps/iso-test2.tmx");
    _map2->setAnchorPoint( Vec2(0.5, 0.5) );
    _map2->setPosition(origin);
    this->addChild(_map2);

    // add toggle menu item
    MenuItemFont::setFontSize(20);
    _itemToggle = MenuItemToggle::createWithCallback(nullptr,
                                                    MenuItemFont::create( "Add/Remove Sprite" ),
                                                    MenuItemFont::create( "Add/Remove Particle"),
                                                    MenuItemFont::create( "Add/Remove Particle System"),
                                                    nullptr);
    _itemToggle->setAnchorPoint(Vec2(0.0f, 0.5f));
    _itemToggle->setPosition(Vec2(origin.x, origin.y + s.height / 2));

    // add decrease & increase menu item
    MenuItemFont::setFontSize(65);
    auto decrease = MenuItemFont::create(" - ", [&](Ref *sender) {
		int idx = _itemToggle->getSelectedIndex();
        switch (idx) {
        case 0:
            removeSprites();
            break;
        case 1:
            removeParticles();
            break;
        case 2:
            removeParticleSystem();
            break;
        default:
            break;
        }
	});
    decrease->setPosition(Vec2(origin.x + s.width / 2 - 80, origin.y + 80));
    decrease->setColor(Color3B(0,200,20));
    auto increase = MenuItemFont::create(" + ", [&](Ref *sender) {
		int idx = _itemToggle->getSelectedIndex();
        switch (idx) {
        case 0:
            addNewSprites(_spriteStepNum);
            break;
        case 1:
            addParticles(_parStepNum);
            break;
        case 2:
            addParticleSystem(_parsysStepNum);
            break;
        default:
            break;
        }
	});
    increase->setColor(Color3B(0,200,20));
    increase->setPosition(Vec2(origin.x + s.width / 2 + 80, origin.y + 80));
    
    auto menu = Menu::create(_itemToggle, decrease, increase, nullptr);
    menu->setPosition(Vec2(0.0f, 0.0f));
    addChild(menu, 10);

    
    // add tip labels
    _spriteLabel = Label::createWithTTF("Sprites : 0", "fonts/arial.ttf", 15);
    _spriteLabel->setAnchorPoint(Vec2(0.0f, 0.5f));
    addChild(_spriteLabel, 10);
    _spriteLabel->setPosition(Vec2(origin.x, origin.y + s.height/2 + 70));
    
    char str[32] = { 0 };
    sprintf(str, "Particles : %d", _particleNumber);
    _particleLabel = Label::createWithTTF(str, "fonts/arial.ttf", 15);
    _particleLabel->setAnchorPoint(Vec2(0.0f, 0.5f));
    addChild(_particleLabel, 10);
    _particleLabel->setPosition(Vec2(origin.x, origin.y + s.height/2 + 45));
    
    _parsysLabel = Label::createWithTTF("Particle System : 0", "fonts/arial.ttf", 15);
    _parsysLabel->setAnchorPoint(Vec2(0.0f, 0.5f));
    addChild(_parsysLabel, 10);
    _parsysLabel->setPosition(Vec2(origin.x, origin.y + s.height/2 + 20));

    // add sprites
    addNewSprites(_initSpriteNum);
    
    // add particle system
    addParticleSystem(_initParsysNum);
}