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


C++ ITimer类代码示例

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


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

示例1: main

int main()
{

	IDevice* device = createDevice(EDT_DIRECT3D11, 800, 600);
	IVideoDriver* driver = device->getVideoDriver();
	IResourceGroupManager* resourceGroupManager = driver->getResourceGroupManager();
	resourceGroupManager->init("Resources.cfg");

	IInputDriver* input = device->getInputDriver();

	ISceneManager* smgr = setupScene(device);
	driver->setDeferredShading(true);
	ITimer* timer = device->getTimer();
	timer->reset();

	const f32 color[] = { 0, 0, 0, 1.0f };
	while (device->run()) {
		float dt = timer->tick();
		if (input->keyDown(GVK_ESCAPE))
			break;

		smgr->update(dt);
		driver->beginScene(true, true, color);
		smgr->drawAll();
		driver->endScene();
	}

	smgr->destroy();
	device->drop();

	return 0;
}
开发者ID:whztt07,项目名称:GameFinal,代码行数:32,代码来源:main.cpp

示例2: main

int main()
{
	IDevice* device = createDevice(EDT_DIRECT3D11, 800, 600);
	IVideoDriver* driver = device->getVideoDriver();
	ISceneManager* smgr = device->createSceneManager();

	ITimer* timer = device->getTimer();
	timer->reset();

	// test
	XMFLOAT4 plane(0, 1.0f, 0, 0);
	XMFLOAT3 p(1.0f, 3.0f, -2.0f);
	XMFLOAT3 p2 = math::ComputeMirrorPointAboutPlane(plane, p);
	std::cout << p2.x << "," << p2.y << "," << p2.z << std::endl;

	const f32 color[] = { 0, 1.0f, 0, 1.0f };
	while (device->run()) {
		driver->beginScene(true, true, color);

		float dt = timer->tick();
		smgr->update(dt);
		smgr->drawAll();

		driver->endScene();
	}

	smgr->destroy();
	device->drop();
	return 0;
}
开发者ID:whztt07,项目名称:GameFinal,代码行数:30,代码来源:main.cpp

示例3: run

    //-------------------------------------------------------------------------
    //                                  r u n 
    //-------------------------------------------------------------------------
    void CApplication::run()
    {
        ITimer* timer = m_device->getTimer();
        u32 current, last = timer->getRealTime();
        u32 delta = 0;

        m_running = true;
        while(m_device->run() && m_running)
        {
            // calc seconds since last frame
            current = timer->getRealTime();
            delta = current-last;
            last = current;

            m_videoDriver->beginScene(true, true, SColor(255,100,101,140));
            preRender(delta);

            m_sceneManager->drawAll();
            m_gui->drawAll();

            postRender();
            m_videoDriver->endScene();

        }

        logMessage("Exiting Run Loop");
        stringc msg = "Frame Rate - Avg: ";
        msg += m_fpsAvg;
        msg += ", Min: ";
        msg += m_fpsMin;
        msg += ", Max: ";
        msg += m_fpsMax;
        logMessage(msg);
    }
开发者ID:bdbdonp,项目名称:tubras,代码行数:37,代码来源:CApplication.cpp

示例4: run

bool Application::run(){
    if(!device) return false;

    ITimer* irrTimer = device->getTimer();
    u32 TimeStamp = irrTimer->getTime(), DeltaTime = 0;

    while(device->run() && driver){
        DeltaTime = irrTimer->getTime() - TimeStamp;
        TimeStamp = irrTimer->getTime();
        
		this->updateTitle();

        if(device->isWindowActive()){
            driver->beginScene(true, true, video::SColor(255,100,100,100));
            smgr->drawAll();
			device->getGUIEnvironment()->drawAll();
            driver->endScene();
        }

		if(scene) scene->update(DeltaTime, state);
		if(state != oldState) loadLevel();
    }

    return true;
}
开发者ID:PuKoren,项目名称:exploot-client,代码行数:25,代码来源:Application.cpp

示例5: dbLoopGDK

