By mulinb
The latest project needs to simulate a simple demonstration of aircraft flight in 3D scenarios. The main function is to provide a large Terrain elevation map and an airplane flight route, which can be displayed in 3D to demonstrate aircraft flight. I feel that I have seen many similar games before. This is nothing more than a simplified version of the first game called the shooting or simulated flying games. So I decided to check the Open Source game engine from the perspective of Avoiding repeated wheel creation, see if there is a similar engine that can quickly develop a first-person shooting game. After reading some online comments and comparisons, I decided to use the 3D Graphics Rendering Engine Ogre for development.
There is a terrain demo in the Ogre demo, which is an example of generating a 3D terrain scenario from a Terrain elevation map. It uses the built-in terrainscenemanager (TSM) of ogre) the scenario manager is described in detail in "Pro ogre 3D programming". It is nothing more than how to configure a terrain. CFG configuration file for ing. For more details, see the official wiki: http://www.ogre3d.org/wiki/index.php/Terrain_Scene_Manager. Using this scenario manager to load a relatively small Terrain elevation map is still relatively effective, but when loading a relatively large Terrain elevation map, the speed is obviously slow, the waiting time for opening the program becomes long, and the frame rate also becomes low.
I checked the information about the scenario manager that supports ing on the Internet and found that the addon plug-in plsm2 (paging landscape scenemanager) of Ogre can load large Terrain elevation maps into small pages, however, there are not many online materials on how to use the scenario manager, which is difficult to use. After some painful debugging, I finally successfully used plsm2 in ogre1.6. The loading speed is much faster, but there are still some problems, when the terrain is roaming, the terrain will be deformed and depressed ...... This is for the time being todo. It is estimated that some settings are not set, or the scenario manager is still not complete. Next we will record the process of using plsm2.
Environment: Windows XP, MS Visual Studio 2005 + SP1.
//--------------------------------------------------------------------------
Official wiki about plsm2 use: http://www.ogre3d.org/wiki/index.php/Paging_Scene_Manager.
Detailed instructions on how to install and use plsm2 and how to configure the configuration file are provided. However, following these official wiki step by step does not allow the demo program to run smoothly. You need to compare the executable file to the path of the media folder according to the error message. In addition, there are two sets of media folders, one for mapsplitter and the other for plsm2 demo. Note that the configuration file is important and time-consuming. The configuration file that requires mapsplitter (used to split a ry elevation map into small blocks), you also need to configure parameters for ing small map maps to the world coordinate system in three-dimensional scenarios during runtime. For the main configuration files, refer to wiki: http://www.ogre3d.org/wiki/index.php/Paging_Scene_Manager_config_files.
For the configuration file, it should be noted that the effect of automatic texture generation is not very good. If there is no suitable texture, you may wish to use MATLAB + Photoshop to generate a pseudo-color map of the Terrain elevation map as the terrain texture, use textureformat = imagepaging to divide the texture into small pieces. From the experiment results, if the pseudo-color image is generated properly, the 3D scene effect is quite beautiful. Another point is that when the map definition parameter in terrain map specification is configured, the value of width and height is the number of the previously split small Topographic Map in two directions, for example, if the large topographic map is 16385x16385 (note that the size of the topographic map must be (2 ^ n) + 1 according to plsm2 ), if the size of a small part is pagesize = 513 (the pagesize here should also be (2 ^ n) + 1), then the size of width and height should be (16385-1) /(513-1) = 32. In addition, the scalex parameter scalez maps a small piece (A pagesize Topographic Map) to the length and width of the three-dimensional scene, instead of ing the whole large image to the length and width of the three-dimensional scene. It has been tested, when scalex = pagesize × 400, the three-dimensional terrain is relatively good, the terrain is relatively smooth, and the terrain is obviously fluctuating. Scaley is the height range mapped to a 3D scenario (0 ~ Scaley ). Many other parameters can be set according to the Wiki instructions.
When you run the demo program, you will find that the time to load the ing using the plsm2 scenario manager is significantly shorter than that of TSM, however, you will find that the problem is that when you roam in a 3D scenario, the terrain will be like a life, and when you zoom in, many mountains will grow taller, when pulling the camera far away, many mountains will shrink back ...... I have not set many parameters for this problem. Which of the following heroes wants to give some advice? However, it is certain that this effect is not too serious when the video card is good.
Okay, now we need to jump out of the demo program and use plsm2 in our own project, you will find that the compiled demo program, mapsplitter program, plsm2 DLL and Lib files downloaded from the official wiki address http://tuan.kuranes.free.fr/Ogre.html are compiled with ogre1.2, if you are using the latest ogre SDK, you may have used ogre1.6.1 like me, you can download the latest Code directly from SVN like me (preferably the same SDK version as you use) and compile a set of mapsplitter programs and plsm2 DLL and Lib files.
Then there is a question about the world coordinate system in plsm2 3D scenarios. In the world coordinate system of plsm2, the origin point (x, z) = (0, 0) (note that in the 3D world coordinate system of ogre, X and Z are the two directions of length and width, Y is the height direction) is in the middle of the scene, corresponding to the central position of the Terrain elevation map, rather than the top left corner of the Terrain elevation map. For example:
Size of a ry elevation chart: 16385x16385
Block Size (pagesize): 513
Width, height: 32
Scalex, scalez: 204800 (204800 = (513-1) × 400)
Then, the size of the plsm2 3D world coordinate system is (sizex, sizez) = 32 × 512 × 400 = (6553600,655 3600)
Then, the coordinates in the upper left corner of the plsm2 3D world coordinate system are (Minx, minz) =-6553600/2 = (-3276800,-3276800)
Fortunately, this information does not need to be calculated by yourself. The scenario manager of plsm2 has corresponding interfaces to obtain these parameters. What needs to be done in the Code is, convert the scenemanager pointer mscenemgr to the paginglandscapescenemanager pointer, and obtain these parameters using the APIS provided by paginglandscapescenemanager. Before writing code, you need to copy the header file of plsm2 to the current project. Because the files in plsm2 are referenced by each other, it is still necessary to pick out these header files. The list of header files I copied is as follows:
Ogrepaginglandscapedata2dmanager. h
Ogrepaginglandscapeocclusion. h
Ogrepaginglandscapeocclusionelement. h
Ogrepaginglandscapeocclusionqueryset. h
Ogrepaginglandscapeocclusiontraversal. h
Ogrepaginglandscapeoctree. h
Ogrepaginglandscapeoctreecamera. h
Ogrepaginglandscapeoctreenode. h
Ogrepaginglandscapeoctreescenemanager. h
Ogrepaginglandscapeoptions. h
Ogrepaginglandscapepoolset. h
Ogrepaginglandscapeprerequisites. h
Ogrepaginglandscapescenemanager. h
Then, you can use the paginglandscapescenemanager interface to obtain the unique parameters of plsm2. The code snippet is as follows:
View plaincopy to clipboardprint?
Paginglandscapescenemanager * g_pplscenemgr = NULL;
Real worldsizex, worldsizez;
G_pplscenemgr = static_cast <paginglandscapescenemanager *> (mscenemgr );
G_pplscenemgr-> getworldsize (& worldsizex, & worldsizez );
Paginglandscapeoptions * pplsm2options = g_pplscenemgr-> getoptions ();
Real xscalefactor = pplsm2options-> scale. X;
// X-direction amplification factor, scalex/(PageSize-1), here is 400
Real zscalefactor = pplsm2options-> scale. Z;
// Z-direction amplification factor, scalez/(PageSize-1), here is 400
Real Maxy = pplsm2options-> scale. Y; // The maximum height. Here is scaley.
Paginglandscapescenemanager * g_pplscenemgr = NULL;
Real worldsizex, worldsizez;
G_pplscenemgr = static_cast <paginglandscapescenemanager *> (mscenemgr );
G_pplscenemgr-> getworldsize (& worldsizex, & worldsizez );
Paginglandscapeoptions * pplsm2options = g_pplscenemgr-> getoptions ();
Real xscalefactor = pplsm2options-> scale. X;
// X-direction amplification factor, scalex/(PageSize-1), here is 400
Real zscalefactor = pplsm2options-> scale. Z;
// Z-direction amplification factor, scalez/(PageSize-1), here is 400
Real Maxy = pplsm2options-> scale. Y; // The maximum height. Here is scaley.
The variable pplsm2options in the above Code can be observed in the debugging mode. In fact, many plsm2 parameters can be observed, which is a good helper for plsm2.
There should be no other issues with the official wiki.
//--------------------------------------------------------------------------
Attached to a small program (texture generated using Matlab + Photoshop ):
Add the pseudo-color chart code generated by MATLAB (Photoshop can be used to splice and color ):
%
Clear all; close;
% Read unprocessed Terrain elevation map, height value range (0 ~ 5000), PNG is 16-bit gray (0 ~ 65535)
Dxgc_data‑imread('dxgct.png ');
% Defines the colormap used for the Paster pseudo-color display. It is a color table that has been adjusted with MATLAB in advance after manual coloring.
Dxcolor = [0 0 0.5625; 0.1 0.2 0.7813; 0.2 0.4 1; 0.3333 0.5333 1; 0.4667 0.6667 1; 0.6 0.8 1; 0.5 0.8 0.75; 0.4 0.8 0.5; 0.3 0.8 0.25; 0.2 0.8 0; 0.24 0.78 0; 0.28 0.76 0.32 0; 0.74 0.36 0; 0.72 0.4 0; 0.7 0.44 0.68 0; 0.48 0.66 0.52 0; 0.64 0.56 0.62 0; 0; 0.6 0.6 0; 0.5926 0.5852 0; 0.5852 0.5704 0.5778 0; 0.5556 0.5704 0; 0.5407 0.563 0; 0.5259 0.5556 0.5111 0; 0.5481 0.4963 0.5407 0; 0.4815 0.5333 0.4667 0; 0; 0.5259 0.4519 0; 0.5185 0.437 0; 0.5111 0.4222 0.5037 0; 0.4074 0.4963 0; 0.3926 0.4889 0; 0.3778 0.4815 0.363 0; 0.4741 0.3481 0.4667 0; 0.3333 0.4593 0.3185 0; 0; 0.4519 0.3037 0; 0.4444 0.2889 0; 0.437 0.2741 0.4296 0; 0.2593 0.4222 0.2444 0; 0.4148 0.2296 0.4074 0; 0.2148 0.4 0.2 0; 0.4 0.1882 0.01176 0.4; 0.1765 0.02353; 0.4 0.1647 0.03529; 0.4 0.1529 0.04706; 0.4 0.1412 0.05882; 0.4 0.1294 0.07059; 0.4 0.1176 0.08235; 0.4 0.1059 0.09412; 0.4 0.09412 0.1059; 0.4 0.08235 0.1176; 0.4 0.07059 0.1294; 0.4 0.05882 0.1412; 0.4 0.04706 0.1529; 0.4 0.03529 0.1647; 0.4 0.02353 0.1765; 0.4 0.01176 0.1882; 0.4 0 0.2];
% Convert an elevation chart to an index chart
Dxgct_ind = gray2ind (dxgc_data, 1000); % after practice, 1000 corresponds to 60 indexes in gray scale
% The index chart is converted to a pseudo-color chart, which can be generated in this row. However, when the topographic map is too large, the MATLAB memory is insufficient.
% Dxgct_rgb = ind2rgb (dxgct_ind, colormap (dxcolor); % use the previously adjusted colormap
% Multipart output
Dxgct_rgb0 = ind2rgb (dxgct_ind (,), colormap (dxcolor ));
Dxgct_rgb1 = ind2rgb (dxgct_ind (, 1501: 3000), colormap (dxcolor ));
Dxgct_rgb2 = ind2rgb (dxgct_ind (1501: 1500, 1:), colormap (dxcolor ));
Dxgct_rgb3 = ind2rgb (dxgct_ind (1501: 3000,:), colormap (dxcolor ));
% The output is PNG, And the MATLAB memory is insufficient.
% Imwrite (dxgct_rgb, 'dxgct_texture.png ', 'png ');
% Multipart output
Imwrite (dxgct_rgb0, 'dxgct_texture0.png ', 'png ');
Imwrite (dxgct_rgb1, 'dxgct_texture1.png ', 'png ');
Imwrite (dxgct_rgb2, 'dxgct_texture2.png ', 'png ');
Imwrite (dxgct_rgb3, 'dxgct_texture3.png ', 'png ');
<End>