Esempio n. 1
0
/*
Finally, the third function creates a toolbox window. In this simple mesh
viewer, this toolbox only contains a tab control with three edit boxes for
changing the scale of the displayed model.
*/
void createToolBox()
{
	// remove tool box if already there
	IGUIEnvironment* env = Device->getGUIEnvironment();
	IGUIElement* root = env->getRootGUIElement();
	IGUIElement* e = root->getElementFromId(GUI_ID_DIALOG_ROOT_WINDOW, true);
	if (e)
		e->remove();

	// create the toolbox window
	IGUIWindow* wnd = env->addWindow(core::rect<s32>(600,45,800,480),
		false, L"Toolset", 0, GUI_ID_DIALOG_ROOT_WINDOW);

	// create tab control and tabs
	IGUITabControl* tab = env->addTabControl(
		core::rect<s32>(2,20,800-602,480-7), wnd, true, true);

	IGUITab* t1 = tab->addTab(L"Config");

	// add some edit boxes and a button to tab one
	env->addStaticText(L"Scale:",
			core::rect<s32>(10,20,60,45), false, false, t1);
	env->addStaticText(L"X:", core::rect<s32>(22,48,40,66), false, false, t1);
	env->addEditBox(L"1.0", core::rect<s32>(40,46,130,66), true, t1, GUI_ID_X_SCALE);
	env->addStaticText(L"Y:", core::rect<s32>(22,82,40,96), false, false, t1);
	env->addEditBox(L"1.0", core::rect<s32>(40,76,130,96), true, t1, GUI_ID_Y_SCALE);
	env->addStaticText(L"Z:", core::rect<s32>(22,108,40,126), false, false, t1);
	env->addEditBox(L"1.0", core::rect<s32>(40,106,130,126), true, t1, GUI_ID_Z_SCALE);

	env->addButton(core::rect<s32>(10,134,85,165), t1, GUI_ID_BUTTON_SET_SCALE, L"Set");

	// quick scale buttons
	env->addButton(core::rect<s32>(65,20,95,40), t1, GUI_ID_BUTTON_SCALE_MUL10, L"* 10");
	env->addButton(core::rect<s32>(100,20,130,40), t1, GUI_ID_BUTTON_SCALE_DIV10, L"* 0.1");

	updateScaleInfo(Model);

	// add transparency control
	env->addStaticText(L"GUI Transparency Control:",
			core::rect<s32>(10,200,150,225), true, false, t1);
	IGUIScrollBar* scrollbar = env->addScrollBar(true,
			core::rect<s32>(10,225,150,240), t1, GUI_ID_SKIN_TRANSPARENCY);
	scrollbar->setMax(255);
	scrollbar->setPos(255);

	// add framerate control
	env->addStaticText(L":", core::rect<s32>(10,240,150,265), true, false, t1);
	env->addStaticText(L"Framerate:",
			core::rect<s32>(12,240,75,265), false, false, t1);
	// current frame info
	env->addStaticText(L"", core::rect<s32>(75,240,200,265), false, false, t1,
			GUI_ID_ANIMATION_INFO);
	scrollbar = env->addScrollBar(true,
			core::rect<s32>(10,265,150,280), t1, GUI_ID_SKIN_ANIMATION_FPS);
	scrollbar->setMax(MAX_FRAMERATE);
	scrollbar->setMin(-MAX_FRAMERATE);
	scrollbar->setPos(DEFAULT_FRAMERATE);
	scrollbar->setSmallStep(1);
}
Esempio n. 2
0
/*
 That's it. The Scene node is done. Now we simply have to start
 the engine, create the scene node and a camera, and look at the result.
 */