///@brief
bool dbLoopGDK()
{
	dbPRINT("dbLoopGDK()\n");

	DarkGDK_SGlobalStruct& app = DarkGDK_SGlobalStruct::getInstance();

	IrrlichtDevice* device = app.Device;

	if (!device) return false;

	/// empty irrlicht message loop
	if (!device->run()) return false;

	ITimer* timer = device->getTimer();

	/// get current time
	app.Time_Now = timer->getTime();

	if (app.Time_Now >= app.Time_Last + 1000 )
	{
		app.FPS_Now = app.FPS_Count;
		app.FPS_Count = 0;
		if (app.FPS_Min > app.FPS_Now)
			app.FPS_Min = app.FPS_Now;
		if (app.FPS_Max < app.FPS_Now)
			app.FPS_Max = app.FPS_Now;
		app.Time_Last = timer->getTime();
	}

	video::IVideoDriver* driver = device->getVideoDriver();

	/// check resize-event
	if ( app.ScreenSize != driver->getScreenSize() )
	{
		app.ScreenSize = driver->getScreenSize();

		app.ScreenRect = core::recti( 0, 0, app.ScreenSize.Width-1, app.ScreenSize.Height-1);

		driver->OnResize( app.ScreenSize );

		/// resize aspect ratio of current active camera

		scene::ISceneManager* smgr = device->getSceneManager();
		scene::ICameraSceneNode*  camera = smgr->getActiveCamera();
		if ( camera )
		{
			app.CurrentCamera = camera;

			camera->setAspectRatio( (f32)app.ScreenSize.Width / (f32)app.ScreenSize.Width );

		}
	}

	return true;
}
开发者ID:benjaminhampe,项目名称:BenniSDK,代码行数:56,代码来源:libDarkGDK.cpp

示例6: main

int main()
{
	SDeviceContextSettings settings;
	settings.MultiSamplingCount = 4;
	settings.MultiSamplingQuality = 32;
	IApplication* device = createDevice(EDT_DIRECT3D11, 800, 600, EWS_NONE, true, settings);

	IVideoDriver* driver = device->getVideoDriver();
	ISceneManager* smgr = device->createSceneManager();
	IMeshManager* meshManager = driver->getMeshManager();

	IResourceGroupManager* resourceGroupManager = driver->getResourceGroupManager();
	resourceGroupManager->init("Resources.cfg");
	//resourceGroupManager->loadResourceGroup("General");

	XMFLOAT3 vertices[4];
	vertices[0] = XMFLOAT3(-10.0f, 0.0f, 10.0f);
	vertices[1] = XMFLOAT3(10.0f, 0.0f, 10.0f);
	vertices[2] = XMFLOAT3(-10.0f, 0.0f, -10.0f);
	vertices[3] = XMFLOAT3(10.0f, 0.0f, -10.0f);

	ISimpleMesh* mesh = meshManager->createSimpleMesh("pointlist", EVF_POSITION, 
		vertices, NULL, 4, sizeof(XMFLOAT3), 0, math::SAxisAlignedBox(), false);
	IMeshNode* meshNode = smgr->addMeshNode(mesh, nullptr, nullptr);
	meshNode->setMaterialName("test/ts_material");
	meshNode->setNeedCulling(false);

	ICameraNode* camera = smgr->addFpsCameraNode(1, nullptr, XMFLOAT3(0, 1.0f, -4.0f), XMFLOAT3(0, 1.0f, 0.0f));
	char caption[200];

	ITimer* timer = device->getTimer();
	timer->reset();

	while (device->run())
	{
		const float clearColor[] = { 0.0f, 0.0f, 0.0f, 1.0f };
		driver->beginScene(true, true, clearColor);

		float dt = timer->tick() * 0.001f;
		updateCamera(camera, dt);

		smgr->update(dt);
		smgr->drawAll();

		driver->endScene();

		sprintf(caption, "FPS:%f", getFps(dt));
		device->setWindowCaption(caption);
	}

	device->drop();

	return 0;
}
开发者ID:woyaofacai,项目名称:GameFinal,代码行数:54,代码来源:main.cpp

示例7: bench_mandelbrot_single_cpu_par

