Ejemplo n.º 1
0
void Game::loadTerrain(){
  ITerrainSceneNode* terrain = smgr->addTerrainSceneNode(
    "resources/other/heightmap.png",
    0,                  // parent node
    -1,                 // node id
    core::vector3df(0.f, 0.f, 0.f),     // position
    core::vector3df(0.f, 0.f, 0.f),     // rotation
    core::vector3df(40.f, 4.4f, 40.f),  // scale
    video::SColor ( 255, 255, 255, 255 ),   // vertexColor
    5,                  // maxLOD
    scene::ETPS_17,             // patchSize
    4                   // smoothFactor
    );
    terrain->setMaterialFlag(video::EMF_LIGHTING, false);
    terrain->setMaterialTexture(0, driver->getTexture("resources/other/heightmap_texture.png"));
    terrain->setPosition(vector3df(0, 0, 0));
    ITriangleSelector* selector = smgr->createTerrainTriangleSelector(terrain, 0);
    terrain->setTriangleSelector(selector);
    scene::ISceneNodeAnimator* anim = smgr->createCollisionResponseAnimator(
    selector, camera, core::vector3df(10,10,10),
    core::vector3df(0,-9,0),
    core::vector3df(0,50,0));
    camera->addAnimator(anim);
    scene::ISceneNode* skybox=smgr->addSkyBoxSceneNode(
    driver->getTexture("resources/textures/skybox/coulee_up.jpg"),
    driver->getTexture("resources/textures/skybox/coulee_dn.jpg"),
    driver->getTexture("resources/textures/skybox/coulee_rt.jpg"),
    driver->getTexture("resources/textures/skybox/coulee_lf.jpg"),
    driver->getTexture("resources/textures/skybox/coulee_ft.jpg"),
    driver->getTexture("resources/textures/skybox/coulee_bk.jpg"));
}
void PhysicsSim::addTerrain(stringw heightfield_file, stringw texture_file, Vector3D scale)
{
	stringw filename = mediaDirectory + heightfield_file;
	stringw texfilename = mediaDirectory + texture_file;

	IImage* hfimg = driver->createImageFromFile (filename.c_str());

	int img_width = hfimg->getDimension().Width;
	int img_height = hfimg->getDimension().Height;

	float xScale = scale.X, yScale = scale.Y, zScale = scale.Z;

	ITerrainSceneNode* terrain = smgr->addTerrainSceneNode(	filename.c_str(),
											smgr->getRootSceneNode(),               // parent node
											-1,                                     // node id
											vector3df(0.f, 0.f, 0.f),               // position
											vector3df(0.f, 0.f, 0.f),               // rotation
											vector3df(1.f, 1.0f, 1.f),              // scale
											video::SColor ( 255, 255, 255, 255 ),   // vertexColor
											5,                                      // maxLOD
											ETPS_17,                                // patchSize
											4                                       // smoothFactor
											);
	terrain->setMaterialTexture(0, driver->getTexture(texfilename.c_str()));
	terrain->scaleTexture(200.0f, 0);

	terrain->setScale(vector3df(xScale, yScale, zScale));
	terrain->setPosition(vector3df(-((img_width-1.0)*xScale)/2.0, 0.0, -((img_height-1.0)*zScale)/2.0));

	this->terrain = new Terrain(terrain, hfimg, Vector3D(xScale, yScale, zScale));

	dynamicsWorld->addRigidBody(this->terrain->getRigidBody());

}
Ejemplo n.º 3
0
/*
The start of the main function starts like in most other example. We ask the
user for the desired renderer and start it up. This time with the advanced
parameter handling.
*/
int main()
{
	// create device with full flexibility over creation parameters
	// you can add more parameters if desired, check irr::SIrrlichtCreationParameters
	irr::SIrrlichtCreationParameters params;
	params.DriverType= video::EDT_DIRECT3D9;
	params.WindowSize=core::dimension2d<u32>(1024, 768);
	IrrlichtDevice* device = createDeviceEx(params);

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

	
	/*
	First, we add standard stuff to the scene: A nice irrlicht engine
	logo, a small help text, a user controlled camera, and we disable
	the mouse cursor.
	*/

	video::IVideoDriver* driver = device->getVideoDriver();
	scene::ISceneManager* smgr = device->getSceneManager();
	gui::IGUIEnvironment* env = device->getGUIEnvironment();
	IFileSystem* filesys = device->getFileSystem();

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

	SKeyMap keyMap[4];
	keyMap[0].Action = EKA_MOVE_FORWARD;
	keyMap[0].KeyCode = KEY_UP;
	keyMap[1].Action = EKA_MOVE_BACKWARD;
	keyMap[1].KeyCode = KEY_DOWN;
	keyMap[2].Action = EKA_STRAFE_LEFT;
	keyMap[2].KeyCode = KEY_LEFT;
	keyMap[3].Action = EKA_STRAFE_RIGHT;
	keyMap[3].KeyCode = KEY_RIGHT;


	// add camera
	camera = smgr->addCameraSceneNodeFPS(0,100.0f,0.5f, -1, keyMap, 4);

	camera->setPosition(core::vector3df(-168, 283, -168));
	camera->setTarget(core::vector3df(60,137,83));
	camera->setFarValue(42000.0f);

	// disable mouse cursor
	device->getCursorControl()->setVisible(false);

	// create event receiver
	MyEventReceiver receiver;
	device->setEventReceiver(&receiver);

	smgr->setAmbientLight(video::SColorf(0.1,0.1,0.1,1));

	ITerrainSceneNode* floorNode = smgr->addTerrainSceneNode(0, 0, -1, vector3df(0, 0, 0), vector3df(0, 0, 0), vector3df(1, 1, 1), SColor(255, 255, 255, 255), 5, ETPS_17, 0, true);
	char floor[32 * 32] = {0};
	IReadFile* floorfile = filesys->createMemoryReadFile(floor, sizeof(char) * 32 * 32, "m2");
	floorNode->loadHeightMapRAW(floorfile);
	//floorNode->setMaterialFlag(EMF_LIGHTING, false);
	floorNode->setScale(vector3df(100, 1, 100));
	floorNode->setPosition(vector3df(-800, 1, -800));
	floorNode->getMaterial(0).EmissiveColor.set(255,10,10,10);
	//floorNode->setVisible(false);

	smgr->addSphereSceneNode(10);

	tool = smgr->addSphereSceneNode(TOOL_R);
	ISceneNodeAnimator* anim = smgr->createRotationAnimator(core::vector3df(0,1,0));
	tool->addAnimator(anim);
	tool->setPosition(vector3df(0, 120, 0));
	tool->setMaterialFlag(EMF_WIREFRAME, true);

	node = smgr->addTerrainSceneNode(0, 0, -1, vector3df(0, 0, 0), vector3df(0, 0, 0), vector3df(1, 1, 1), SColor(255, 255, 255, 255), 0, ETPS_17, 0, true);
	
	
	
	
	for (int i = OFFSET; i < (MATERIAL_SIZE + OFFSET); ++i)
	{
		for (int j = OFFSET; j < (MATERIAL_SIZE + OFFSET); ++j)
		{
			material[i * REAL_SIZE + j] = 100; 
		}
	}

	file = filesys->createMemoryReadFile(material, sizeof(float) * REAL_SIZE * REAL_SIZE, "m1");
	node->loadHeightMapRAW(file, 32, false, true, REAL_SIZE);

	node->getMaterial(0).AmbientColor.set(255,0,0,255);
	//node->getMaterial(0).Shininess = 20.0f;
	
  	//node->setMaterialFlag(EMF_LIGHTING, false);
 	//node->setMaterialFlag(EMF_WIREFRAME, true);
	node->setMaterialFlag(EMF_BACK_FACE_CULLING, false);
	node->setPosition(vector3df(-OFFSET, 0, -OFFSET));


	smgr->addLightSceneNode( 0, core::vector3df(100,300,100), video::SColorf(0.3f,0.3f,0.3f), 300); 

	std::list<vector3df> pathList;
	pathList.push_back(vector3df(30, 100, 30));
	pathList.push_back(vector3df(30, 100, 170));
	pathList.push_back(vector3df(170, 100, 170));
	pathList.push_back(vector3df(170, 100, 30));
	pathList.push_back(vector3df(60, 100, 30));
	pathList.push_back(vector3df(60, 100, 140));
	pathList.push_back(vector3df(140, 100, 140));
	pathList.push_back(vector3df(140, 100, 60));

	std::list<vector3df>::iterator pathIter = pathList.begin();

	int s = 0;


	int lastFPS = -1;

	while(device->run())
	if (device->isWindowActive())
	{
			if (pathIter != pathList.end())
			{
				vector3df endP = *pathIter;
				vector3df noewP = tool->getPosition();

				vector3df vStep;

				if (noewP.X < endP.X)
				{
					vStep.X = STEP;
				}
				if (noewP.X > endP.X)
				{
					vStep.X = -STEP;
				}

				if (noewP.Y < endP.Y)
				{
					vStep.Y = STEP;
				}
				if (noewP.Y > endP.Y)
				{
					vStep.Y = -STEP;
				}

				if (noewP.Z < endP.Z)
				{
					vStep.Z = STEP;
				}
				if (noewP.Z > endP.Z)
				{
					vStep.Z = -STEP;
				}

				tool->setPosition(tool->getPosition() + vStep);
				Cut();

				if (endP.getDistanceFrom(noewP) <= STEP)
				{
					++pathIter;
				}
			}


//  		IMesh* m = node->getMesh();
//  		IMeshBuffer* b = m->getMeshBuffer(0);
//  
//  		u32 c1 = m->getMeshBufferCount();
//  
//  		u32 c2 = b->getVertexCount();
//  
//  		void* v = b->getVertices();
//  
//   		for (int i = 0; i < 30; ++i)
//   		{
//   			for (int j = 0; j < 30; ++j)
//   			{
//  				S3DVertex2TCoords* tmpv = (static_cast<S3DVertex2TCoords*>(v) + (i + s + 10) * 128 + (j + s + 10));
//  
//   				tmpv->Pos.Y = 1000;
//   			}
//   		}
//   
//   		s = (s + 1) % 50 + 10;
//   
//   		for (int i = 0; i < 30; ++i)
//   		{
//   			for (int j = 0; j < 30; ++j)
//   			{
//  				S3DVertex2TCoords* tmpv = (static_cast<S3DVertex2TCoords*>(v) + (i + s + 10) * 128 + (j + s + 10));
//  
//  				tmpv->Pos.Y = 800;
//   			}
//   		}
//  		node->setPosition(node->getPosition());


		driver->beginScene(true, true, 0 );

		smgr->drawAll();
		env->drawAll();


// 		for (int i = 0; i < 30; ++i)
// 		{
// 			for (int j = 0; j < 30; ++j)
// 			{
// 				material[(i + s + 10) * 128 + (j + s + 10)] = 1000;
// 			}
// 		}
// 
// 		s = (s + 1) % 50 + 10;
// 
// 		for (int i = 0; i < 30; ++i)
// 		{
// 			for (int j = 0; j < 30; ++j)
// 			{
// 				material[(i + s + 10) * 128 + (j + s + 10)] = 800;
// 			}
// 		}
// 
// 		file->read(material, sizeof(float) * 128 * 128);
// 		file->seek(0);
// 		node->loadHeightMapRAW(file, 32, false, true, 128);
// 
// 		node->setMaterialFlag(EMF_LIGHTING, false);
// 		node->setMaterialFlag(EMF_WIREFRAME, true);
// 		node->setMaterialFlag(EMF_BACK_FACE_CULLING, false);
// 		node->setMaterialFlag(EMF_FRONT_FACE_CULLING, false);

		


		driver->endScene();

		// display frames per second in window title
		int fps = driver->getFPS();
		if (lastFPS != fps)
		{
			core::stringw str = L"Terrain Renderer - Irrlicht Engine [";
			str += driver->getName();
			str += "] FPS:";
			str += fps;
			// Also print terrain height of current camera position
			// We can use camera position because terrain is located at coordinate origin

			device->setWindowCaption(str.c_str());
			lastFPS = fps;
		}
	}

	device->drop();

	return 0;
}
Ejemplo n.º 4
0
int main()
{


/*		shadowDimen = dimension2du(1024,1024);
		shadowDimen = dimension2du(2048,2048);
		shadowDimen = dimension2du(4096,4096);
		shadowDimen = dimension2du(2048,2048);
		filterType = EFT_NONE;
		filterType = EFT_4PCF;
		filterType = EFT_8PCF;
		filterType = EFT_4PCF;
*/
	dimension2du shadowDimen = dimension2du(1024,1024);
    E_FILTER_TYPE filterType = EFT_4PCF;
    filterType = EFT_NONE;
////


IrrlichtDevice* device = createDevice(EDT_OPENGL,dimension2du(800,600),32);

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

ICameraSceneNode* cam = smgr->addCameraSceneNodeFPS(0,100,.5);
cam->setPosition(vector3df(0,10,0));

// Create the effect handler, passing the device and RTT size (as a dimension2d) .
effectHandler* effect = new effectHandler(device,shadowDimen);


ITerrainSceneNode* terrain = smgr->addTerrainSceneNode("media/terrain.bmp",0,-1,vector3df(0,0,0),vector3df(0,0,0),vector3df(1,1,1),SColor(255,255,255,255),1,ETPS_33);
terrain->setMaterialTexture(0,driver->getTexture("media/terrain.jpg"));
terrain->setMaterialTexture(1, driver->getTexture("media/detailmap.jpg"));
terrain->scaleTexture(1,10);
terrain->setScale(core::vector3df(4, 0.01f, 4));
terrain->setPosition(vector3df(-120,-1.5f,-120));
terrain->setMaterialType(EMT_DETAIL_MAP);

// Make the terrain recieve a shadow with the specified filter type.
// (NOTE: 12PCF is only available in Direct3D9, all others work with OpenGL)
effect->addShadowToNode(terrain,filterType);

IAnimatedMeshSceneNode* sydney;
IAnimatedMesh* sydneymesh = smgr->getMesh("media/dwarf.x");

for(int g = 0;g < 1;g++)
{
	for(int v = 0;v < 3;v++)
	{
		sydney = smgr->addAnimatedMeshSceneNode(sydneymesh);
		sydney->setScale(vector3df(0.05f,0.05f,0.05f));
		sydney->setPosition(vector3df(g * 4,0.5f,v * 4));
		sydney->setMaterialFlag(EMF_NORMALIZE_NORMALS,true);

		sydney->setAutomaticCulling(EAC_FRUSTUM_BOX);

		sydney->setMaterialType(EMT_SOLID);

		// Add the nodes to the depth pass so that they cast a shadow.
		effect->addNodeToDepthPass(sydney);

	}
}


effect->getLightCamera()->addAnimator(smgr->createFlyCircleAnimator(sydney->getPosition() + vector3df(0,15,0),25,0.0002f));

effect->getLightCamera()->setNearValue(5);

effect->setMaxShadowDistanceFromLight(120);

smgr->addLightSceneNode(effect->getLightCamera());


MyEventReceiver receiver(cam);
device->setEventReceiver(&receiver);

// Parent a sphere to the light camera so we can see its position.
smgr->addSphereSceneNode(1,8,effect->getLightCamera())->setMaterialFlag(EMF_LIGHTING,false);



while(device->run())
{
	wchar_t tmp[255];
	swprintf(tmp,255,L"Shadow Map Demo (FPS: %d)",driver->getFPS());
	device->setWindowCaption(tmp);

	driver->beginScene(true,true,SColor(0,0,0,0));

	// Point the light camera at one of the nodes as it rotates around them.
	effect->setLightTarget(sydney->getPosition());

	// Update the effect  handler, remember to always do this BEFORE smgr->drawAll and AFTER beginscene!
	effect->update();

	smgr->drawAll();

	// If user wishes we can display the shadow map to the screen. (May not work in OpenGL)
	if(disp2d)
		driver->draw2DImage(effect->getShadowMapTexture(),position2d<s32>(0,0));

	driver->endScene();
	//	device->sleep(5);
}

device->drop();
return 0;
}