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()); }
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(); }
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; }
/* 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; }
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; }