void bench_mandelbrot_single_cpu_par(
	ITimer& timer,
	Extent& ext,
	thrust::host_vector<int>& h,
	const int max_iter,
	Rectangle r
	)
{
	timer.start();
	mandelbrot_cpu_par(ext, thrust::raw_pointer_cast(&h[0]), max_iter, r);
	timer.stop();
	cout
		<< max_iter << ";"
		<< timer.delta()
		<< endl;
}
开发者ID:jdinkla,项目名称:parallel2014_gpucomputing,代码行数:16,代码来源:MandelbrotCPU.cpp

示例8: main

int main()
{
    IAscriber* ascriber = Ascriber::getInstance();

    ITimer* timer = new Timer(ascriber);

    new AnalogClock(timer, ascriber);
    new DigitalClock(timer, ascriber);

    while(1)
    {
        timer->tick();
        this_thread::sleep_for (chrono::seconds(1));
    }

    delete timer;

    return 0;
}
开发者ID:gabrielinuz,项目名称:observer-pattern-evolution,代码行数:19,代码来源:main.cpp

示例9: _tmain

int _tmain(int argc, _TCHAR* argv[])
{
    SDeviceContextSettings settings;
    settings.MultiSamplingCount = 1;
    settings.MultiSamplingQuality = 0;
    settings.WindowsProcedure = EditorWindow::WndProc;

    EditorWindow* window = new EditorWindow(SCREEN_WIDTH, SCREEN_HEIGHT);
    EditorWindow::_setInstance(window);

    IDevice* device = gf::createDevice(EDT_DIRECT3D11, SCREEN_WIDTH, SCREEN_HEIGHT, EWS_NONE, true, settings);
    IVideoDriver* driver = device->getVideoDriver();
    EditorScene* scene = new EditorScene(device);
    EditorScene::_setInstance(scene);


    scene->setupInitialScene();
    window->init();

    ITimer* timer = device->getTimer();
    timer->reset();
    char caption[200];
    while (device->run())
    {
        const float clearColor[] = { 1.0f, 0.0f, 0.0f, 1.0f };
        driver->beginScene(true, true, clearColor);

        f32 dt = timer->tick();
        scene->update(dt);
        scene->drawAll();

        driver->endScene();

        sprintf(caption, "FPS:%f", getFps(dt));
        device->setWindowCaption(caption);
    }

    delete scene;
    device->drop();

    return 0;
}
开发者ID:whztt07,项目名称:GameFinal,代码行数:42,代码来源:main.cpp

示例10: _tmain

