From 7028cbe09c688437910a25623098762bf0fa592d Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Mon, 28 Mar 2016 22:28:34 +1000 Subject: Move Irrlicht to src/others. --- .../examples/12.TerrainRendering/Makefile | 38 +++ .../12.TerrainRendering/TerrainRendering.cbp | 56 ++++ .../12.TerrainRendering/TerrainRendering.dev | 59 +++++ .../12.TerrainRendering/TerrainRendering.vcproj | 163 ++++++++++++ .../TerrainRendering_vc10.vcxproj | 231 +++++++++++++++++ .../TerrainRendering_vc11.vcxproj | 235 +++++++++++++++++ .../TerrainRendering_vc8.vcproj | 231 +++++++++++++++++ .../TerrainRendering_vc9.vcproj | 230 +++++++++++++++++ .../examples/12.TerrainRendering/main.cpp | 285 +++++++++++++++++++++ .../examples/12.TerrainRendering/tutorial.html | 122 +++++++++ 10 files changed, 1650 insertions(+) create mode 100644 src/others/irrlicht-1.8.1/examples/12.TerrainRendering/Makefile create mode 100644 src/others/irrlicht-1.8.1/examples/12.TerrainRendering/TerrainRendering.cbp create mode 100644 src/others/irrlicht-1.8.1/examples/12.TerrainRendering/TerrainRendering.dev create mode 100644 src/others/irrlicht-1.8.1/examples/12.TerrainRendering/TerrainRendering.vcproj create mode 100644 src/others/irrlicht-1.8.1/examples/12.TerrainRendering/TerrainRendering_vc10.vcxproj create mode 100644 src/others/irrlicht-1.8.1/examples/12.TerrainRendering/TerrainRendering_vc11.vcxproj create mode 100644 src/others/irrlicht-1.8.1/examples/12.TerrainRendering/TerrainRendering_vc8.vcproj create mode 100644 src/others/irrlicht-1.8.1/examples/12.TerrainRendering/TerrainRendering_vc9.vcproj create mode 100644 src/others/irrlicht-1.8.1/examples/12.TerrainRendering/main.cpp create mode 100644 src/others/irrlicht-1.8.1/examples/12.TerrainRendering/tutorial.html (limited to 'src/others/irrlicht-1.8.1/examples/12.TerrainRendering') diff --git a/src/others/irrlicht-1.8.1/examples/12.TerrainRendering/Makefile b/src/others/irrlicht-1.8.1/examples/12.TerrainRendering/Makefile new file mode 100644 index 0000000..92b529f --- /dev/null +++ b/src/others/irrlicht-1.8.1/examples/12.TerrainRendering/Makefile @@ -0,0 +1,38 @@ +# Makefile for Irrlicht Examples +# It's usually sufficient to change just the target name and source file list +# and be sure that CXX is set to a valid compiler +Target = 12.TerrainRendering +Sources = main.cpp + +# general compiler settings +CPPFLAGS = -I../../include -I/usr/X11R6/include +CXXFLAGS = -O3 -ffast-math +#CXXFLAGS = -g -Wall + +#default target is Linux +all: all_linux + +ifeq ($(HOSTTYPE), x86_64) +LIBSELECT=64 +endif + +# target specific settings +all_linux: LDFLAGS = -L/usr/X11R6/lib$(LIBSELECT) -L../../lib/Linux -lIrrlicht -lGL -lXxf86vm -lXext -lX11 -lXcursor +all_linux clean_linux: SYSTEM=Linux +all_win32: LDFLAGS = -L../../lib/Win32-gcc -lIrrlicht -lopengl32 -lm +all_win32 clean_win32: SYSTEM=Win32-gcc +all_win32 clean_win32: SUF=.exe +# name of the binary - only valid for targets which set SYSTEM +DESTPATH = ../../bin/$(SYSTEM)/$(Target)$(SUF) + +all_linux all_win32: + $(warning Building...) + $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(Sources) -o $(DESTPATH) $(LDFLAGS) + +clean: clean_linux clean_win32 + $(warning Cleaning...) + +clean_linux clean_win32: + @$(RM) $(DESTPATH) + +.PHONY: all all_win32 clean clean_linux clean_win32 diff --git a/src/others/irrlicht-1.8.1/examples/12.TerrainRendering/TerrainRendering.cbp b/src/others/irrlicht-1.8.1/examples/12.TerrainRendering/TerrainRendering.cbp new file mode 100644 index 0000000..a0c93b7 --- /dev/null +++ b/src/others/irrlicht-1.8.1/examples/12.TerrainRendering/TerrainRendering.cbp @@ -0,0 +1,56 @@ + + + + + + diff --git a/src/others/irrlicht-1.8.1/examples/12.TerrainRendering/TerrainRendering.dev b/src/others/irrlicht-1.8.1/examples/12.TerrainRendering/TerrainRendering.dev new file mode 100644 index 0000000..678e536 --- /dev/null +++ b/src/others/irrlicht-1.8.1/examples/12.TerrainRendering/TerrainRendering.dev @@ -0,0 +1,59 @@ +[Project] +FileName=example.dev +Name=Irrlicht Example 12 Terrain Rendering +UnitCount=1 +Type=1 +Ver=1 +ObjFiles= +Includes=..\..\include +Libs= +PrivateResource= +ResourceIncludes= +MakeIncludes= +Compiler= +CppCompiler= +Linker=../../lib/Win32-gcc/libIrrlicht.a_@@_ +IsCpp=1 +Icon= +ExeOutput=../../bin/Win32-gcc +ObjectOutput=obj +OverrideOutput=1 +OverrideOutputName=12.TerrainRendering.exe +HostApplication= +Folders= +CommandLine= +IncludeVersionInfo=0 +SupportXPThemes=0 +CompilerSet=0 +CompilerSettings=0000000000000000000000 +UseCustomMakefile=0 +CustomMakefile= + +[Unit1] +FileName=main.cpp +CompileCpp=1 +Folder=Projekt1 +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[VersionInfo] +Major=0 +Minor=1 +Release=1 +Build=1 +LanguageID=1033 +CharsetID=1252 +CompanyName= +FileVersion= +FileDescription=Irrlicht Engine example compiled using DevCpp and gcc +InternalName= +LegalCopyright= +LegalTrademarks= +OriginalFilename= +ProductName= +ProductVersion= +AutoIncBuildNr=0 + diff --git a/src/others/irrlicht-1.8.1/examples/12.TerrainRendering/TerrainRendering.vcproj b/src/others/irrlicht-1.8.1/examples/12.TerrainRendering/TerrainRendering.vcproj new file mode 100644 index 0000000..2200562 --- /dev/null +++ b/src/others/irrlicht-1.8.1/examples/12.TerrainRendering/TerrainRendering.vcproj @@ -0,0 +1,163 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/others/irrlicht-1.8.1/examples/12.TerrainRendering/TerrainRendering_vc10.vcxproj b/src/others/irrlicht-1.8.1/examples/12.TerrainRendering/TerrainRendering_vc10.vcxproj new file mode 100644 index 0000000..c68f9ff --- /dev/null +++ b/src/others/irrlicht-1.8.1/examples/12.TerrainRendering/TerrainRendering_vc10.vcxproj @@ -0,0 +1,231 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + 12.TerrainRendering + {3A5B74E5-6390-43B0-A459-2793B81FFD31} + TerrainRendering + + + + Application + false + MultiByte + + + Application + false + MultiByte + + + Application + false + MultiByte + + + Application + false + MultiByte + + + + + + + + + + + + + + + + + + + + + + + <_ProjectFileVersion>10.0.30319.1 + ..\..\bin\Win32-VisualStudio\ + ..\..\bin\Win64-VisualStudio\ + + + ..\..\bin\Win32-VisualStudio\ + ..\..\bin\Win64-VisualStudio\ + + + AllRules.ruleset + AllRules.ruleset + + + + + AllRules.ruleset + AllRules.ruleset + + + + + + + + .\Debug/TerrainRendering.tlb + + + + + Disabled + ..\..\include;%(AdditionalIncludeDirectories) + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + EnableFastChecks + MultiThreadedDebug + + + Level3 + EditAndContinue + + + _DEBUG;%(PreprocessorDefinitions) + 0x0c07 + + + ..\..\bin\Win32-VisualStudio\12.TerrainRendering.exe + ..\..\lib\Win32-visualstudio;%(AdditionalLibraryDirectories) + true + Console + + + + + + + .\Debug/TerrainRendering.tlb + + + + + Disabled + ..\..\include;%(AdditionalIncludeDirectories) + WIN32;WIN64;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + EnableFastChecks + MultiThreadedDebug + + + Level3 + ProgramDatabase + + + _DEBUG;%(PreprocessorDefinitions) + 0x0c07 + + + ..\..\bin\Win64-VisualStudio\12.TerrainRendering.exe + ..\..\lib\Win64-visualstudio;%(AdditionalLibraryDirectories) + true + Console + + + + + + + .\Release/TerrainRendering.tlb + + + + + MaxSpeed + OnlyExplicitInline + ..\..\include;%(AdditionalIncludeDirectories) + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + MultiThreaded + true + + + Level3 + + + NDEBUG;%(PreprocessorDefinitions) + 0x0c07 + + + ..\..\bin\Win32-VisualStudio\12.TerrainRendering.exe + ..\..\lib\Win32-visualstudio;%(AdditionalLibraryDirectories) + Console + + + + + + + .\Release/TerrainRendering.tlb + + + + + MaxSpeed + OnlyExplicitInline + ..\..\include;%(AdditionalIncludeDirectories) + WIN32;WIN64;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + MultiThreaded + true + + + Level3 + + + NDEBUG;%(PreprocessorDefinitions) + 0x0c07 + + + ..\..\bin\Win64-VisualStudio\12.TerrainRendering.exe + ..\..\lib\Win64-visualstudio;%(AdditionalLibraryDirectories) + Console + + + + + + + Disabled + Disabled + %(AdditionalIncludeDirectories) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(PreprocessorDefinitions) + EnableFastChecks + EnableFastChecks + MaxSpeed + MaxSpeed + %(AdditionalIncludeDirectories) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(PreprocessorDefinitions) + + + + + + \ No newline at end of file diff --git a/src/others/irrlicht-1.8.1/examples/12.TerrainRendering/TerrainRendering_vc11.vcxproj b/src/others/irrlicht-1.8.1/examples/12.TerrainRendering/TerrainRendering_vc11.vcxproj new file mode 100644 index 0000000..d91cb76 --- /dev/null +++ b/src/others/irrlicht-1.8.1/examples/12.TerrainRendering/TerrainRendering_vc11.vcxproj @@ -0,0 +1,235 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + 12.TerrainRendering + {3A5B74E5-6390-43B0-A459-2793B81FFD31} + TerrainRendering + + + + Application + false + MultiByte + v110 + + + Application + false + MultiByte + v110 + + + Application + false + MultiByte + v110 + + + Application + false + MultiByte + v110 + + + + + + + + + + + + + + + + + + + + + + + <_ProjectFileVersion>10.0.30319.1 + ..\..\bin\Win32-VisualStudio\ + ..\..\bin\Win64-VisualStudio\ + + + ..\..\bin\Win32-VisualStudio\ + ..\..\bin\Win64-VisualStudio\ + + + AllRules.ruleset + AllRules.ruleset + + + + + AllRules.ruleset + AllRules.ruleset + + + + + + + + .\Debug/TerrainRendering.tlb + + + + + Disabled + ..\..\include;%(AdditionalIncludeDirectories) + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + EnableFastChecks + MultiThreadedDebug + + + Level3 + EditAndContinue + + + _DEBUG;%(PreprocessorDefinitions) + 0x0c07 + + + ..\..\bin\Win32-VisualStudio\12.TerrainRendering.exe + ..\..\lib\Win32-visualstudio;%(AdditionalLibraryDirectories) + true + Console + + + + + + + .\Debug/TerrainRendering.tlb + + + + + Disabled + ..\..\include;%(AdditionalIncludeDirectories) + WIN32;WIN64;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + EnableFastChecks + MultiThreadedDebug + + + Level3 + ProgramDatabase + + + _DEBUG;%(PreprocessorDefinitions) + 0x0c07 + + + ..\..\bin\Win64-VisualStudio\12.TerrainRendering.exe + ..\..\lib\Win64-visualstudio;%(AdditionalLibraryDirectories) + true + Console + + + + + + + .\Release/TerrainRendering.tlb + + + + + MaxSpeed + OnlyExplicitInline + ..\..\include;%(AdditionalIncludeDirectories) + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + MultiThreaded + true + + + Level3 + + + NDEBUG;%(PreprocessorDefinitions) + 0x0c07 + + + ..\..\bin\Win32-VisualStudio\12.TerrainRendering.exe + ..\..\lib\Win32-visualstudio;%(AdditionalLibraryDirectories) + Console + + + + + + + .\Release/TerrainRendering.tlb + + + + + MaxSpeed + OnlyExplicitInline + ..\..\include;%(AdditionalIncludeDirectories) + WIN32;WIN64;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + MultiThreaded + true + + + Level3 + + + NDEBUG;%(PreprocessorDefinitions) + 0x0c07 + + + ..\..\bin\Win64-VisualStudio\12.TerrainRendering.exe + ..\..\lib\Win64-visualstudio;%(AdditionalLibraryDirectories) + Console + + + + + + + Disabled + Disabled + %(AdditionalIncludeDirectories) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(PreprocessorDefinitions) + EnableFastChecks + EnableFastChecks + MaxSpeed + MaxSpeed + %(AdditionalIncludeDirectories) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(PreprocessorDefinitions) + + + + + + \ No newline at end of file diff --git a/src/others/irrlicht-1.8.1/examples/12.TerrainRendering/TerrainRendering_vc8.vcproj b/src/others/irrlicht-1.8.1/examples/12.TerrainRendering/TerrainRendering_vc8.vcproj new file mode 100644 index 0000000..757e2f6 --- /dev/null +++ b/src/others/irrlicht-1.8.1/examples/12.TerrainRendering/TerrainRendering_vc8.vcproj @@ -0,0 +1,231 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/others/irrlicht-1.8.1/examples/12.TerrainRendering/TerrainRendering_vc9.vcproj b/src/others/irrlicht-1.8.1/examples/12.TerrainRendering/TerrainRendering_vc9.vcproj new file mode 100644 index 0000000..8a7f2f1 --- /dev/null +++ b/src/others/irrlicht-1.8.1/examples/12.TerrainRendering/TerrainRendering_vc9.vcproj @@ -0,0 +1,230 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/others/irrlicht-1.8.1/examples/12.TerrainRendering/main.cpp b/src/others/irrlicht-1.8.1/examples/12.TerrainRendering/main.cpp new file mode 100644 index 0000000..d829244 --- /dev/null +++ b/src/others/irrlicht-1.8.1/examples/12.TerrainRendering/main.cpp @@ -0,0 +1,285 @@ +/** Example 012 Terrain Rendering + +This tutorial will briefly show how to use the terrain renderer of Irrlicht. It +will also show the terrain renderer triangle selector to be able to do +collision detection with terrain. + +Note that the Terrain Renderer in Irrlicht is based on Spintz' +GeoMipMapSceneNode, lots of thanks go to him. DeusXL provided a new elegant +simple solution for building larger area on small heightmaps -> terrain +smoothing. + +In the beginning there is nothing special. We include the needed header files +and create an event listener to listen if the user presses a key: The 'W' key +switches to wireframe mode, the 'P' key to pointcloud mode, and the 'D' key +toggles between solid and detail mapped material. +*/ +#include +#include "driverChoice.h" + +using namespace irr; + +#ifdef _MSC_VER +#pragma comment(lib, "Irrlicht.lib") +#endif + + +class MyEventReceiver : public IEventReceiver +{ +public: + + MyEventReceiver(scene::ISceneNode* terrain, scene::ISceneNode* skybox, scene::ISceneNode* skydome) : + Terrain(terrain), Skybox(skybox), Skydome(skydome), showBox(true), showDebug(false) + { + Skybox->setVisible(showBox); + Skydome->setVisible(!showBox); + } + + bool OnEvent(const SEvent& event) + { + // check if user presses the key 'W' or 'D' + if (event.EventType == irr::EET_KEY_INPUT_EVENT && !event.KeyInput.PressedDown) + { + switch (event.KeyInput.Key) + { + case irr::KEY_KEY_W: // switch wire frame mode + Terrain->setMaterialFlag(video::EMF_WIREFRAME, + !Terrain->getMaterial(0).Wireframe); + Terrain->setMaterialFlag(video::EMF_POINTCLOUD, false); + return true; + case irr::KEY_KEY_P: // switch wire frame mode + Terrain->setMaterialFlag(video::EMF_POINTCLOUD, + !Terrain->getMaterial(0).PointCloud); + Terrain->setMaterialFlag(video::EMF_WIREFRAME, false); + return true; + case irr::KEY_KEY_D: // toggle detail map + Terrain->setMaterialType( + Terrain->getMaterial(0).MaterialType == video::EMT_SOLID ? + video::EMT_DETAIL_MAP : video::EMT_SOLID); + return true; + case irr::KEY_KEY_S: // toggle skies + showBox=!showBox; + Skybox->setVisible(showBox); + Skydome->setVisible(!showBox); + return true; + case irr::KEY_KEY_X: // toggle debug information + showDebug=!showDebug; + Terrain->setDebugDataVisible(showDebug?scene::EDS_BBOX_ALL:scene::EDS_OFF); + return true; + default: + break; + } + } + + return false; + } + +private: + scene::ISceneNode* Terrain; + scene::ISceneNode* Skybox; + scene::ISceneNode* Skydome; + bool showBox; + bool showDebug; +}; + + +/* +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() +{ + // ask user for driver + video::E_DRIVER_TYPE driverType=driverChoiceConsole(); + if (driverType==video::EDT_COUNT) + return 1; + + // create device with full flexibility over creation parameters + // you can add more parameters if desired, check irr::SIrrlichtCreationParameters + irr::SIrrlichtCreationParameters params; + params.DriverType=driverType; + params.WindowSize=core::dimension2d(640, 480); + 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(); + + driver->setTextureCreationFlag(video::ETCF_ALWAYS_32_BIT, true); + + // add irrlicht logo + env->addImage(driver->getTexture("../../media/irrlichtlogo2.png"), + core::position2d(10,10)); + + //set other font + env->getSkin()->setFont(env->getFont("../../media/fontlucida.png")); + + // add some help text + env->addStaticText( + L"Press 'W' to change wireframe mode\nPress 'D' to toggle detail map\nPress 'S' to toggle skybox/skydome", + core::rect(10,421,250,475), true, true, 0, -1, true); + + // add camera + scene::ICameraSceneNode* camera = + smgr->addCameraSceneNodeFPS(0,100.0f,1.2f); + + camera->setPosition(core::vector3df(2700*2,255*2,2600*2)); + camera->setTarget(core::vector3df(2397*2,343*2,2700*2)); + camera->setFarValue(42000.0f); + + // disable mouse cursor + device->getCursorControl()->setVisible(false); + + /* + Here comes the terrain renderer scene node: We add it just like any + other scene node to the scene using + ISceneManager::addTerrainSceneNode(). The only parameter we use is a + file name to the heightmap we use. A heightmap is simply a gray scale + texture. The terrain renderer loads it and creates the 3D terrain from + it. + + To make the terrain look more big, we change the scale factor of + it to (40, 4.4, 40). Because we don't have any dynamic lights in the + scene, we switch off the lighting, and we set the file + terrain-texture.jpg as texture for the terrain and detailmap3.jpg as + second texture, called detail map. At last, we set the scale values for + the texture: The first texture will be repeated only one time over the + whole terrain, and the second one (detail map) 20 times. + */ + + // add terrain scene node + scene::ITerrainSceneNode* terrain = smgr->addTerrainSceneNode( + "../../media/terrain-heightmap.bmp", + 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("../../media/terrain-texture.jpg")); + terrain->setMaterialTexture(1, + driver->getTexture("../../media/detailmap3.jpg")); + + terrain->setMaterialType(video::EMT_DETAIL_MAP); + + terrain->scaleTexture(1.0f, 20.0f); + + /* + To be able to do collision with the terrain, we create a triangle selector. + If you want to know what triangle selectors do, just take a look into the + collision tutorial. The terrain triangle selector works together with the + terrain. To demonstrate this, we create a collision response animator + and attach it to the camera, so that the camera will not be able to fly + through the terrain. + */ + + // create triangle selector for the terrain + scene::ITriangleSelector* selector + = smgr->createTerrainTriangleSelector(terrain, 0); + terrain->setTriangleSelector(selector); + + // create collision response animator and attach it to the camera + scene::ISceneNodeAnimator* anim = smgr->createCollisionResponseAnimator( + selector, camera, core::vector3df(60,100,60), + core::vector3df(0,0,0), + core::vector3df(0,50,0)); + selector->drop(); + camera->addAnimator(anim); + anim->drop(); + + /* If you need access to the terrain data you can also do this directly via the following code fragment. + */ + scene::CDynamicMeshBuffer* buffer = new scene::CDynamicMeshBuffer(video::EVT_2TCOORDS, video::EIT_16BIT); + terrain->getMeshBufferForLOD(*buffer, 0); + video::S3DVertex2TCoords* data = (video::S3DVertex2TCoords*)buffer->getVertexBuffer().getData(); + // Work on data or get the IndexBuffer with a similar call. + buffer->drop(); // When done drop the buffer again. + + /* + To make the user be able to switch between normal and wireframe mode, + we create an instance of the event receiver from above and let Irrlicht + know about it. In addition, we add the skybox which we already used in + lots of Irrlicht examples and a skydome, which is shown mutually + exclusive with the skybox by pressing 'S'. + */ + + // create skybox and skydome + driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, false); + + scene::ISceneNode* skybox=smgr->addSkyBoxSceneNode( + driver->getTexture("../../media/irrlicht2_up.jpg"), + driver->getTexture("../../media/irrlicht2_dn.jpg"), + driver->getTexture("../../media/irrlicht2_lf.jpg"), + driver->getTexture("../../media/irrlicht2_rt.jpg"), + driver->getTexture("../../media/irrlicht2_ft.jpg"), + driver->getTexture("../../media/irrlicht2_bk.jpg")); + scene::ISceneNode* skydome=smgr->addSkyDomeSceneNode(driver->getTexture("../../media/skydome.jpg"),16,8,0.95f,2.0f); + + driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, true); + + // create event receiver + MyEventReceiver receiver(terrain, skybox, skydome); + device->setEventReceiver(&receiver); + + /* + That's it, draw everything. + */ + + int lastFPS = -1; + + while(device->run()) + if (device->isWindowActive()) + { + driver->beginScene(true, true, 0 ); + + smgr->drawAll(); + env->drawAll(); + + 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 + str += " Height: "; + str += terrain->getHeight(camera->getAbsolutePosition().X, + camera->getAbsolutePosition().Z); + + device->setWindowCaption(str.c_str()); + lastFPS = fps; + } + } + + device->drop(); + + return 0; +} + +/* +Now you know how to use terrain in Irrlicht. +**/ diff --git a/src/others/irrlicht-1.8.1/examples/12.TerrainRendering/tutorial.html b/src/others/irrlicht-1.8.1/examples/12.TerrainRendering/tutorial.html new file mode 100644 index 0000000..f3d765f --- /dev/null +++ b/src/others/irrlicht-1.8.1/examples/12.TerrainRendering/tutorial.html @@ -0,0 +1,122 @@ + + +Irrlicht Engine Tutorial + + + + +
+ + + + + + + + +
+
+
Tutorial 12. Terrain Rendering
+
+
+
+

