当前位置: 首页>>代码示例>>C++>>正文


C++ ParticleManager::addParticle方法代码示例

本文整理汇总了C++中ParticleManager::addParticle方法的典型用法代码示例。如果您正苦于以下问题:C++ ParticleManager::addParticle方法的具体用法?C++ ParticleManager::addParticle怎么用?C++ ParticleManager::addParticle使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ParticleManager的用法示例。


在下文中一共展示了ParticleManager::addParticle方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: createString

	// Create a particleGraph
	ParticleGraph createString(glm::vec2 A, glm::vec2 B, glm::vec3 color, glm::vec3 headColor, uint32_t discFactor, ParticleManager& particleManager) {
	    glm::vec2 AB = B - A;
	    glm::vec2 step = glm::vec2(AB[0]/discFactor, AB[1]/discFactor);
	    glm::vec2 position = A;
	    float mass = 1.f;

	    ParticleGraph graph;

	    unsigned int id = 0;

	    for(int i = 0; i < discFactor + 1; ++i) {
	        id = particleManager.addParticle(mass, position, glm::vec2(0.f, 0.f), glm::vec2(0.f, 0.f), color, ParticleManager::Type::P_SNAKE);
	        if(id != 0) {
	            std::pair<unsigned int, unsigned int> pair (id, id - 1);
	            graph.push_back(pair);    
	        }
	        else if(id == discFactor) {
	            std::pair<unsigned int, unsigned int> pair (id, 0);  
	            graph.push_back(pair);   

	        }
	  
	        position += step;
	    }
	    particleManager.getParticleColor(0) = headColor;
	    return graph;
	}
开发者ID:eprana,项目名称:Zipix,代码行数:28,代码来源:Game.cpp

示例2: copyParticle

	// Copy a particle
	int copyParticle(ParticleManager& sourceManager, ParticleManager& destinationManager, int id) {
		int newId = destinationManager.addParticle(sourceManager.getParticleMass(id),
                            sourceManager.getParticlePosition(id),           
                            sourceManager.getParticleVelocity(id),
                            sourceManager.getParticleForce(id),
                            sourceManager.getParticleColor(id));

		return newId;
	}
开发者ID:eprana,项目名称:Zipix,代码行数:10,代码来源:Game.cpp

示例3: main