int _tmain(int argc, _TCHAR* argv[])
{
	srand(time(0));
	SAppSettings settings;
	settings.Graphics.MultiSamplingCount = 8;
	settings.Graphics.MultiSamplingQuality = 32;
	settings.Window.Width = 400;
	settings.Window.Height = 300;

	//IApplication* device = gf::createDevice(EDT_DIRECT3D11, SCREEN_WIDTH, SCREEN_HEIGHT, EWS_NONE, true, settings);
	device = gf::createApp(settings);
	driver = device->getVideoDriver();

	math::SAxisAlignedBox aabb;
	aabb.Center = XMFLOAT3(0, 10.0f, 0);
	aabb.Extents = XMFLOAT3(500.0f, 500.0f, 500.0f);
	smgr = device->createSceneManager(aabb);
	IMeshManager* meshManager = driver->getMeshManager();
	IMaterialManager* materialManager = driver->getMaterialManager();
	ITextureManager* textureManager = driver->getTextureManager();
	IPipelineManager* pipelineManager = driver->getPipelineManager();
	IResourceGroupManager* resourceGroupManager = driver->getResourceGroupManager();
	resourceGroupManager->init("Resources.cfg");

	PhysicsEngine::getInstance();
	setupPhysics(smgr);
	// create ground
	
	ISimpleMesh* groundMesh = meshManager->createPlaneMesh("ground", groundSize, groundSize, 10, 10, 30.0f, 30.0f);
	IMeshNode* groundNode = smgr->addMeshNode(groundMesh, nullptr, nullptr, false);
	groundNode->setMaterialName("ground_material");

	createBoxes(smgr);

	// add directional light
	XMFLOAT3 light_dir(5.0f, -5.0f, -2.0f);
	f32 lightDistance = -20;
	ILightNode* light = smgr->addDirectionalLight(1, nullptr, light_dir);
	light->setSpecular(XMFLOAT4(1.0f, 1.0, 1.0f, 32.0f));
	light->setDiffuse(XMFLOAT4(0.8f, 0.8f, 0.8f, 1.0f));
	//light->setShadowCameraOrthographicSize(10.0f, 7.0f);

	XMFLOAT4 unit_dir = light->getDirection();
	light->setPosition(XMFLOAT3(unit_dir.x * lightDistance, unit_dir.y * lightDistance, unit_dir.z * lightDistance));
	light->setShadowMapSize(SCREEN_WIDTH, SCREEN_HEIGHT);
	light->setShadowCameraOrthographicSize(100.0f, 100.0f);
	light->enableShadow(true);
	camera = smgr->addFpsCameraNode(1, nullptr, XMFLOAT3(0, 1.0f, -4.0f), XMFLOAT3(0, 1.0f, 0.0f), XMFLOAT3(0, 1.0f, 0), true);
	camera->setPosition(XMFLOAT3(0, 20.0f, -40.0f));
	camera->lookAt(XMFLOAT3(0, 0, 0));
	camera->setNearZ(1.0f);
	camera->setFarZ(1000.0f);
	camera->setShadowRange(200.0f);
	smgr->setAmbient(XMFLOAT4(0.8f, 0.8f, 0.8f, 1.0f));

	updateLightDirection(10.0f, light);

	ITimer* timer = device->getTimer();
	timer->reset();

	const f32 color2[] = { 1.0f, 0.0f, 0.0f, 1.0f };

	device->setUpdateCallback(game_update);
	device->run();

	/*
	while (device->run())
	{
		const float clearColor[] = { 0.0f, 0.0f, 0.0f, 1.0f };
		driver->beginScene(true, true, clearColor);

		float dt = timer->tick();
		//float dt = ms * 0.001f;

		updatePhysics(dt);
		updateCamera(camera, dt);
		//updateLightDirection(dt, light);

		smgr->update(dt);

		smgr->drawAll();

		driver->endScene();

		sprintf_s(caption, "FPS:%f", getFps(dt));
		device->setWindowCaption(caption);

		//Sleep(10);
	}
	*/

	//sphereMaterial.drop();
	smgr->destroy();
	device->drop();

	delete g_ground;
	delete g_box;
	PhysicsEngine::deleteInstance();

	return 0;
//.........这里部分代码省略.........
开发者ID:woyaofacai,项目名称:GameFinal,代码行数:101,代码来源:main.cpp

示例11: fast_atof

//! Test both the accuracy and speed of Irrlicht's fast_atof() implementation.
bool fast_atof(void)
{
    bool accurate = true;

    accurate &= testCalculation("340282346638528859811704183484516925440.000000");
    accurate &= testCalculation("3.402823466e+38F");
    accurate &= testCalculation("3402823466e+29F");
    accurate &= testCalculation("-340282346638528859811704183484516925440.000000");
    accurate &= testCalculation("-3.402823466e+38F");
    accurate &= testCalculation("-3402823466e+29F");
    accurate &= testCalculation("34028234663852885981170418348451692544.000000");
    accurate &= testCalculation("3.402823466e+37F");
    accurate &= testCalculation("3402823466e+28F");
    accurate &= testCalculation("-34028234663852885981170418348451692544.000000");
    accurate &= testCalculation("-3.402823466e+37F");
    accurate &= testCalculation("-3402823466e+28F");
    accurate &= testCalculation(".00234567");
    accurate &= testCalculation("-.00234567");
    accurate &= testCalculation("0.00234567");
    accurate &= testCalculation("-0.00234567");
    accurate &= testCalculation("1.175494351e-38F");
    accurate &= testCalculation("1175494351e-47F");
    accurate &= testCalculation("1.175494351e-37F");
    accurate &= testCalculation("1.175494351e-36F");
    accurate &= testCalculation("-1.175494351e-36F");
    accurate &= testCalculation("123456.789");
    accurate &= testCalculation("-123456.789");
    accurate &= testCalculation("0000123456.789");
    accurate &= testCalculation("-0000123456.789");
    accurate &= testCalculation("-0.0690462109446526");

    if(!accurate)
    {
        logTestString("Calculation is not accurate, so the speed is irrelevant\n");
        return false;
    }

    IrrlichtDevice* device = createDevice(video::EDT_NULL);
    if (!device)
        return false;
    ITimer* timer = device->getTimer();

    enum { ITERATIONS = 100000 };
    int i;

    f32 value;
    u32 then = timer->getRealTime();
    for(i = 0; i < ITERATIONS; ++i)
        value = (f32)atof("-340282346638528859811704183484516925440.000000");

    const u32 atofTime = timer->getRealTime() - then;

    then += atofTime;
    for(i = 0; i < ITERATIONS; ++i)
        value = fast_atof("-340282346638528859811704183484516925440.000000");
    const u32 fastAtofTime = timer->getRealTime() - then;

    then += fastAtofTime;
    for(i = 0; i < ITERATIONS; ++i)
        value = old_fast_atof("-340282346638528859811704183484516925440.000000");
    const u32 oldFastAtofTime = timer->getRealTime() - then;

    logTestString("         atof time = %d\n    fast_atof Time = %d\nold fast_atof time = %d\n",
                  atofTime, fastAtofTime, oldFastAtofTime);

    device->drop();

    if(fastAtofTime > (1.2f*atofTime))
    {
        logTestString("The fast method is slower than atof()\n");
        return false;
    }

    return true;
}
开发者ID:jivibounty,项目名称:irrlicht,代码行数:76,代码来源:fast_atof.cpp

示例12: main


//.........这里部分代码省略.........
    m_helpPanel = m_gui->addStaticText(L"",rect<s32>(2,0,202,200));
    m_helpPanel->setBackgroundColor(SColor(128, 30, 30, 30));
    m_helpPanel->setDrawBorder(true);
    _addHelpText("F1 - Toggle Help");
    _addHelpText("F3 - Cycle Wire, Points, Solid");
    _addHelpText("F4 - Toggle Physics Debug");
    _addHelpText("F5 - Warp To Start Position");
    _addHelpText("F9 - Detach Camera");

    // turn hardware cursor off
    m_device->getCursorControl()->setVisible(false);

#if defined(USE_BULLET)
    m_device->setWindowCaption(L"irrb Collision/Physics example - Using Bullet");
#elif defined(USE_IRRPHYSX)
    m_device->setWindowCaption(L"irrb Collision/Physics example - Using IrrPhysx");
#else
    m_device->setWindowCaption(L"irrb Collision/Physics example - Using Irrlicht");
#endif
    m_camera = m_sceneManager->addCameraSceneNodeFPS(0, 100.0f, m_moveSpeed, -1, keyMap, 5, true, m_jumpSpeed);
    m_camera->setPosition(vector3df(0,10,0));
    m_camera->setFOV(core::PI / 2.5f);
    m_camera->setNearValue(.1f);
    m_camera->setFarValue(1000.f);

    // save off animator
    core::list<ISceneNodeAnimator*>::ConstIterator anims=m_camera->getAnimators().begin();
    while(anims != m_camera->getAnimators().end())
    {
        if ((*anims)->getType() == ESNAT_CAMERA_FPS)
        {
            m_fpsAnimator = (ISceneNodeAnimatorCameraFPS*)*anims;
            break;
        }
        ++anims;
    }

    // init physics library
    _initPhysicsLibrary();

    m_displayPhysicsDebug = true;
    _enablePhysicsDebug(true);
    m_debugNode->setVisible(true);

    // load scene
    sceneFileName = argv[1];   
    sceneDirectory = m_fileSystem->getFileDir(sceneFileName);

    saveDir = m_fileSystem->getWorkingDirectory();
    m_fileSystem->changeWorkingDirectoryTo(sceneDirectory);

    m_sceneManager->loadScene(sceneFileName.c_str(), &serializer);

    m_fileSystem->changeWorkingDirectoryTo(saveDir);

    // if the scene also contained a camera, set the active
    // camera to our fps camera and update the fps pos/rot.
    if(m_camera && (m_camera != m_sceneManager->getActiveCamera()))
    {
        ICameraSceneNode* anode = m_sceneManager->getActiveCamera();

        m_camera->setPosition(anode->getPosition());
        m_camera->setRotation(anode->getRotation());
        m_sceneManager->setActiveCamera(m_camera);
        m_startPos = m_camera->getPosition();
        _warp(m_startPos);
    }

    ITimer* timer = m_device->getTimer();
    u32 current, last = timer->getRealTime();
    u32 delta = 0;

    while(m_device->run() && m_running)
    {
        _clearDebugText();
        m_videoDriver->beginScene(true, true, SColor(255,100,101,140));

        // calc milliseconds since last frame
        current = timer->getRealTime();
        delta = current-last;
        last = current;

        // update collision/physics simulation
        _stepSimulation(delta);

        m_sceneManager->drawAll();

        static char buf[64];
        sprintf(buf, "FPS: %d", m_videoDriver->getFPS());  
        _updateDebugText(0, buf);
        m_gui->drawAll();

        m_videoDriver->endScene();
    }

    m_device->drop();
    delete m_eventReceiver;    

    return 0;
}
开发者ID:bdbdonp,项目名称:tubras,代码行数:101,代码来源:main.cpp