This tutorial will briefly show how to use the terrain renderer of + Irrlicht. It will also show the terrain renderer triangle selector to + be able to do collision detection with terrain.

+

The program which is described here will look like this:

+

+


+ Note that the terrain renderer in Irrlicht is based the terrain renderer + by Soconne and the GeoMipMapSceneNode developed by Spinz, lots of thanks + go to them.

+
+
+
+ + + + + + + +
Lets start!
+
+

In the beginning there is nothing special. We include the needed + header files and create an event listener to listen if the user presses + the 'W' key so we can switch to wireframe mode and if he presses 'D' + we toggle to material between solid and detail mapped.

+ + + + +
#include <irrlicht.h>
#include <iostream>
using namespace irr;

#pragma comment(lib, "Irrlicht.lib")

class MyEventReceiver : public IEventReceiver
{
public:
MyEventReceiver(scene::ISceneNode* terrain)
{
// store pointer to terrain so we can change its drawing mode
Terrain = terrain;
}

bool OnEvent(const SEvent& event)
{
// check if user presses the key 'W' or 'D'
if (event.EventType == irr::EET_KEY_INPUT_EVENT && !event.KeyInput.PressedDown)
{
switch (event.KeyInput.Key)
{
case irr::KEY_KEY_W: // switch wire frame mode
Terrain->setMaterialFlag(video::EMF_WIREFRAME, !Terrain->getMaterial(0).Wireframe);
return true;
case irr::KEY_KEY_D: // toggle detail map
Terrain->setMaterialType(
Terrain->getMaterial(0).MaterialType == video::EMT_SOLID ?
video::EMT_DETAIL_MAP : video::EMT_SOLID);
return true;
}
}
return false;
}

private:
scene::ISceneNode* Terrain;
};