int main() {
    WindowManager wm(WINDOW_WIDTH, WINDOW_HEIGHT, "ZIPIX");
    wm.setFramerate(30);

    // FMOD
    FMOD_SYSTEM *system;

    /* Création et initialisation d'un objet système */
    FMOD_System_Create(&system);
    FMOD_System_Init(system, 2, FMOD_INIT_NORMAL, NULL);

    FMOD_SOUND* background = NULL;
    FMOD_SOUND* firework = NULL;

    FMOD_RESULT check;

    check = FMOD_System_CreateSound(system, "../music/firework_explode_and_crackle.mp3", FMOD_CREATESAMPLE, 0, &firework);
    if (check != FMOD_OK)
    {
        fprintf(stderr, "Impossible de lire le fichier firework_explode_and_crackle.mp3\n");
        exit(EXIT_FAILURE);
    }
    check = FMOD_System_CreateSound(system, "../music/Timer.mp3", FMOD_SOFTWARE | FMOD_2D | FMOD_CREATESTREAM, 0, &background);
    
    if (check != FMOD_OK)
    {
        fprintf(stderr, "Impossible de lire le fichier Timer.mp3\n");
        exit(EXIT_FAILURE);
    }
    
    FMOD_CHANNEL *backgroundChannel = NULL;
    FMOD_CHANNEL *fireworkChannel = NULL;
    FMOD_System_GetChannel(system, 0, &backgroundChannel);
    FMOD_System_GetChannel(system, 1, &fireworkChannel);
    FMOD_Sound_SetLoopCount(background, -1);


    FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, background, 0, &backgroundChannel);

    // Time
    time_t beginTime;
    time_t currentTime;
    time(&beginTime);

    // Managers and Renderer
    ParticleRenderer2D renderer;

    ParticleManager snakeManager;
    snakeManager.setHeadColor(glm::vec3(0.4f, 0.8f, 0.3f));
    ParticleManager redManager;
    redManager.setHeadColor(glm::vec3(0.9f, 0.4f, 0.3f));
    ParticleManager blueManager;
    blueManager.setHeadColor(glm::vec3(0.2f, 0.4f, 0.9f));

    ParticleManager foodManager;
    ParticleManager bonusManager;
    ParticleManager fireworkManager;

    ParticleManager autoManager;

    // Graph Forces
    GraphHookForce graphHook = GraphHookForce(1.f, 0.15f/4.f);
    GraphBrakeForce graphBrake = GraphBrakeForce(0.3f, 10.f); // 0.5 = viscosité max 
    
    GraphHookForce redGraphHook = GraphHookForce(1.f, 0.15f/4.f);
    GraphBrakeForce redGraphBrake = GraphBrakeForce(0.3f, 0.0001f);

    GraphHookForce blueGraphHook = GraphHookForce(1.f, 0.15f/4.f);
    GraphBrakeForce blueGraphBrake = GraphBrakeForce(0.3f, 0.0001f);

    // Box
    Polygon box = buildBox(glm::vec3(1.f, 1.f, 1.f), glm::vec2(-1.f, -1.f), 2, 2, true);

    // // Ajout des particules
    int id = foodManager.addRandomParticle(1);
    bonusManager.addParticle(1.5f, glm::vec2(0.5, 0.5), glm::vec2(0, 0), glm::vec2(0, 0), glm::vec3(0.619f, 0.05f, 0.25f));
    bonusManager.addParticle(1.5f, glm::vec2(-0.2, 0.6), glm::vec2(0, 0), glm::vec2(0, 0), glm::vec3(0.619f, 0.05f, 0.25f));
    bonusManager.addParticle(1.5f, glm::vec2(0.8, -0.7), glm::vec2(0, 0), glm::vec2(0, 0), glm::vec3(0.619f, 0.05f, 0.25f));
    bonusManager.addParticle(1.5f, glm::vec2(-0.7, -0.5), glm::vec2(0, 0), glm::vec2(0, 0), glm::vec3(0.619f, 0.05f, 0.25f));
    bonusManager.addParticle(1.5f, glm::vec2(0.3, -0.1), glm::vec2(0, 0), glm::vec2(0, 0), glm::vec3(0.619f, 0.05f, 0.25f));

    // Copy the food to the autoManager
    copyParticle(foodManager, autoManager, id);

    // Forces
    ConstantForce mg(glm::vec2(0.f, -0.005));

    // LeapfrogSolver
    LeapfrogSolver leapfrog;
    PolygonForce boxForce(box, 1.5f, leapfrog);

    // Snake's creation
    ParticleGraph snakeGraph = createString(glm::vec2(0.f, 0.0f), glm::vec2(0.f, -0.15f), glm::vec3(0.2f, 0.6f, 0.2f), glm::vec3(0.4f, 0.8f, 0.3f), 4.f, snakeManager);
    ParticleGraph redGraph = createString(glm::vec2(0.f, 0.2f), glm::vec2(0.15f, 0.2f), glm::vec3(0.9f, 0.2f, 0.2f), glm::vec3(0.9f, 0.4f, 0.3f), 4.f, redManager);
    ParticleGraph blueGraph = createString(glm::vec2(0.f, -0.2f), glm::vec2(-0.15f, -0.2f), glm::vec3(0.2f, 0.2f, 0.6f), glm::vec3(0.2f, 0.4f, 0.9f), 4.f, blueManager);

    copyParticle(snakeManager, autoManager, 0);
    copyParticle(redManager, autoManager, 0);
    copyParticle(blueManager, autoManager, 0);

//.........这里部分代码省略.........
开发者ID:eprana,项目名称:Zipix,代码行数:101,代码来源:main.cpp


注:本文中的ParticleManager::addParticle方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。