示例13: test_strtol

//! Test both the accuracy and speed of Irrlicht's strtol10() implementation.
bool test_strtol(void)
{
	bool accurate = true;

	accurate &= testCalculation_strtol("340282346638528859811704183484516925440");
	accurate &= testCalculation_strtol("3402823466");
	accurate &= testCalculation_strtol("3402823466e+29F");
	accurate &= testCalculation_strtol("-340282346638528859811704183484516925440");
	accurate &= testCalculation_strtol("-3402823466");
	accurate &= testCalculation_strtol("-3402823466e+29F");
	accurate &= testCalculation_strtol("402823466385288598117");
	accurate &= testCalculation_strtol("402823466");
	accurate &= testCalculation_strtol("402823466e+28F");
	accurate &= testCalculation_strtol("402823466385288598117");
	accurate &= testCalculation_strtol("-402823466");
	accurate &= testCalculation_strtol("-402823466e+28F");
	accurate &= testCalculation_strtol(".00234567");
	accurate &= testCalculation_strtol("-234567");
	accurate &= testCalculation_strtol("234567");
	accurate &= testCalculation_strtol("-234567");
	accurate &= testCalculation_strtol("1175494351");
	accurate &= testCalculation_strtol("11754943512");
	accurate &= testCalculation_strtol("11754943513");
	accurate &= testCalculation_strtol("11754943514");
	accurate &= testCalculation_strtol("-1175494351");
	accurate &= testCalculation_strtol("123456789");
	accurate &= testCalculation_strtol("-123456789");
	accurate &= testCalculation_strtol("123456.789");
	accurate &= testCalculation_strtol("-123456.789");
	accurate &= testCalculation_strtol("-109446526");

	if(!accurate)
	{
		logTestString("Calculation is not accurate, so the speed is irrelevant\n");
		return false;
	}

	IrrlichtDevice* device = createDevice(video::EDT_NULL);
	if (!device)
		return false;
	ITimer* timer = device->getTimer();

	const int ITERATIONS = 1000000;
	int i;

	s32 value;
	u32 then = timer->getRealTime();
	for(i = 0; i < ITERATIONS; ++i)
		value = strtol("-3402823466", 0, 10);

	const u32 strtolTime = timer->getRealTime() - then;

	then += strtolTime;
	for(i = 0; i < ITERATIONS; ++i)
		value = strtol10("-3402823466");
	const u32 strtol10Time = timer->getRealTime() - then;

	then += strtol10Time;
	for(i = 0; i < ITERATIONS; ++i)
		value = old_strtol10("-3402823466");
	const u32 oldstrtol10Time = timer->getRealTime() - then;

	logTestString("Speed test\n      strtol time = %d\n    strtol10 time = %d\nold strtol10 time = %d\n",
		strtolTime, strtol10Time, oldstrtol10Time);

	device->closeDevice();
	device->run();
	device->drop();

	if (strtol10Time > (1.2f*strtolTime))
	{
		logTestString("The fast method is slower than strtol()\n");
		return false;
	}

	return true;
}
开发者ID:Badcreature,项目名称:sagcg,代码行数:78,代码来源:fast_atof.cpp