+

The start of the main function starts like in most other example. + We ask the user for the desired renderer and start it up.

+ + + + +
int main()
{
// let user select driver type

video::E_DRIVER_TYPE driverType = video::EDT_DIRECT3D9;

printf("Please select the driver you want for this example:\n"\
" (a) Direct3D 9.0c\n (b) Direct3D 8.1\n (c) OpenGL 1.5\n"\
" (d) Software Renderer\n (e) Apfelbaum Software Renderer\n"\
" (f) NullDevice\n (otherKey) exit\n\n");

char i;
std::cin >> i;

switch(i)
{
case 'a': driverType = video::EDT_DIRECT3D9;break;
case 'b': driverType = video::EDT_DIRECT3D8;break;
case 'c': driverType = video::EDT_OPENGL; break;
case 'd': driverType = video::EDT_SOFTWARE; break;
case 'e': driverType = video::EDT_BURNINGSVIDEO;break;
case 'f': driverType = video::EDT_NULL; break;
default: return 1;
}

// create device
IrrlichtDevice* device = createDevice(driverType, core::dimension2d<s32>(640, 480));

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();

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

// add irrlicht logo
env->addImage(driver->getTexture("../../media/irrlichtlogoalpha.tga"),
core::position2d<s32>(10,10));
+// add some help text
gui::IGUIStaticText* text = env->addStaticText(
L"Press 'W' to change wireframe mode\nPress 'D' to toggle detail map",
core::rect<s32>(10,453,200,475), true, true, 0, -1, true);
+// add camera
scene::ICameraSceneNode* camera =
smgr->addCameraSceneNodeFPS(0,100.0f,1200.0f);
camera->setPosition(core::vector3df(1900*2,255*2,3700*2));
camera->setTarget(core::vector3df(2397*2,343*2,2700*2));
camera->setFarValue(12000.0f);

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

Here comes the terrain renderer scene node: We add it just like + any other scene node to the scene using ISceneManager::addTerrainSceneNode(). + The only parameter we use is a file name to the heightmap we use. + A heightmap is simply a gray scale texture. The terrain renderer loads + it and creates the 3D terrain from it.
+ To make the terrain look more big, we change the scale factor of it + to (40, 4.4, 40). Because we don't have any dynamic lights in the + scene, we switch off the lighting, and we set the file terrain-texture.jpg + as texture for the terrain and detailmap3.jpg as second texture, called + detail map. At last, we set the scale values for the texture: The + first texture will be repeated only one time over the whole terrain, + and the second one (detail map) 20 times.

+ + + + +
// add terrain scene node
scene::ITerrainSceneNode* terrain = smgr->addTerrainSceneNode(
"../../media/terrain-heightmap.bmp");

terrain->setScale(core::vector3df(40, 4.4f, 40));
terrain->setMaterialFlag(video::EMF_LIGHTING, false);

terrain->setMaterialTexture(0, driver->getTexture("../../media/terrain-texture.jpg"));
terrain->setMaterialTexture(1, driver->getTexture("../../media/detailmap3.jpg"));

terrain->setMaterialType(video::EMT_DETAIL_MAP);
terrain->scaleTexture(1.0f, 20.0f);
+

To be able to do collision with the terrain, we create a triangle + selector. If you want to know what triangle selectors do, just take + a look into the collision tutorial. The terrain triangle selector + works together with the terrain. To demonstrate this, we create a + collision response animator and attach it to the camera, so that the + camera will not be able to fly through the terrain.

+
+ + + + +
// create triangle selector for the terrain	
scene::ITriangleSelector* selector =
smgr->createTerrainTriangleSelector(terrain, 0);
terrain->setTriangleSelector(selector);

// create collision response animator and attach it to the camera
scene::ISceneNodeAnimator* anim = smgr->createCollisionResponseAnimator(
selector, camera, core::vector3df(60,100,60),
core::vector3df(0,0,0),
core::vector3df(0,50,0));
selector->drop();
camera->addAnimator(anim);
anim->drop();
+

To make the user be able to switch between normal and wireframe mode, + we create an instance of the event reciever from above and let Irrlicht + know about it. In addition, we add the skybox which we already used + in lots of Irrlicht examples.

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

// create skybox
driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, false);

smgr->addSkyBoxSceneNode(
driver->getTexture("../../media/irrlicht2_up.jpg"),
driver->getTexture("../../media/irrlicht2_dn.jpg"),
driver->getTexture("../../media/irrlicht2_lf.jpg"),
driver->getTexture("../../media/irrlicht2_rt.jpg"),
driver->getTexture("../../media/irrlicht2_ft.jpg"),
driver->getTexture("../../media/irrlicht2_bk.jpg"));
+driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, true);
+

That's it, draw everything. Now you know how to use terrain in Irrlicht.

+ + + + +
	int lastFPS = -1;

while(device->run())
if (device->isWindowActive())
{
driver->beginScene(true, true, 0 );

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

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;
device->setWindowCaption(str.c_str());
lastFPS = fps;
}
}

device->drop();

return 0;
}
+

 

+
+
+

 

+ + -- cgit v1.1