예제 #1
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();
}
예제 #2
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;
}