示例14: main

s32 main( s32 argc, c8** argv)
{
	const c8* MY_TITLE = "CGUIPlot (c) 2013 by [email protected]";

	video::E_DRIVER_TYPE DriverType = video::EDT_OPENGL;

	// we like to have some choice
	//DriverType = driverChoiceConsole(true);

	/// create NullDevice
	SIrrlichtCreationParameters params;
	params.DriverType = video::EDT_NULL;
	params.LoggingLevel = ELL_NONE;
	params.Fullscreen = false;

	IrrlichtDevice* nulldev = createDeviceEx( params );
    if (nulldev)
    {
		video::IVideoModeList* videoModes = nulldev->getVideoModeList();
        //params.WindowSize = videoModes->getDesktopResolution();
        //params.WindowSize -= core::dimension2du(100,100);
        params.WindowSize = core::dimension2du(800,600);
        params.Bits = videoModes->getDesktopDepth();

		nulldev->drop();
    }
    else
	{
		printf("Could not create Null device\n");
		exit(-1);
	}

	/// create Device

	params.LoggingLevel = ELL_INFORMATION;
	params.DriverType = DriverType;
	params.AntiAlias = video::EAAM_QUALITY;
	params.EventReceiver = 0;
	params.HighPrecisionFPU = true;
	params.Doublebuffer = true;
	params.Vsync = false;
	params.Fullscreen = false;
	// params.ZBufferBits = 32;
	// params.Stencilbuffer = true;
	// params.WithAlphaChannel = false;

	IrrlichtDevice* device = createDeviceEx( params );
	if (!device)
	{
		printf("Could not create device\n");
		exit(-2);
	}

	MyEventReceiver receiver( device );

	gui::IGUIEnvironment* env = device->getGUIEnvironment();
	video::IVideoDriver* driver = device->getVideoDriver();
	core::dimension2du screen = driver->getScreenSize();
	scene::ISceneManager* smgr = device->getSceneManager();
	ITimer* timer = device->getTimer();

    device->setResizable( true );
	device->setWindowCaption( core::stringw( MY_TITLE ).c_str() );

	//gui::IGUIFont* font = env->getBuiltInFont();

	/// create some functions of time f(t)

	CSineOscillator<f32> vco_0(1, 0, 3);
	CSineOscillator<f32> vco_1(2, 0, 2);
	CSineOscillator<f32> vco_2(3, 0, 1);

	CRectangleOscillator<f32> vco_3(1, 0.1f, 0.4f, 2, -1);

	CSawOscillator<f32> vco_4(1, 0, 0.5f, -0.5f);
	CSawOscillator<f32> vco_5(3, 0.5f, 3, 0);

	CADSREnvelope<f32> adsr(1,3,0.7,2, CADSREnvelope<f32>::EMTT_LINEAR);

	/// create IGUIWindow as container for CGUIPlot

	gui::IGUIWindow* plotWindow = env->addWindow(
		core::recti( 100,100,screen.Width-100, screen.Height-100 ),
		false, L"CGUIPlot Window", env->getRootGUIElement(), -1);

	/// create CGUIPlot

	gui::CGUIPlotManager* plotMgr = new gui::CGUIPlotManager( env, plotWindow, -1, plotWindow->getClientRect());

	gui::CGUIPlot* plot = plotMgr->addPlot( new gui::CGUIPlot( smgr, env, plotMgr, -1, plotMgr->getClientRect() ) );

	// left, bottom, right, top
	plot->setZoomRect( core::rectf( -1,-3,10,3) );

	plot->setDrawBackground( true );

	plot->setBackgroundColor( video::SColor(128,255,255,255) );



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

示例15: Vector3

bool Application::run(){
    if(!device){
        return false;
    }

    Simulation sim;
    sim.Init();

    //std::vector<Boid*> boids;
	int nbLead = 3;
	int nbUnit = 20;
    this->CreateBoids(nbLead, nbUnit, 10, sim, NULL,0,0,0);

    //this->SetCameraTarget(boids[0]);
	/*this->CreateBoids(150, &boids, &sim, Vector3(0.f, 0.f, 0.f));	
	this->CreateBoids(50, &boids, &sim, Vector3(40.f, 0.f, 0.f));*/

    ITimer* irrTimer = device->getTimer();
    u32 TimeStamp = irrTimer->getTime();
	irr::u32 DeltaTime = 0;
    while(device->run()){
        DeltaTime = irrTimer->getTime() - TimeStamp;
        TimeStamp = irrTimer->getTime();

        sim.Update((float)DeltaTime);
        vector<Unit*> list = sim.GetAllUnits();
        for(unsigned int i = 0; i < list.size(); i++){
            Vector3 pos = list[i]->m_position;
            ((Boid*)list[i]->GetData())->setOrientation(core::vector3df(pos.X, pos.Y, pos.Z));
            ((Boid*)list[i]->GetData())->setPosition(core::vector3df(pos.X, pos.Y, pos.Z));            
        }

        driver->beginScene();
        smgr->drawAll();

		irr::video::SMaterial m;
        m.Lighting=false;
        driver->setMaterial(m);
        driver->setTransform(video::ETS_WORLD, core::matrix4());
		
		m_currentTime += DeltaTime;

		if(m_currentTime >= m_lastTime) {
			m_lastTime = TimeStamp + 10000 / (nbUnit * nbLead);
			if(list.size() > nbLead) {			
				int r = rand()%list.size();
				ps->setPosition(irr::core::vector3df(list[r]->m_position.X, list[r]->m_position.Y, list[r]->m_position.Z));
			} else {
				ps->setEmitter(0);
			}
		}

		for(unsigned int i = 0; i < list.size(); i++){
			if(list[i]->m_lead == NULL && list[i]->m_target != NULL) {
				Vector3 pos = list[i]->m_position;
				Vector3 posTarget = list[i]->m_target->m_position;				
				driver->draw3DLine(irr::core::vector3df(pos.X,pos.Y,pos.Z),irr::core::vector3df(posTarget.X,posTarget.Y,posTarget.Z), ((Boid*)list[i]->GetData())->getColor());
			}

            auto projectiles = list[i]->GetProjectileList();
            for(unsigned int j = 0; j < projectiles.size(); j++){
                Vector3 pos = projectiles[j].m_position;
                Vector3 posTarget = projectiles[j].m_position + (projectiles[j].m_velocity * projectiles[j].m_speed * 20.f);				
				driver->draw3DLine(irr::core::vector3df(pos.X,pos.Y,pos.Z),irr::core::vector3df(posTarget.X,posTarget.Y,posTarget.Z), ((Boid*)list[i]->GetData())->getColor());
            }
		}

		if(font) {
			std::vector<Unit*> rootUnits = sim.GetRootUnits();

			for(unsigned int i = 0; i < rootUnits.size(); i++) {
				wchar_t str[1000];
				swprintf(str,  L"LEADER %d", i + 1);
				video::SColor color = ((Boid*)rootUnits.at(i)->GetData())->getColor();

				font->draw(str,
						core::rect<s32>(20, (20 + 40)*i + 20,200,50),
						color);

				swprintf(str,  L"Units: %d", rootUnits.at(i)->m_units.size() + 1);
				font->draw(str,
						core::rect<s32>(45, (20 + 40)*i + 40,200,50),
						color);
			}
		}

        driver->endScene();
    }

    /*for(unsigned int i = 0; i < boids.size(); i++){
        delete boids[i];
    }*/
    sim.Clear();
    return true;
}
开发者ID:NHKChris,项目名称:hierarchical-fighting-boids,代码行数:95,代码来源:Application.cpp


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