有的地图不是tile的整数倍,有的地图没有WCollision文件,有的地图有centre等

有的地图没有光照图等等

比如武当的地图不是tile的整数倍,那么就需要调整tile大小,其实只需要稍微改动

源码没有经过优化的,比如不需要更改的函数参数可以全部改成const引用,提高效率的

自己去优化了,

  1. void TLBBTerrain::createTerrain()
  2. {
  3. // 生成材质, 看是否有光照图
  4. if(mHasLightMap){
  5. createLightMaterial();
  6. }else{
  7. createMaterial();
  8. }
  9. // 判断地图大小是否能被tile(32)整除,不能整除的就矫正tile大小
  10. bool isAdjustCol = false;  // 是否矫正tile的大小
  11. bool isAdjustRow = false;
  12. if(mXSize%mTileSize != 0){
  13. isAdjustCol = true;
  14. }
  15. if(mZSize%mTileSize != 0){
  16. isAdjustRow = true;
  17. }
  18. // tile的行数和列数,不管能否被整除都适用
  19. mTileCol = mXSize/mTileSize;
  20. mTileRow = mZSize/mTileSize;
  21. // WCollision
  22. createWCollision();
  23. // 地形mesh
  24. for(size_t matIndex = 0; matIndex < mMaterialNum; ++ matIndex){
  25. // 同材质的mesh按tile区域生成
  26. for(int tileIndex =0; tileIndex < mTileCol*mTileRow; ++ tileIndex){
  27. if(createTileMesh(tileIndex, matIndex, isAdjustCol, isAdjustRow)){
  28. Entity* entity = mSceneMgr->createEntity("tile"+StringConverter::toString(tileIndex + matIndex*mTileCol*mTileRow), "GridMesh" + StringConverter::toString(tileIndex + matIndex*mTileCol*mTileRow));
  29. entity->setCastShadows(false);
  30. mSceneMgr->getRootSceneNode()->createChildSceneNode(mCentre)->attachObject(entity);
  31. }
  32. }
  33. }
  34. }
