Esempio n. 1
0
void Stage::createBackground()
{
	dimension2d<u32> screenSize = _game->getDevice(
		)->getVideoDriver()->getScreenSize();
	dimension2d<f32> screenSizeF32 = dimension2d<f32>( 
		(f32) screenSize.Width, (f32) screenSize.Height);

	ISceneManager* scene = _game->getDevice()->getSceneManager();
	const IGeometryCreator* geometry = scene->getGeometryCreator();

	SMaterial material;
	material.MaterialType = EMT_TRANSPARENT_ALPHA_CHANNEL;

	dimension2d<u32> textureSize = _stageConfig.BackgroundTexture->getSize();
	dimension2d<f32> textureRepeats = dimension2d<f32>(
		screenSizeF32.Width/textureSize.Width, 
		screenSizeF32.Height/textureSize.Height);

	material.setTexture(0, _stageConfig.BackgroundTexture); 
	scene->addMeshSceneNode(geometry->createPlaneMesh(
		screenSizeF32, dimension2d<u32>(1, 1), &material, textureRepeats),
		_rootNode);
}
Esempio n. 2
0
	/*!
		Constructs button as a plane node and text node with shared root node.
		@param game Game instance.
		@param config Configuration (texture, size, etc).
		@param index Index of the button (from 0 to count - 1).
	*/
	Button(Game* game, const MenuConfig& config, s32 index)
	{
		ISceneManager* scene = game->getDevice()->getSceneManager();
		Root = scene->addEmptySceneNode();

		scene->addTextSceneNode(
			config.Font,
			config.Buttons[index].Text.c_str(),
			config.FontColor,
			Root)->setPosition(vector3df(0, 10, 0));

		SMaterial material;

		material.MaterialType = EMT_TRANSPARENT_ALPHA_CHANNEL;
		material.setTexture(0, config.ButtonTextures.Default);

		Plane = scene->addMeshSceneNode(
			scene->getGeometryCreator()->createPlaneMesh(
				dimension2df(
					(f32) config.ButtonSize.Width, 
					(f32) config.ButtonSize.Height),
				dimension2du(1, 1), &material, dimension2df(1, 1)
			), Root);
	};