int main()
{
	// ask user for driver
	video::E_DRIVER_TYPE driverType = video::EDT_OPENGL; //FIXME: hardcoded driverChoiceConsole();
	if (driverType == video::EDT_COUNT)
		return 1;

	// create device

	MyEventReceiver receiver;

	g_Device = createDevice(driverType, core::dimension2d<u32>(640, 480), 16,
			false, false, false, &receiver);

	if (g_Device == 0)
		return 1; // could not create selected driver.

	// create engine and camera

	g_Device->setWindowCaption(L"Custom Scene Node - Irrlicht Engine Demo");

	video::IVideoDriver* driver = g_Device->getVideoDriver();
	scene::ISceneManager* smgr = g_Device->getSceneManager();

	IGUIEnvironment* env = g_Device->getGUIEnvironment();

	IGUISkin* skin = env->getSkin();
	IGUIFont* font = env->getFont("media/fonthaettenschweiler.bmp");
	if (font)
		skin->setFont(font);

	skin->setFont(env->getBuiltInFont(), EGDF_TOOLTIP);

	env->addStaticText(L"Movement speed:", rect<s32> (GUI_X, GUI_Y, GUI_X + 95,
			GUI_Y + 20), true);
	IGUIScrollBar* scrollbar = env->addScrollBar(true, rect<s32> (GUI_X + 100,
			GUI_Y, GUI_X + 100 + 200, GUI_Y + 20), 0, GUI_ID_SPEED_SCROLL);

	//scrollbar->drop();

	//max speed -> 1000 * 1000 / 100000 = 10 km/frame
	//min speed -> 10 * 10 / 100000 = 1m / frame
	scrollbar->setMax(1000);
	scrollbar->setMin(10);

	scrollbar->setPos(255);

	// add a camera scene node
	scene::ICameraSceneNode* camera = smgr->addCameraSceneNodeFPS();
	//scene::ICameraSceneNode* camera = addCameraSceneNodeFPS(smgr);

	g_CameraAnimator = JWSceneNodeAnimatorCameraFPS::injectOnFPSCamera(camera);
	g_CameraAnimator->setMoveSpeed(scrollbar->getPos() / 5000.0);
	g_CameraAnimator->setAnimationEventsReceiver(&receiver);

	env->addStaticText(L"Level:", rect<s32> (GUI_X, GUI_Y + 22, GUI_X + 95,
			GUI_Y + 22 + 20), true);
	scrollbar = env->addScrollBar(true, rect<s32> (GUI_X + 100, GUI_Y + 22,
			GUI_X + 100 + 200, GUI_Y + 22 + 20), 0, GUI_ID_LEVEL);

#define START_LEVEL 14
	scrollbar->setMax(14);
	scrollbar->setMin(0);
	scrollbar->setPos(START_LEVEL);
	g_LevelScroll = scrollbar;
	env->addStaticText(L"Wireframe:", rect<s32> (GUI_X, GUI_Y + 22 + 22, GUI_X
			+ 95, GUI_Y + 22 + 22 + 20), true);
	env->addCheckBox(false, rect<s32> (GUI_X + 100, GUI_Y + 22 + 22, GUI_X
			+ 100 + 200, GUI_Y + 22 + 22 + 20), 0, GUI_ID_WIREFRAME);

	env->addStaticText(L"Update mesh:", rect<s32> (GUI_X, GUI_Y + 22 + 22 + 22,
			GUI_X + 95, GUI_Y + 22 + 22 + 22 + 20), true);
	env->addCheckBox(true, rect<s32> (GUI_X + 100, GUI_Y + 22 + 22 + 22, GUI_X
			+ 100 + 200, GUI_Y + 22 + 22 + 22 + 20), 0, GUI_ID_MESH_UPDATE);

	SKeyMap keyMap[] =
	{
	{ EKA_MOVE_FORWARD, KEY_KEY_W },
	{ EKA_MOVE_BACKWARD, KEY_KEY_S },
	{ EKA_STRAFE_LEFT, KEY_KEY_A },
	{ EKA_STRAFE_RIGHT, KEY_KEY_D },
	{ EKA_JUMP_UP, KEY_SPACE },
	{ EKA_CROUCH, KEY_LSHIFT } };
	g_CameraAnimator->setKeyMap(keyMap, 6);
	core::vector3df earthCenter(0, 0, 0);
	camera->setFarValue(500000.f); //500 000 km
	//camera->setUpVector(core::vector3df(0,0,1));
	camera->setPosition(core::vector3df(100, 100, -EARTH_RADIUS - 200.));
	camera->setTarget(earthCenter);
	//camera->setFarValue(20000.f);
	//camera->setPosition(core::vector3df(0,0,-200));
	// Maya cameras reposition themselves relative to their target, so target the location
	// where the mesh scene node is placed.
	//camera->setTarget(core::vector3df(0, 0, 0));
	//smgr->addCameraSceneNode(0, core::vector3df(0,-40,0), core::vector3df(0,0,0));
	/*
	 Create our scene node. I don't check the result of calling new, as it
	 should throw an exception rather than returning 0 on failure. Because
	 the new node will create itself with a reference count of 1, and then
	 will have another reference added by its parent scene node when it is
	 added to the scene, I need to drop my reference to it. Best practice is
	 to drop it only *after* I have finished using it, regardless of what
	 the reference count of the object is after creation.
	 */
	g_EarthVisualization = new SphereVisualization(smgr->getRootSceneNode(),
			smgr, driver, 666, START_LEVEL, earthCenter, EARTH_RADIUS);
	g_EarthVisualization->setMaterialType(video::EMT_SOLID);
	//g_textre = driver->getTexture("media/earth.bmp");
	//g_EarthVisualization->getMaterial().setTexture(0, g_textre);
	g_EarthVisualization->setViewerPoint(camera->getPosition());

	/*
	 To animate something in this boring scene consisting only of one
	 tetraeder, and to show that you now can use your scene node like any
	 other scene node in the engine, we add an animator to the scene node,
	 which rotates the node a little bit.
	 irr::scene::ISceneManager::createRotationAnimator() could return 0, so
	 should be checked.
	 */
	scene::ISceneNodeAnimator *anim = 0;
	//smgr->createRotationAnimator(core::vector3df(0.8f, 0, 0.8f));
	if (anim)
	{
		g_EarthVisualization->addAnimator(anim);
		/*
		 I'm done referring to anim, so must
		 irr::IReferenceCounted::drop() this reference now because it
		 was produced by a createFoo() function. As I shouldn't refer to
		 it again, ensure that I can't by setting to 0.
		 */
		anim->drop();
		anim = 0;
	}
	/*
	 I'm done with my CSampleSceneNode object, and so must drop my reference.
	 This won't delete the object, yet, because it is still attached to the
	 scene graph, which prevents the deletion until the graph is deleted or the
	 custom scene node is removed from it.
	 */
	g_EarthVisualization->drop();
	//myNode = 0; // As I shouldn't refer to it again, ensure that I can't
	scene::ISceneNode *bill = smgr->addBillboardSceneNode(0, core::dimension2d<
			f32>(600, 600), earthCenter, 113);
	//600x600 km billboard
	bill->setMaterialFlag(video::EMF_LIGHTING, false);
	bill->setMaterialFlag(video::EMF_ZWRITE_ENABLE, false);
	bill->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR);
	bill->setMaterialTexture(0, driver->getTexture("media/particlered.bmp"));
	//bill->drop();
	/*
	 Now draw everything and finish.
	 */
	u32 frames = 0;
	while (g_Device->run())
	{
		driver->beginScene(true, true, video::SColor(0, 100, 100, 100));
		smgr->drawAll();
		env->drawAll();
		driver->endScene();
		if (++frames == 100)
		{
			core::vector3df vpoint = g_EarthVisualization->getViewerPoint();
			vpoint.normalize();
			core::vector2d<f32> txCoord = g_EarthVisualization->getSphericalCoordinates(vpoint);

			core::stringw str = L"FPS: ";
			str += (s32) (driver->getFPS());
			str += L" TCoord:(";
			str += txCoord.X;
			str += L", ";
			str += txCoord.Y;
			str += L") Tile: ";
			str.printBinary(g_EarthVisualization->getUTriangleUnderUs(), 32,
					L'0', L'1');
			g_Device->setWindowCaption(str.c_str());
			frames = 0;
		}
	}

	g_Device->drop();

	return 0;
}