view plain
  1. // 分别用mesh和ManualObject生成地形
  2. bool TLBBTerrain::createTileMesh(int tileIndex, int materialIndex, bool isAdjustCol, bool isAdjustRow)
  3. {
  4. // 方法1, ManualObject
  5. const Real width = 1;
  6. ManualObject mo("GridObject" + StringConverter::toString(tileIndex + materialIndex*mMaterialNum));
  7. mo.begin("material"+StringConverter::toString(materialIndex), RenderOperation::OT_TRIANGLE_LIST);
  8. int k = 0;
  9. bool hasMesh = false;
  10. int tileSizeX = mTileSize;
  11. int tileSizeZ = mTileSize;
  12. int tileIndex_x = tileIndex%(mXSize/mTileSize);
  13. int tileIndex_z = tileIndex/(mXSize/mTileSize);
  14. // 如果地图大小不能被tile整除,就需要矫正
  15. if(isAdjustCol && tileIndex_x == mXSize/mTileSize - 1){
  16. tileSizeX = mTileSize + mXSize%mTileSize;
  17. }
  18. if(isAdjustRow && tileIndex_z == mZSize/mTileSize - 1){
  19. tileSizeZ = mTileSize + mZSize%mTileSize;
  20. }
  21. // 地图可以被tile整除
  22. for(int j = 0; j < tileSizeX*tileSizeZ; ++ j){
  23. // 把每个tile的坐标转换成全图坐标
  24. int row = j/tileSizeX + tileIndex_z*mTileSize;
  25. int col = j%tileSizeX + tileIndex_x*mTileSize;
  26. int mapIndex = col + row*mXSize;
  27. Ogre::String str;
  28. if(mHasLightMap){
  29. str = mLightMaterialData[mapIndex];
  30. }else{
  31. str = mMaterialData[mapIndex];
  32. }
  33. if(str == "material"+StringConverter::toString(materialIndex) && mGridData[mapIndex].nFirstLayer >= 0){
  34. // 此tile含有此材质的mesh
  35. hasMesh = true;
  36. // 高度图坐标转换
  37. int heightMapIndex = mapIndex + mapIndex/mXSize;
  38. // 第一层纹理坐标
  39. Real left1 = mPixMapData[mGridData[mapIndex].nFirstLayer].left;
  40. Real right1 = mPixMapData[mGridData[mapIndex].nFirstLayer].right;
  41. Real top1 = mPixMapData[mGridData[mapIndex].nFirstLayer].top;
  42. Real bottom1 = mPixMapData[mGridData[mapIndex].nFirstLayer].bottom;
  43. Vector2 left_top_1(left1, top1);
  44. Vector2 right_top_1(right1, top1);
  45. Vector2 right_bottom_1(right1, bottom1);
  46. Vector2 left_bottom_1(left1, bottom1);
  47. // 图片翻转等操作
  48. flipPicture(mGridData[mapIndex].nFirstLayerOp, left_top_1, right_top_1, left_bottom_1, right_bottom_1, mGridData[mapIndex].IndexOrder);
  49. // 第二层纹理坐标
  50. Vector2 left_top_2 = Vector2::ZERO;
  51. Vector2 right_top_2 = Vector2::ZERO;
  52. Vector2 right_bottom_2 = Vector2::ZERO;
  53. Vector2 left_bottom_2 = Vector2::ZERO;
  54. if(mGridData[mapIndex].nSecondLayer >= 0){
  55. Real left2 = mPixMapData[mGridData[mapIndex].nSecondLayer].left;
  56. Real right2 = mPixMapData[mGridData[mapIndex].nSecondLayer].right;
  57. Real top2 = mPixMapData[mGridData[mapIndex].nSecondLayer].top;
  58. Real bottom2 = mPixMapData[mGridData[mapIndex].nSecondLayer].bottom;
  59. left_top_2 = Vector2(left2, top2);
  60. right_top_2 = Vector2(right2, top2);
  61. right_bottom_2 = Vector2(right2, bottom2);
  62. left_bottom_2 = Vector2(left2, bottom2);
  63. flipPicture(mGridData[mapIndex].nSecondLayerOp, left_top_2, right_top_2, left_bottom_2, right_bottom_2, mGridData[mapIndex].IndexOrder);
  64. }
  65. // 光照图纹理坐标
  66. Vector2 left_top_3 = Vector2::ZERO;
  67. Vector2 right_top_3 = Vector2::ZERO;
  68. Vector2 right_bottom_3 = Vector2::ZERO;
  69. Vector2 left_bottom_3 = Vector2::ZERO;
  70. if(mHasLightMap){
  71. Real left3 = (mapIndex%mXSize)/(Real)mXSize;
  72. Real right3 = left3 + 1/(Real)mXSize;
  73. Real top3 = (mapIndex/mXSize)/(Real)mZSize;
  74. Real bottom3 = top3 + 1/(Real)mZSize;
  75. left_top_3 = Vector2(left3, top3);
  76. right_top_3 = Vector2(right3, top3);
  77. right_bottom_3 = Vector2(right3, bottom3);
  78. left_bottom_3 = Vector2(left3, bottom3);
  79. }
  80. // 点0
  81. mo.position((mapIndex%mXSize)*mScaleX, mHeightMapData[heightMapIndex]*mScaleY, (mapIndex/mXSize)*mScaleZ);
  82. mo.normal(getNormalAt(mapIndex%mXSize, mapIndex/mXSize));
  83. mo.textureCoord(left_top_1);
  84. if(mGridData[mapIndex].nSecondLayer >= 0){
  85. mo.textureCoord(left_top_2);
  86. }
  87. if(mHasLightMap){
  88. mo.textureCoord(left_top_3);     // 光照图纹理坐标
  89. }
  90. // 点1
  91. mo.position((mapIndex%mXSize+width)*mScaleX, mHeightMapData[heightMapIndex+1]*mScaleY, (mapIndex/mXSize)*mScaleZ);
  92. mo.normal(getNormalAt(mapIndex%mXSize+width, mapIndex/mXSize));
  93. mo.textureCoord(right_top_1);
  94. if(mGridData[mapIndex].nSecondLayer >= 0){
  95. mo.textureCoord(right_top_2);
  96. }
  97. if(mHasLightMap){
  98. mo.textureCoord(right_top_3);   // 光照图纹理坐标
  99. }
  100. // 点2
  101. mo.position((mapIndex%mXSize+width)*mScaleX, mHeightMapData[heightMapIndex+mXSize+2]*mScaleY, (width+mapIndex/mXSize)*mScaleZ);
  102. mo.normal(getNormalAt(mapIndex%mXSize+width, mapIndex/mXSize+width));
  103. mo.textureCoord(right_bottom_1);
  104. if(mGridData[mapIndex].nSecondLayer >= 0){
  105. mo.textureCoord(right_bottom_2);
  106. }
  107. if(mHasLightMap){
  108. mo.textureCoord(right_bottom_3);  // 光照图纹理坐标
  109. }
  110. // 点3
  111. mo.position((mapIndex%mXSize)*mScaleX, mHeightMapData[heightMapIndex+mXSize+1]*mScaleY, (width+mapIndex/mXSize)*mScaleZ);
  112. mo.normal(getNormalAt(mapIndex%mXSize, mapIndex/mXSize+width));
  113. mo.textureCoord(left_bottom_1);
  114. if(mGridData[mapIndex].nSecondLayer >= 0){
  115. mo.textureCoord(left_bottom_2);
  116. }
  117. if(mHasLightMap){
  118. mo.textureCoord(left_bottom_3);   // 光照图纹理坐标
  119. }
  120. // 三角形索引顺序
  121. int offset = k * 4;
  122. if(mGridData[mapIndex].IndexOrder == 0){ // 正常顺序
  123. mo.triangle(offset+1, offset, offset+3);
  124. mo.triangle(offset+1, offset+3, offset+2);
  125. }else{
  126. mo.triangle(offset, offset+3, offset+2);
  127. mo.triangle(offset, offset+2, offset+1);
  128. }
  129. ++ k;
  130. }
  131. }
  132. mo.end();
  133. if(hasMesh){
  134. mo.convertToMesh("GridMesh" + StringConverter::toString(tileIndex + materialIndex*mTileCol*mTileRow));
  135. return true;
  136. }
  137. return false;
  138. }

