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


C++ ParticleEmitter::update方法代码示例

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


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

示例1: updateEmitters

void ParticleSystem::updateEmitters( float milliseconds )
{
	for(EmitterSet::const_iterator i=emitters.begin(); i!=emitters.end(); ++i)
	{
		ParticleEmitter *emitter = *i;
		emitter->update(milliseconds);
	}
}
开发者ID:foxostro,项目名称:heroman,代码行数:8,代码来源:ParticleSystem.cpp

示例2: update

void ParticleSystem::update(float delta) {
    if (sprite == NULL) {
        std::cout << "sprite was null" << std::endl;
        return;
        return;
    }
    removeMe.clear();

    //std::cout << "1" << std::endl;


    for(unsigned int i = 0; i < emitters.size(); i++) {
        ParticleEmitter* emitter = emitters.at(i);
        if (emitter->isEnabled()) {
            //std::cout << "en" << std::endl;
            emitter->update(this, delta);
            //std::cout << "en2" << std::endl;
            if (removeCompletedEmitters) {
                if (emitter->isComplete()) {
                    removeMe.push_back(emitter);
                    particlesByEmitter.erase(emitter);
                }
            }
        }
    }

    //std::cout << "2" << std::endl;

    // remove items in removeMe from emitters.
    vector<ParticleEmitter*>::iterator ito = emitters.begin();
    while (ito != emitters.end()) {
        ParticleEmitter* e = (*ito);

        vector<ParticleEmitter*>::iterator ito2 = removeMe.begin();
        while (ito2 != removeMe.end()) {
            ParticleEmitter* e2 = (*ito2);

            if (e == e2) {
                ito = emitters.erase(ito);
                continue;
            }

            ito2++;
        }

        ito++;
    }

    //std::cout << "3" << std::endl;

    pCount = 0;

    if (!particlesByEmitter.empty()) {
        //std::cout << "4: " << particlesByEmitter.size() << std::endl;
        map<ParticleEmitter*, ParticlePool*>::iterator it = particlesByEmitter.begin();
        while (it != particlesByEmitter.end()) {
            ParticleEmitter* emitter = it->first;
            if (emitter->isEnabled()) {
                ParticlePool* pool = it->second;
                //std::cout << "5" << std::endl;
                for (unsigned int i = 0; i < pool->particlesActive.size(); i++) {
                    if (pool->particlesActive.at(i)->getLife() > 0) {
                        pool->particlesActive.at(i)->update(delta);
                        pCount++;
                    }
                }
            }
            it++;
            //std::cout << "6" << std::endl;
        }
    }
}
开发者ID:ashleygwinnell,项目名称:ark2d,代码行数:72,代码来源:ParticleSystem.cpp

示例3: main

// main program
int main (int argc, char * const argv[])
{
	argc;
	argv;
	bool success = false;
	srand(1);

	// initialize timers:------------------------------
		// Initialize timer
		timer::initTimer();

		// Create a global Timer
		globalTimer::create();

		// Create a timer objects
		timer updateTimer;
		timer drawTimer;

	// create a window:---------------------------------
		success = OpenGLDevice::InitWindow();
		assert(success);
	
	// create an emitter:-------------------------------
		ParticleEmitter emitter;

	// Get the inverse Camera Matrix:-------------------

		// initialize the camera matrix
		Matrix cameraMatrix;
		cameraMatrix.setIdentMatrix();

		// setup the translation matrix
		Matrix transMatrix;
		Vect4D trans(0.0f,3.0f,10.0f);
		transMatrix.setTransMatrix( trans );

		// multiply them together
		Matrix tmp;
		tmp = cameraMatrix * transMatrix;

		// get the inverse matrix
		Matrix inverseCameraMatrix;
		tmp.Inverse(inverseCameraMatrix);

	// counter for printing
	int i = 0;

	// main update loop... do this forever or until some breaks 
	while(OpenGLDevice::IsRunning())
	{
		// start update timer ---------------------------------------
		updateTimer.tic();

			// start draw... end draw (the draw updates)
			OpenGLDevice::StartDraw();
		
			// set matrix to Model View
			// push the inverseCameraMarix to stack
			glMatrixMode(GL_MODELVIEW);
			glLoadMatrixf(reinterpret_cast<float*>(&inverseCameraMatrix));
			glPushMatrix(); // push the camera matrix

			// update the emitter
			emitter.update();

		// stop update timer: -----------------------------------------
		updateTimer.toc();

		// start draw timer: ----------------------------------------
		drawTimer.tic();

			// draw particles
			emitter.draw();
		
			// pop matrix - needs to correspond to previous push
			glPopMatrix();

		// stop draw timer: -----------------------------------------
		drawTimer.toc();

		// finish draw update
		OpenGLDevice::EndDraw();

		// Love for Windows - allows the windows to behave to external events
		EventHandler::ProcessEvents();

		// update ouput every 50 times
		i++;
		if( i > 50 ) 
		{
			i = 0;
			float updateTime = updateTimer.timeInSeconds();
			float drawTime = drawTimer.timeInSeconds();
			printf("LoopTime: update:%f ms  draw:%f ms  tot:%f\n",updateTime * 1000.0f, drawTime * 1000.0f, (updateTime + drawTime) *1000.0f);
		}
	}
	
    return 0;
}
开发者ID:rgomezer,项目名称:Coding-Samples,代码行数:100,代码来源:main.cpp


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