/** Tests that the geometry creator does what it says it does. */
bool testGeometryCreator(void)
{
	IrrlichtDevice *device = createDevice(video::EDT_BURNINGSVIDEO,
					core::dimension2du(160,120), 32);
	if (!device)
		return false;

	IVideoDriver* driver = device->getVideoDriver();
	ISceneManager* smgr = device->getSceneManager();
	(void)smgr->addCameraSceneNode(0, vector3df(0, 0, -50));

	const IGeometryCreator * geom = smgr->getGeometryCreator();

	ITexture * wall = driver->getTexture("../media/wall.bmp");

	SMaterial material;
	material.Lighting = false;
	material.TextureLayer[0].Texture = wall;

	irr::scene::IMesh * meshHill = geom->createHillPlaneMesh(dimension2df(10, 5), dimension2du(5, 5), 
									&material, 10, dimension2df(2, 2), dimension2df(3, 3) );
	IMeshSceneNode * node = smgr->addMeshSceneNode(meshHill, 0, -1,
									vector3df(0, 10, 0), vector3df(-60, 0, 0));
	meshHill->drop();

	irr::scene::IMesh * meshArrow = geom->createArrowMesh(4, 8, 10, 6, 3, 6,
								SColor(255, 255, 0, 0), SColor(255, 0, 255, 0));
	node = smgr->addMeshSceneNode(meshArrow, 0, -1, vector3df(-10, -20, 0));
	node->setMaterialFlag(video::EMF_LIGHTING, false);
	meshArrow->drop();

	irr::scene::IMesh * meshCone = geom->createConeMesh(5.f, 10.f, 16);
	node = smgr->addMeshSceneNode(meshCone, 0, -1, vector3df(-35, -20, 0));
	node->setMaterialFlag(video::EMF_LIGHTING, false);
	node->setMaterialTexture(0, wall);
	meshCone->drop();

	irr::scene::IMesh * meshCube = geom->createCubeMesh();
	node = smgr->addMeshSceneNode(meshCube, 0, -1, vector3df(-20, -20, 0));
	node->setMaterialFlag(video::EMF_LIGHTING, false);
	node->setMaterialTexture(0, wall);
	meshCube->drop();

	irr::scene::IMesh * meshCylinder = geom->createCylinderMesh(3, 10, 16);
	node = smgr->addMeshSceneNode(meshCylinder, 0, -1, vector3df(0, -20, 10), core::vector3df(45,0,0));
	node->setMaterialFlag(video::EMF_LIGHTING, false);
	node->setMaterialTexture(0, wall);
	meshCylinder->drop();

	irr::scene::IMesh * meshSphere = geom->createSphereMesh();
	node = smgr->addMeshSceneNode(meshSphere, 0, -1, vector3df(10, -15, 0));
	node->setMaterialFlag(video::EMF_LIGHTING, false);
	node->setMaterialTexture(0, wall);
	meshSphere->drop();

	irr::scene::IMesh * meshVolumeLight = geom->createVolumeLightMesh();
	node = smgr->addMeshSceneNode(meshVolumeLight, 0, -1, vector3df(20, -20, -10));
	node->setMaterialFlag(video::EMF_LIGHTING, false);
	node->setMaterialTexture(0, wall);
	node->setScale(core::vector3df(4.f,4.f,4.f));
	meshVolumeLight->drop();

	bool result = false;
	device->run();
	if (driver->beginScene(true, true, video::SColor(0, 80, 80, 80)))
	{
		smgr->drawAll();
		driver->endScene();
		result = takeScreenshotAndCompareAgainstReference(driver, "-testGeometryCreator.png", 99.994f);
	}

	smgr->clear();

	driver->setTextureCreationFlag(video::ETCF_ALWAYS_32_BIT, true);

	// add camera
	scene::ICameraSceneNode* camera = smgr->addCameraSceneNodeFPS(0,100.0f,2.0f);
	camera->setPosition(core::vector3df(2000.0f,5000.f,0.0f));
	camera->setTarget(core::vector3df(0.0f,0.0f,0.0f));
	camera->setFarValue(20000.0f);
	device->getCursorControl()->setVisible(false); // disable mouse cursor

	video::IImage* colorMapImage = driver->createImageFromFile("../media/terrain-texture.jpg");
	video::IImage* heightMapImage = driver->createImageFromFile("../media/terrain-heightmap.bmp");

	scene::IAnimatedMesh* terrain = smgr->addTerrainMesh("TerrainMeshName",
			colorMapImage, heightMapImage,
			core::dimension2d<f32>(40, 40), // size of a pixel
			8*40); // maximum height
	colorMapImage->drop();
	colorMapImage = 0;
	heightMapImage->drop();
	heightMapImage = 0;

	scene::IAnimatedMeshSceneNode* anode = smgr->addAnimatedMeshSceneNode(terrain);
	if (anode)
	{
		anode->setMaterialFlag(video::EMF_LIGHTING, false);
		anode->setPosition(core::vector3df(-5000,0,-5000));
	}

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

	// This screenshot shows some mipmap problems, but this seems to be
	// no fault of the mesh
	result = takeScreenshotAndCompareAgainstReference(driver, "-testTerrainMesh.png", 99.989f);

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

	return result;
}
/** Tests that the geometry creator does what it says it does. */
bool testGeometryCreator(void)
{
    IrrlichtDevice *device = createDevice(video::EDT_BURNINGSVIDEO,
										core::dimension2du(160,120), 32);
    if (!device)
        return false;

    IVideoDriver* driver = device->getVideoDriver();
    ISceneManager* smgr = device->getSceneManager();
	(void)smgr->addCameraSceneNode(0, vector3df(0, 0, -50));

	const IGeometryCreator * geom = smgr->getGeometryCreator();

	ITexture * wall = driver->getTexture("../media/wall.bmp");

	SMaterial material;
	material.Lighting = false;
	material.TextureLayer[0].Texture = wall;

	IMeshSceneNode * node = smgr->addMeshSceneNode(
		geom->createHillPlaneMesh(dimension2df(10, 5), dimension2du(5, 5), 
									&material, 10, dimension2df(2, 2), dimension2df(3, 3)), 0, -1,
									vector3df(0, 10, 0), vector3df(-60, 0, 0));

	node = smgr->addMeshSceneNode(geom->createArrowMesh(4, 8, 10, 6, 3, 6,
														SColor(255, 255, 0, 0), SColor(255, 0, 255, 0)),
									0, -1, vector3df(-10, -20, 0));
	node->setMaterialFlag(video::EMF_LIGHTING, false);

	node = smgr->addMeshSceneNode(geom->createConeMesh(5.f, 10.f, 16), 0, -1, vector3df(-35, -20, 0));
	node->setMaterialFlag(video::EMF_LIGHTING, false);
	node->setMaterialTexture(0, wall);

	node = smgr->addMeshSceneNode(geom->createCubeMesh(), 0, -1, vector3df(-20, -20, 0));
	node->setMaterialFlag(video::EMF_LIGHTING, false);
	node->setMaterialTexture(0, wall);

	node = smgr->addMeshSceneNode(geom->createCylinderMesh(3, 10, 16), 0, -1, vector3df(0, -20, 10), core::vector3df(45,0,0));
	node->setMaterialFlag(video::EMF_LIGHTING, false);
	node->setMaterialTexture(0, wall);

	node = smgr->addMeshSceneNode(geom->createSphereMesh(), 0, -1, vector3df(10, -15, 0));
	node->setMaterialFlag(video::EMF_LIGHTING, false);
	node->setMaterialTexture(0, wall);

	node = smgr->addMeshSceneNode(geom->createVolumeLightMesh(), 0, -1, vector3df(20, -20, -10));
	node->setMaterialFlag(video::EMF_LIGHTING, false);
	node->setMaterialTexture(0, wall);
	node->setScale(core::vector3df(4.f,4.f,4.f));

	bool result = false;
	device->run();
	if (driver->beginScene(true, true, video::SColor(0, 80, 80, 80)))
	{
		smgr->drawAll();
		driver->endScene();
		result = takeScreenshotAndCompareAgainstReference(driver, "-testGeometryCreator.png", 99.999f);
	}

    device->drop();

    return result;
}