如图,武当正确载入

老是看峨眉那图,都看烦了!换几个新鲜的

菜鸟学习OGRE和天龙八部之十七: 修正部分地图载入的通用性问题,附源码相关推荐

  1. android flv 编码器,Android 音视频深入 十七 FFmpeg 获取 RTMP 流保存为 flv (附源码下载)...

    Android 音视频深入 十七 FFmpeg 获取 RTMP 流保存为 flv (附源码下载) 项目地址 https://github.com/979451341/RtmpSave 这个项目主要代码 ...

  2. 菜鸟学习OGRE和天龙八部之十八: 获得档案(Archive)文件列表

    要获得档案文件的文件列表,只要获得Archive的指针,就可以调用list()函数获得文件列表 但是如何获得Archive的指针呢,先看看资源的载入过程: 先从resources.cfg文件获取资源的 ...

  3. 【深度强化学习】神经网络、爬山法优化控制倒立摆问题实战(附源码)

    需要源码请点赞关注收藏后评论区留言私信~~~ 直接优化策略 直接优化策略强化学习算法中,根据采用的是确定性策略还是随机性策略,又分为确定性策略搜索和随机性策略搜索两类.随机性策略搜索算法有策略梯度法和 ...

  4. 【ML-SVM案例学习】案例一:对鸢尾花数据进行SVM分类(附源码)

    文章目录 前言 一.完整源码分步实现 1.引入库 2.读入数据 3.编码数据 4.数据分割 5.数据SVM分类器构建 6.计算模型的准确率/精度 7.计算决策函数的结构值以及预测值 8.画图 总结 前 ...

  5. 深度强化学习之gym扫地机器人环境的搭建(持续更新算法,附源码,python实现)

    想要源码可以点赞关注收藏后评论区留下QQ邮箱 本次利用gym搭建一个扫地机器人环境,描述如下: 在一个5×5的扫地机器人环境中,有一个垃圾和一个充电桩,到达[5,4]即图标19处机器人捡到垃圾,并结束 ...

  6. 菜鸟学习OGRE和天龙八部之二: 天龙八部AXP数据格式搞定

    站位编辑,过段时间再写...因为现在有大侠写了资源提取工具,我暂时不用自己去写了哇 ---------------------------------------------------------- ...

  7. 通过自定义组件学习Vue系列(二)【时间轴】(附源码)

    需求: 用于升级日志的显示 效果图: 实现原理: 主要区域分为两块,时间区和内容区,时间区是画一个圆点和显示一个时间,内容区左边一个竖线和文字显示 然后做一下循环,将每个日期的数据显示出来 布局采用f ...

  8. 菜鸟学习OGRE和天龙八部之四: 地表贴图的实现

    地表我已经成功载入,也走了不少弯路...犯了很多低级错误...不然半天都可以搞定的事情,郁闷 天龙八部的地表算是比较难搞的了,至少我这样认为,由于自己没多少OGRE经验,不清楚地形的载入过程,于是看T ...

  9. 前海征信“好信杯”大数据算法竞赛 - HM队【附源码】 原创 2017-06-17 高铭 科赛Kesci 赛题回顾 自2006年Hinton等人提出“深度学习”概念至今,深度学习在海量数据的挖

    前海征信"好信杯"大数据算法竞赛 - H&M队[附源码] 原创 2017-06-17 高铭 科赛Kesci 赛题回顾 自2006年Hinton等人提出"深度学习& ...

