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


C++ IVideoDriver::setViewPort方法代码示例

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


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

示例1: viewPortText

/** The result should be as follows: We have three times the same image, a billboard with a cube and the text in front.
They are replicated three times, one centered in the screen without viewport, one in the upper left (qurter screen) and
one on the right (half screen). The latter is stretched due to the changed aspect ratio.
The two viewport scenes get the texture drawn over the center as well, using draw2dimage. This should mark the proper
image position with the top left corner of the texture.
Finally, each scene has a checkbox drawn at the left side, vertically centered. This will show whether GUI elements adhere
to viewports as well. */
static bool viewPortText(E_DRIVER_TYPE driverType)
{
	IrrlichtDevice *device = createDevice( driverType, dimension2d<u32>(160, 120), 32);
	if (!device)
		return true; // Treat a failure to create a driver as benign; this saves a lot of #ifdefs

	IVideoDriver* driver = device->getVideoDriver();
	ISceneManager * smgr = device->getSceneManager();
	IGUIEnvironment* env = smgr->getGUIEnvironment();

	stabilizeScreenBackground(driver);

	env->addCheckBox(true, core::recti(10,60,28,82));

	logTestString("Testing driver %ls\n", driver->getName());

	IBillboardSceneNode * bnode = smgr->addBillboardSceneNode(0,dimension2d<f32>(32,32),core::vector3df(0,0,10));
	bnode->setMaterialFlag(video::EMF_LIGHTING, false);
	bnode->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR);
	bnode->setMaterialTexture(0, driver->getTexture("../media/fire.bmp"));

	smgr->addTextSceneNode(device->getGUIEnvironment()->getBuiltInFont(), L"TEST", video::SColor(255,255,255,255), 0);
	smgr->addCubeSceneNode();
	smgr->addCameraSceneNode(0, vector3df(0,30,-40), vector3df(0,5,0));

	driver->beginScene(video::ECBF_COLOR | video::ECBF_DEPTH, SColor(255,100,101,140));
	smgr->drawAll();
	env->drawAll();
	driver->setViewPort(rect<s32>(0,0,160/2,120/2));
	smgr->drawAll();
	env->drawAll();
	driver->draw2DImage(driver->getTexture("../media/fire.bmp"), core::vector2di(160/2,120/2));
	driver->setViewPort(rect<s32>(160/2,0,160,120));
	smgr->drawAll();
	env->drawAll();
	driver->draw2DImage(driver->getTexture("../media/fire.bmp"), core::vector2di(160/2,120/2));
	driver->endScene(); 

	bool result = takeScreenshotAndCompareAgainstReference(driver, "-viewPortText.png", 98.71f);

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

	return result;
}
开发者ID:Alberto-Izquierdo,项目名称:irrlicht,代码行数:53,代码来源:viewPort.cpp

示例2: main


//.........这里部分代码省略.........
		camera[3]->setPosition(core::vector3df(-50,0,-50));

/*
Create a variable for counting the fps and hide the mouse:
*/
	//Hide mouse
	device->getCursorControl()->setVisible(false);
	//We want to count the fps
	int lastFPS = -1;

