示例#1
0
文件: main.cpp 项目: lisacvuk/Game
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());

}
示例#3
0
void Game::init()
{
#ifdef WIN32
	device = createDevice(video::EDT_DIRECT3D9, core::dimension2d<s32>(640, 480));
#else
	device = createDevice(video::EDT_OPENGL, core::dimension2d<s32>(640, 480));
#endif
	
	driver = device->getVideoDriver();
	smgr = device->getSceneManager();
	guienv = device->getGUIEnvironment();
	
	device->setWindowCaption(L"Not So Much Super Offroad - By Andreas Kröhnke");
	
	IMeshSceneNode *node = smgr->addMeshSceneNode( smgr->getMesh("data/car3.3ds")->getMesh(0) );
	GameObject *car = new GameObject();
	car->setSceneNode(node);
	node->setMaterialFlag(EMF_LIGHTING, false);
	node->setScale(vector3df(0.09,0.09,0.09));
	node->setRotation(vector3df(0,0,0));
	node->setPosition(vector3df(3454,500,1256));
	//node->setDebugDataVisible(EDS_BBOX);
	object->push_back(car);
	
	ITerrainSceneNode *terrain = smgr->addTerrainSceneNode("data/level1.bmp");
	GameObject *go_terrain = new GameObject();
	go_terrain->setSceneNode(terrain);
	terrain->setMaterialFlag(EMF_LIGHTING, false);
	terrain->setScale(core::vector3df(18, 3.0f, 18));
	terrain->setMaterialFlag(video::EMF_LIGHTING, false);
	terrain->setMaterialTexture(0, driver->getTexture("data/terrain-texture.jpg"));
	terrain->setMaterialTexture(1, driver->getTexture("data/detailmap3.jpg"));
	terrain->setMaterialType(video::EMT_DETAIL_MAP);
	terrain->scaleTexture(1.0f, 20.0f);
	terrain->setDebugDataVisible(EDS_BBOX);
	object->push_back(go_terrain);
	
	// Camera
	Camera *cam = new Camera();
	cam->setSceneNode(smgr->addCameraSceneNode());
	object->push_back(cam);
	cam->followNode(car->getSceneNode());
	
	reciever = new EventReciever();
	reciever->setSteer(car->getSceneNode());
	device->setEventReceiver(reciever);
	
	// create triangle selector for the terrain	
	ITriangleSelector* selector = smgr->createTerrainTriangleSelector(terrain, 0);
	terrain->setTriangleSelector(selector);
	selector->drop();
	
	// create collision response animator and attach it to the camera
	ISceneNodeAnimator* anim = smgr->createCollisionResponseAnimator(selector, car->getSceneNode(), core::vector3df(10,10,10),
																			core::vector3df(0,-5.0f,0), 
																			core::vector3df(0,0,0)
	);
	
	car->getSceneNode()->addAnimator(anim);
	anim->drop();
	
	// Skybox
	smgr->addSkyBoxSceneNode(
							 driver->getTexture("data/irrlicht2_up.jpg"),
							 driver->getTexture("data/irrlicht2_dn.jpg"),
							 driver->getTexture("data/irrlicht2_lf.jpg"),
							 driver->getTexture("data/irrlicht2_rt.jpg"),
							 driver->getTexture("data/irrlicht2_ft.jpg"),
							 driver->getTexture("data/irrlicht2_bk.jpg"));
	
	// Checkpoints
	pair<vector3df, vector3df> cp1(vector3df(3112,393,1234), vector3df(90,90,0));
	addCheckPoint(cp1.first, cp1.second);
	pair<vector3df, vector3df> cp2(vector3df(2531,281,1389), vector3df(90,120,0));
	addCheckPoint(cp2.first, cp2.second);
	addCheckPoint(vector3df(2304,160,1826), vector3df(90,140,0));
	addCheckPoint(vector3df(2132,111,2672), vector3df(90,120,0));
	addCheckPoint(vector3df(1130,415,3313), vector3df(90,75,0));
	addCheckPoint(vector3df(746,471,1753), vector3df(90,0,0));
	addCheckPoint(vector3df(1985,269,1457), vector3df(90,-120,0));
	addCheckPoint(vector3df(2475,146,2868), vector3df(90,-120,0));
	addCheckPoint(vector3df(3707,417,2915), vector3df(90,-60,0));
	
	// Arrows
	addArrow(vector3df(3012,320,1234), vector3df(100,-55,0));
	addArrow(vector3df(2531,220,1389), vector3df(100,-10,0));
	//addArrow(vector3df(2304,110,1826), vector3df(90,10,0));
	addArrow(vector3df(2232,20,2272), vector3df(90,-20,0));

	// HUD
	info = guienv->addStaticText(L"USE ARROW KEYS TO PLAY",
								 rect<int>(10,10,200,60), true);
	info->setOverrideColor(SColor(255, 255, 255, 255));

	//IGUIStaticText *quick_info = guienv->addStaticText(L"Arrow keys to play\n", rect<int>(10,50,200,50), true);
	//quick_info->setOverrideColor(SColor(255,255,255,255));
	initSound();
}
示例#4
0
bool terrainSceneNode(void)
{
    IrrlichtDevice *device =
        createDevice(video::EDT_OPENGL, dimension2di(160, 120), 32);

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

    ITerrainSceneNode* terrain = smgr->addTerrainSceneNode(
        "../media/terrain-heightmap.bmp");
    terrain->setScale(core::vector3df(40.f, .1f, 40.f));

    terrain->setMaterialFlag(video::EMF_LIGHTING, false);
    terrain->setMaterialTexture(0, driver->getTexture("../media/terrain-texture.jpg"));
    terrain->setDebugDataVisible(scene::EDS_FULL);

    ICameraSceneNode* camera = smgr->addCameraSceneNode();

    const core::vector3df center (terrain->getBoundingBox().getCenter());
    camera->setTarget (center);

    // yes, Y is intentionally being set to X here
    const core::vector3df above (center.X, center.X, center.Z);
    camera->setPosition (above);
	camera->setUpVector(vector3df(1.f, 0.f, 0.f));
    camera->setFarValue(above.Y);

    device->run();
    smgr->drawAll();


	// This shouldn't cause a recalc
	camera->setUpVector(vector3df(1.f, 0.f, .01f).normalize());
    device->run();
	driver->beginScene(true, true, video::SColor(255,100,101,140));
	smgr->drawAll();
	driver->endScene();

	// Note that this has to be a slightly fuzzier than usual compare to satisfy multiple OpenGL environments
	bool result = takeScreenshotAndCompareAgainstReference(driver, "-terrainSceneNode-1.png", 98.3f);
	if(!result)
	{
		logTestString("Small camera up rotation caused bad recalc.\n");
		assert(false);
	}


	// This is big enough to cause a recalc
	camera->setUpVector(vector3df(1.f, 0.f, .1f).normalize());
    device->run();
	driver->beginScene(true, true, video::SColor(255,100,101,140));
	smgr->drawAll();
	driver->endScene();

	result &= takeScreenshotAndCompareAgainstReference(driver, "-terrainSceneNode-2.png", 98.9f);
	if(!result)
	{
		logTestString("Large camera up rotation caused bad recalc.\n");
		assert(false);
	}

    device->drop();
    return result;
}
示例#5
0
文件: example.cpp 项目: tecan/Luna
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;
}