最新文章

  1. PostgreSQL 10.1 手册_部分 II. SQL 语言_第 9 章 函数和操作符_9.15. JSON 函数和操作符...
  2. Java基础概念(一)
  3. Python学习笔记——文件写入和读取
  4. 机器学习基础(一)——人工神经网络与简单的感知器
  5. hashmap 判断key是否存在
  6. centos国内yum源
  7. 2013年人人校园招聘笔试题
  8. 字符串函数参数传入传出(字符串反转)
  9. 自己动手写事件总线(EventBus)
  10. Duplicate entry ‘XXX‘ for key
  11. 如何运行python代码
  12. android手机设置固定dns,安卓手机修改WiFi DNS设置的方法
  13. Crashing Balloon
  14. 在印度与软件相关的发明可不可以申请专利?
  15. TCP/IP详解卷1:第十四章 DNS 域名系统
  16. 华为交换机端口安全配置
  17. [读书笔记] 代码整洁之道(一)
  18. lougu3906 Geodetic
  19. 【产品实操】手把手教你安装 TDH8.1.0
  20. 时间与日期插件 -- laydate 使用方法(摘自官网)

热门文章

  1. 手机号3-4-4 滚动函数 滚盘抽奖
  2. @Valid效验注解使用
  3. oracle中有关listagg函数的使用
  4. aft-fuzz 小白安装 macOS
  5. 第三方支付“千万元罚单”与“紧箍咒”齐飞
  6. BSP Day 24
  7. PHP数组遍历的五种方法
  8. 【微信小程序】真机调试引用的外部字体不生效问题
  9. keytool及apksigner常用指令
  10. Mac下快速搭建PHP开发环境