/*
There wasn't much new stuff - till now!
Only by defining four cameras, the game won't be splitscreen.
To do this you need several steps:
  - Set the viewport to the whole screen
  - Begin a new scene (Clear screen)

  - The following 3 steps are repeated for every viewport in the splitscreen
    - Set the viewport to the area you wish
    - Activate the camera which should be "linked" with the viewport
    - Render all objects

  - If you have a GUI:
    - Set the viewport the whole screen
    - Display the GUI
  - End scene

Sounds a little complicated, but you'll see it isn't:
*/

	while(device->run())
	{
		//Set the viewpoint to the whole screen and begin scene
		driver->setViewPort(rect<s32>(0,0,ResX,ResY));
		driver->beginScene(true,true,SColor(255,100,100,100));
		//If SplitScreen is used
		if (SplitScreen)
		{
			//Activate camera1
			smgr->setActiveCamera(camera[0]);
			//Set viewpoint to the first quarter (left top)
			driver->setViewPort(rect<s32>(0,0,ResX/2,ResY/2));
			//Draw scene
			smgr->drawAll();
			//Activate camera2
			smgr->setActiveCamera(camera[1]);
			//Set viewpoint to the second quarter (right top)
			driver->setViewPort(rect<s32>(ResX/2,0,ResX,ResY/2));
			//Draw scene
			smgr->drawAll();
			//Activate camera3
			smgr->setActiveCamera(camera[2]);
			//Set viewpoint to the third quarter (left bottom)
			driver->setViewPort(rect<s32>(0,ResY/2,ResX/2,ResY));
			//Draw scene
			smgr->drawAll();
			//Set viewport the last quarter (right bottom)
			driver->setViewPort(rect<s32>(ResX/2,ResY/2,ResX,ResY));
		}
		//Activate camera4
		smgr->setActiveCamera(camera[3]);
		//Draw scene
		smgr->drawAll();
		driver->endScene();

		/*
开发者ID:gametechnology,项目名称:psi-old,代码行数:67,代码来源:main.cpp

示例3: main


//.........这里部分代码省略.........

//-- robots ------------------------------------------------------------//

    //create robots
    Fly2D::Brain* brains[nRobots];


    //all to a default type
    //for ( int i=0; i<nRobots; i++ )
    //{
        //brains[i] = new Fly2D::BrainForward;
        ////brains[i] = new Fly2D::BrainCircle();
    //}

    brains[0] = new Fly2D::BrainForward;
    brains[1] = new Fly2D::BrainForward;

    //decide human control
        vector<Fly2D::BrainHuman*> hBrains;
        for (
            vector<int>::iterator i = humanBrainIds.begin();
            i != humanBrainIds.end();
            ++i
        )
        {
            if ( *i > nRobots )
            {
                cerr << "no such robot: " << *i << endl;
                exit(EXIT_FAILURE);
            }
            delete brains[*i];
            Fly2D::BrainHuman* hBrain = new Fly2D::BrainHuman;
            brains[*i] = hBrain;
            hBrains.push_back(hBrain);
        }
        Fly2D::ReceiverHuman hReceiver = Fly2D::ReceiverHuman( hBrains );
        device->setEventReceiver( &hReceiver );

    Robot* robots[nRobots];
    robots[0] = new Fly2D::Robot( *device, *meta, *brains[0], vector3df(0,0,-0.5f), vector3df(0,0, 0.5f),  0.01 );
    robots[1] = new Fly2D::Robot( *device, *meta, *brains[1], vector3df(0,0,0.5f),  vector3df(0,0, -0.5f), 0.01 );

    meta->drop(); // As soon as we're done with the selector, drop it.

//-- run ------------------------------------------------------------//
    //TEST
    vector3df oldpos, oldtarget;
    //END TEST
    
    int nFrames = 0;
    ITimer* timer = device->getTimer();
    int t0 = timer->getTime();
    int w = driver->getScreenSize().Width;
    int h = driver->getScreenSize().Height;
    int dh = h/nRobots;
    int observeRobot = 0;

	while(device->run())
	{
        //if (device->isWindowActive()) //only work if window has focus.

        //draw

        driver->setViewPort(rect<s32>(0,0,w,h));
        driver->beginScene(true,true,0);
        for(int i=0; i<nRobots; i++)
        {
            driver->setViewPort(rect<s32>(0,dh*i,w,dh*(i+1)));
            //only part of window gets drawn into

            smgr->setActiveCamera(robots[i]->camera);

            smgr->drawAll(); 
            //draws on window scene of active camera
 
            robots[i]->update();
        }
        driver->endScene();

        //TEST
        //if
        //(
            //robots[observeRobot].getPosition() != oldpos
            //|| robots[observeRobot].getTarget() != oldtarget
        //)
        //oldpos = robots[observeRobot].getPosition();
        //oldtarget = robots[observeRobot].getTarget();

        cout << robots[observeRobot]->str();

        //FPS info
            //cout << "frame no:" << endl << nFrames << endl;;
            //cout << "average fps:" << endl << 1000*nFrames/(float)(timer->getTime()-t0) << endl;
            //nFrames++;
            cout << "fps:" << endl << driver->getFPS() << endl;
        //END TEST
	}
	device->drop();
	return 0;
}
开发者ID:cirosantilli,项目名称:computer_vision2d,代码行数:101,代码来源:main.cpp

示例4: run

bool Editor::run(IrrlichtDevice* irr_device,Configuration* conf){
	// Do Irrlicht Stuff
	_device = irr_device;
	IVideoDriver* driver = GetDevice()->getVideoDriver();
	ISceneManager* smgr = GetDevice()->getSceneManager();
	IGUIEnvironment* guienv = GetDevice()->getGUIEnvironment();	
	GetDevice()->setEventReceiver(this);

	if (!conf->getSettingAsBool("fullscreen"))
		GetDevice()->setResizable(true);

	// Project and state
	Project* proj = new Project();
	_state = new EditorState(GetDevice(),proj,conf);

	// Menu State
	MenuState* ms = new MenuState(GetState());
	GetState()->SetMenu(ms);

	// Add editor modes
	GetState()->AddMode(new NBEditor(GetState()));

	// Set up project
	proj->AddNode(new Node(GetDevice(),GetState()));
	proj->SelectNode(0);

	// Load user interface
	LoadScene();	
	GetState()->Menu()->init();
	GetState()->Mode()->load();
	printf("Complete!\n");

	int LastX = driver->getScreenSize().Width;
	if (!GetState()->Settings()->getSettingAsBool("hide_sidebar"))
			LastX -= 256;
	int LastY = driver->getScreenSize().Height;
	int lastFPS = -1;
	while (GetDevice()->run()){
		if (GetState()->NeedsClose()){
			GetDevice()->closeDevice();
			return true;
		}

		driver->beginScene(true, true, irr::video::SColor(255,150,150,150));

		int ResX = driver->getScreenSize().Width;
		if (!GetState()->Settings()->getSettingAsBool("hide_sidebar"))
			ResX -= 256;
		
		int ResY = driver->getScreenSize().Height;

		if (currentWindow == -1)
		{
			// Draw Camera 0
			if (camera[0]){
				smgr->setActiveCamera(camera[0]);
				rect<s32> offset = rect<s32>(0,0,ResX/2,ResY/2);
				driver->setViewPort(offset);
				smgr->drawAll();

				if (GetState()->Mode())
					GetState()->Mode()->viewportTick(EVIEW_PERS, driver, offset);
			}

			// Draw Camera 1
			if (camera[1]){
				smgr->setActiveCamera(camera[1]);
				rect<s32> offset = rect<s32>(ResX/2,0,ResX,ResY/2);
				driver->setViewPort(offset);
				smgr->drawAll();

				if (GetState()->Mode())
					GetState()->Mode()->viewportTick(EVIEW_XZ, driver, offset);
			}

			// Draw Camera 2
			if (camera[2]){
				smgr->setActiveCamera(camera[2]);
				rect<s32> offset = rect<s32>(0,ResY/2,ResX/2,ResY);
				driver->setViewPort(offset);
				smgr->drawAll();

				if (GetState()->Mode())
					GetState()->Mode()->viewportTick(EVIEW_XY, driver, offset);

			}

			// Draw Camera 3
			if (camera[3]){
				smgr->setActiveCamera(camera[3]);
				rect<s32> offset = rect<s32>(ResX/2,ResY/2,ResX,ResY);
				driver->setViewPort(offset);
				smgr->drawAll();

				if (GetState()->Mode())
					GetState()->Mode()->viewportTick(EVIEW_ZY, driver, offset);
			}

			// Draw GUI
			driver->setViewPort(rect<s32>(0,0,driver->getScreenSize().Width,driver->getScreenSize().Height));
//.........这里部分代码省略.........
开发者ID:jmf,项目名称:The-NodeBox-Generator,代码行数:101,代码来源:Editor.cpp

示例5: draw

	//! draws the element and its children
	void CGUIMeshViewer::draw()
	{
		if (!IsVisible)
			return;

		IGUISkin* skin = Environment->getSkin();
		IVideoDriver* driver = Environment->getVideoDriver();
		rect<SINT32> viewPort = AbsoluteRect;
		viewPort.LowerRightCorner.x -= 1;
		viewPort.LowerRightCorner.y -= 1;
		viewPort.UpperLeftCorner.x += 1;
		viewPort.UpperLeftCorner.y += 1;

		viewPort.clipAgainst(AbsoluteClippingRect);

		// draw the frame

		rect<SINT32> frameRect(AbsoluteRect);
		frameRect.LowerRightCorner.y = frameRect.UpperLeftCorner.y + 1;
		skin->draw2DRectangle(this, skin->getColor(EGDC_3D_SHADOW), frameRect, &AbsoluteClippingRect);

		frameRect.LowerRightCorner.y = AbsoluteRect.LowerRightCorner.y;
		frameRect.LowerRightCorner.x = frameRect.UpperLeftCorner.x + 1;
		skin->draw2DRectangle(this, skin->getColor(EGDC_3D_SHADOW), frameRect, &AbsoluteClippingRect);

		frameRect = AbsoluteRect;
		frameRect.UpperLeftCorner.x = frameRect.LowerRightCorner.x - 1;
		skin->draw2DRectangle(this, skin->getColor(EGDC_3D_HIGH_LIGHT), frameRect, &AbsoluteClippingRect);

		frameRect = AbsoluteRect;
		frameRect.UpperLeftCorner.y = AbsoluteRect.LowerRightCorner.y - 1;
		skin->draw2DRectangle(this, skin->getColor(EGDC_3D_HIGH_LIGHT), frameRect, &AbsoluteClippingRect);

		// draw the mesh

		if (Mesh)
		{
			//TODO: if outside of screen, dont draw.
			// - why is the absolute clipping rect not already the screen?

			rect<SINT32> oldViewPort = driver->getViewPort();

			driver->setViewPort(viewPort);

			Matrix4 mat;

			//CameraControl->calculateProjectionMatrix(mat);
			//driver->setTransform(TS_PROJECTION, mat);

			mat = Matrix4::IDENTITY;
			mat.setTrans(Vector3(0, 0, 0));
			//mat.setTranslation(Vector3(0, 0, 0));
			driver->setTransform(ETS_WORLD, mat);

			//CameraControl->calculateViewMatrix(mat);
			//driver->setTransform(TS_VIEW, mat);

			driver->setMaterial(Material);

			UINT32 frame = 0;
			if (Mesh->getFrameCount())
				frame = (Timer::getTime() / 20) % Mesh->getFrameCount();
			const IMesh* const m = Mesh->getMesh(frame);
			for (UINT32 i = 0; i<m->getMeshBufferCount(); ++i)
			{
				IMeshBuffer* mb = m->getMeshBuffer(i);
				driver->drawVertexPrimitiveList(mb->getVertices(),
					mb->getVertexCount(), mb->getIndices(),
					mb->getIndexCount() / 3, mb->getVertexType(),
					EPT_TRIANGLES, mb->getIndexType());
			}

			driver->setViewPort(oldViewPort);
		}

		IGUIElement::draw();
	}
开发者ID:zxycode007,项目名称:Sapphire,代码行数:78,代码来源:SapphireCGUIMeshViewer.cpp

示例6: viewportTick

void Editor::viewportTick(Viewport viewport, rect<s32> rect,
		bool mousehit, bool middlehit)
{
	// Init
	IVideoDriver *driver = device->getVideoDriver();
	ISceneManager *smgr = device->getSceneManager();
	IGUIEnvironment *guienv = device->getGUIEnvironment();
	ViewportType type = state->getViewportType(viewport);

	// Draw camera
	smgr->setActiveCamera(camera[(int)viewport]);
	driver->setViewPort(rect);
	if (type == VIEWT_BOTTOM)
		plane->setVisible(false);
	smgr->drawAll();
	if (type == VIEWT_BOTTOM)
		plane->setVisible(true);

	// Callbacks
	if (state->Mode())
		state->Mode()->viewportTick(viewport, driver, rect);

	if (viewport_drag == viewport) {
		vector2di delta = state->mouse_position;
		delta -= viewport_drag_last;
		viewport_drag_last = state->mouse_position;
		viewport_offset[(int)viewport].X -= (f32)delta.X * 0.01f;
		viewport_offset[(int)viewport].Y += (f32)delta.Y * 0.01f;
		if (viewport_offset[(int)viewport].X > 0.5)
			viewport_offset[(int)viewport].X = 0.5;
		if (viewport_offset[(int)viewport].X < -0.5)
			viewport_offset[(int)viewport].X = -0.5;
		if (viewport_offset[(int)viewport].Y > 0.5)
			viewport_offset[(int)viewport].Y = 0.5;
		if (viewport_offset[(int)viewport].Y < -0.5)
			viewport_offset[(int)viewport].Y = -0.5;
		applyCameraOffsets(viewport);
	}

	if (middlehit && rect.isPointInside(state->mouse_position)
			&& type != VIEWT_PERS) {
		viewport_drag = viewport;
		viewport_drag_last = state->mouse_position;
	}

	// Draw text
	driver->setViewPort(rects32(0, 0, driver->getScreenSize().Width,
			driver->getScreenSize().Height));
	{
		static const wchar_t* labels[7] = {L"Perspective", L"Front", L"Left",
				L"Top", L"Back", L"Right", L"Bottom"};

		// Handle clicking
		position2d<s32> labelpos(rect.LowerRightCorner.X - 86,
				rect.UpperLeftCorner.Y + ((rect.UpperLeftCorner.Y < 50)?30:10));
		rects32 backgroundrect(rect.LowerRightCorner.X - 96,
					rect.UpperLeftCorner.Y + ((rect.UpperLeftCorner.Y < 50)?25:5),
					rect.LowerRightCorner.X - 5,
					rect.UpperLeftCorner.Y + ((rect.UpperLeftCorner.Y < 50)?185:165));
		bool context_is_open = (viewport_contextmenu == viewport);
		if (mousehit && !state->menu->dialog) {
			if ((rects32(labelpos.X, labelpos.Y, labelpos.X + 90,
					labelpos.Y + 25)).isPointInside(state->mouse_position)) {
				viewport_contextmenu = viewport;
			} else if (context_is_open) {
				context_is_open = false;
				viewport_contextmenu = VIEW_NONE;
				if (backgroundrect.isPointInside(state->mouse_position)) {
					int y = 0;
					for (int i = 0; i < 7; i++) {
						if (i != (int)type) {
							int ty = rect.UpperLeftCorner.Y +
									((rect.UpperLeftCorner.Y < 50)?56:36)
									+ y * 20;
							rects32 trect(rect.LowerRightCorner.X - 96,
									ty,
									rect.LowerRightCorner.X - 5, ty + 20);
							y++;
							if (trect.isPointInside(state->mouse_position)) {
								viewport_offset[(int)viewport] = vector3df(0, 0, 0);
								state->settings->set(viewportToSetting(viewport),
									viewportTypeToSetting((ViewportType)i));
								recreateCameras();
								break;
							}
						}
					}
				}
			}
		}

		// Context menu
		if (context_is_open) {
			// Context menu background
			driver->draw2DRectangle(SColor(100, 32, 32, 32), backgroundrect);
			s32 y2 = rect.UpperLeftCorner.Y + ((rect.UpperLeftCorner.Y < 50)?52:32);
			driver->draw2DLine(position2d<s32>(rect.LowerRightCorner.X - 96, y2),
					position2d<s32>(rect.LowerRightCorner.X - 5, y2),
					SColor(100, 255, 255, 255));
			// Draw options
//.........这里部分代码省略.........
开发者ID:asl97,项目名称:NodeBoxEditor,代码行数:101,代码来源:Editor.cpp

示例7: run

bool Editor::run(IrrlichtDevice* irr_device, Configuration* conf,
		bool editor_is_installed)
{
	// Do Irrlicht Stuff
	device = irr_device;
	IVideoDriver *driver = device->getVideoDriver();
	ISceneManager *smgr = device->getSceneManager();
	IGUIEnvironment *guienv = device->getGUIEnvironment();
	device->setEventReceiver(this);
	device->setWindowCaption(L"Node Box Editor");

	if (!conf->getBool("fullscreen")) {
		device->setResizable(true);
	}

	// Project and state
	Project *proj = new Project();
	state = new EditorState(device, proj, conf);
	state->isInstalled = editor_is_installed;

	// Menu State
	state->menu = new MenuState(state);

	// Add editor modes
	state->AddMode(new NBEditor(state));
	state->AddMode(new NodeEditor(state));
	state->AddMode(new TextureEditor(state));

	// Set up project
	proj->AddNode(state, true, false);

	proj->media.debug();

	// Load user interface
	LoadScene();
	state->SelectMode(0);

	int LastX = driver->getScreenSize().Width;
	if (!state->settings->getBool("hide_sidebar")) {
			LastX -= 256;
	}
	int LastY = driver->getScreenSize().Height;
#ifdef _DEBUG
	int lastFPS = -1;
#endif

	bool dosleep = state->settings->getBool("use_sleep");
	u32 last = std::clock();
	double dtime = 0;
	while (device->run()) {
		if (state->NeedsClose()) {
			device->closeDevice();
			return true;
		}

		driver->beginScene(true, true, irr::video::SColor(255, 150, 150, 150));

		int ResX = driver->getScreenSize().Width;
		if (!state->settings->getBool("hide_sidebar"))
			ResX -= 256;

		int ResY = driver->getScreenSize().Height;

		if (currentWindow == -1) {
			bool newmoused = (state->mousedown && !click_handled);
			viewportTick(VIEW_TL, rect<s32>(0,      0,      ResX/2, ResY/2),
					newmoused, !middle_click_handled);
			viewportTick(VIEW_TR, rect<s32>(ResX/2, 0,      ResX,   ResY/2),
					newmoused, !middle_click_handled);
			viewportTick(VIEW_BL, rect<s32>(0,      ResY/2, ResX/2, ResY  ),
					newmoused, !middle_click_handled);
			viewportTick(VIEW_BR, rect<s32>(ResX/2, ResY/2, ResX,   ResY  ),
					newmoused, !middle_click_handled);

			// Draw separating lines
			driver->setViewPort(rect<s32>(0, 0, driver->getScreenSize().Width,
					driver->getScreenSize().Height));
			driver->draw2DLine(vector2d<irr::s32>(0, ResY/2),
					vector2d<irr::s32>(ResX, ResY/2), SColor(175,255,255,255));
			driver->draw2DLine(vector2d<irr::s32>(0, ResY/2-1),
					vector2d<irr::s32>(ResX, ResY/2-1), SColor(175,255,255,255));
			driver->draw2DLine(vector2d<irr::s32>(ResX/2, 0),
					vector2d<irr::s32>(ResX/2, ResY), SColor(175,255,255,255));
			driver->draw2DLine(vector2d<irr::s32>(ResX/2+1, 0),
					vector2d<irr::s32>(ResX/2+1, ResY), SColor(175,255,255,255));
		} else if (camera[currentWindow]) {
			viewportTick((Viewport)currentWindow, rect<s32>(0, 0, ResX, ResY),
					(state->mousedown && !click_handled), !middle_click_handled);
		}

		if (state->menu) {
			state->menu->draw(driver);
		}
		if (state->Mode()) {
			state->Mode()->draw(driver);
		}

		if (state->project && state->project->GetCurrentNode()) {
			vector3df pos = vector3df(
				(f32)state->project->GetCurrentNode()->position.X,
//.........这里部分代码省略.........
开发者ID:asl97,项目名称:NodeBoxEditor,代码行数:101,代码来源:Editor.cpp

示例8: main

int main(int argc, char** argv) {
	CustomEventReceiver receiver;
	IrrlichtDevice *device = createDevice( video::EDT_OPENGL, dimension2d<u32>(800, 600), 16, false, false, false, &receiver);
	if (!device) {
		return EXIT_FAILURE;
    }
	device->setWindowCaption(L"Solar System Simulator");
	IVideoDriver* driver = device->getVideoDriver();
	ISceneManager* sceneManager = device->getSceneManager();
	scene::ISceneCollisionManager* collisionManager= sceneManager->getSceneCollisionManager();
	IGUIEnvironment* guiEnv = device->getGUIEnvironment();
	guiEnv->addStaticText(L"Click on a planet to attach the camera to it", rect<s32>(10,10,260,22), false);

	sf::SoundBuffer buffer;
	if (buffer.loadFromFile(currentPath() + "/sounds/burning.aif")) {
		sf::Listener::setPosition(0, 0,0);

		sf::Sound sound;
		sound.setBuffer(buffer);
		sound.setPosition(0, 0, 0);
		sound.setLoop(true);
		sound.play();
	}

	const char* spaceTexturePath = ( currentPath() + "/textures/space.jpg" ).c_str();
	video::ITexture* space = driver->getTexture(spaceTexturePath);
	scene::ISceneNode* skybox = sceneManager->addSkyBoxSceneNode(space, space, space, space, space, space);

	sceneManager->addLightSceneNode(0, vector3df(0, 0, -50),  video::SColorf(1.0f, 1.0f, 1.0f), 50.0f, 1001);

	PlanetFactory planetFactory(sceneManager, driver);
	Planet sun = planetFactory.create(PlanetId::Sun);
	Planet earth = planetFactory.create(PlanetId::Earth);
	Planet pluto = planetFactory.create(PlanetId::Pluto);
	Planet jupiter = planetFactory.create(PlanetId::Jupiter);
	Planet uranus = planetFactory.create(PlanetId::Uranus);
	Planet neptune = planetFactory.create(PlanetId::Neptune);

	vector<Planet> planets = { sun, planetFactory.create(PlanetId::Mercury) };
	planets.push_back(planetFactory.create(PlanetId::Venus));
	planets.push_back(earth);
	planets.push_back(planetFactory.create(PlanetId::Mars));
	planets.push_back(jupiter);
	planets.push_back(planetFactory.create(PlanetId::Saturn));
	planets.push_back(uranus);
	planets.push_back(neptune);
	planets.push_back(pluto);

	ICameraSceneNode* camera = sceneManager->addCameraSceneNode(0, vector3df(0,0,40), vector3df(0,0,0));
	rect<s32> mainCameraViewPortRect(0, 0, 800, 600);

	ICameraSceneNode* topViewCamera = sceneManager->addCameraSceneNode(0, vector3df(0,50,0), vector3df(0,0,0));
	
	sceneManager->setAmbientLight(video::SColorf(255.0,255.0,255.0));

	ISceneNode* selectedNode = sun.node;
	while(device->run()) {

		if(receiver.GetMouseState().LeftButtonDown) {
			position2di mousepos = receiver.GetMouseState().Position;
			line3df ray = sceneManager->getSceneCollisionManager()->getRayFromScreenCoordinates( mousepos, camera);

			vector3df intersection;
			triangle3df tri;

            for(Planet& planet : planets) {
				ITriangleSelector* wselector = sceneManager->createTriangleSelectorFromBoundingBox(planet.node);
				if (collisionManager->getCollisionPoint(ray, wselector, intersection, tri, planet.node)) {
					selectedNode = planet.node;
				}
				wselector->drop();
			}
		}

		camera->setTarget(selectedNode->getAbsolutePosition());

		skybox->setVisible(true);		
        
		driver->setViewPort(mainCameraViewPortRect);
		driver->beginScene(true, true, SColor(255,100,101,140));
		sceneManager->setActiveCamera(camera);
		sceneManager->drawAll();
		guiEnv->drawAll();

		driver->setViewPort(rect<s32>(0, 380, 200, 600));
		driver->draw2DRectangle(SColor(100,0,0,190), mainCameraViewPortRect);
		skybox->setVisible(false);		
		sceneManager->setActiveCamera(topViewCamera);
		sceneManager->drawAll();
		
		driver->endScene();
	}
	device->drop();

	return EXIT_SUCCESS;
}
开发者ID:Ponup,项目名称:solar-system-simulator,代码行数:96,代码来源:Main.cpp

示例9: run

bool Editor::run(IrrlichtDevice* irr_device,Configuration* conf)
{
	// Do Irrlicht Stuff
	device = irr_device;
	IVideoDriver *driver = device->getVideoDriver();
	ISceneManager *smgr = device->getSceneManager();
	IGUIEnvironment *guienv = device->getGUIEnvironment();	
	device->setEventReceiver(this);
	device->setWindowCaption(L"Node Box Editor");

	if (!conf->getBool("fullscreen")) {
		device->setResizable(true);
	}

	// Project and state
	Project *proj = new Project();
	state = new EditorState(device, proj, conf);

	// Menu State
	state->menu = new MenuState(state);

	// Add editor modes
	state->AddMode(new NBEditor(state));
	state->AddMode(new NodeEditor(state));

	// Set up project
	proj->AddNode(state, true, false);

	// Load user interface
	LoadScene();	
	state->SelectMode(0);

	int LastX = driver->getScreenSize().Width;
	if (!state->settings->getBool("hide_sidebar")) {
			LastX -= 256;
	}
	int LastY = driver->getScreenSize().Height;
#ifdef _DEBUG
	int lastFPS = -1;
#endif

	bool dosleep = state->settings->getBool("use_sleep");
	u32 last = std::clock();
	double dtime = 0;
	while (device->run()) {
		if (state->NeedsClose()) {
			device->closeDevice();
			return true;
		}

		driver->beginScene(true, true, irr::video::SColor(255, 150, 150, 150));

		int ResX = driver->getScreenSize().Width;
		if (!state->settings->getBool("hide_sidebar"))
			ResX -= 256;
		
		int ResY = driver->getScreenSize().Height;

		if (currentWindow == -1) {
			// Draw Camera 0
			if (camera[0]) {
				smgr->setActiveCamera(camera[0]);
				rect<s32> offset = rect<s32>(0, 0, ResX/2, ResY/2);
				driver->setViewPort(offset);
				smgr->drawAll();

				if (state->Mode())
					state->Mode()->viewportTick(VIEW_PERS, driver, offset);
			}

			// Draw Camera 1
			if (camera[1]) {
				smgr->setActiveCamera(camera[1]);
				rect<s32> offset = rect<s32>(ResX/2, 0, ResX, ResY/2);
				driver->setViewPort(offset);
				smgr->drawAll();

				if (state->Mode())
					state->Mode()->viewportTick(VIEW_XZ, driver, offset);
			}

			// Draw Camera 2
			if (camera[2]) {
				smgr->setActiveCamera(camera[2]);
				rect<s32> offset = rect<s32>(0, ResY/2, ResX/2, ResY);
				driver->setViewPort(offset);
				smgr->drawAll();

				if (state->Mode())
					state->Mode()->viewportTick(VIEW_XY, driver, offset);

			}

			// Draw Camera 3
			if (camera[3]) {
				smgr->setActiveCamera(camera[3]);
				rect<s32> offset = rect<s32>(ResX/2, ResY/2, ResX, ResY);
				driver->setViewPort(offset);
				smgr->drawAll();

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


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