OGRESceneMgrView.cpp
上传用户:xhbjoy
上传日期:2014-10-07
资源大小:38068k
文件大小:44k
源码类别:

游戏引擎

开发平台:

Visual C++

  1. // OGRESceneMgrView.cpp : COGRESceneMgrView 类的实现
  2. //
  3. #include "stdafx.h"
  4. #include "OGRESceneMgr.h"
  5. #include "OGRESceneMgrDoc.h"
  6. #include "OGRESceneMgrView.h"
  7. #include "ImportParticle.h"
  8. #include "ImportParticle2.h"
  9. #include "SetTetureDlg.h"
  10. #include "OgreString.h"
  11. #include "ExampleFrameListener.h"
  12. #include ".ogrescenemgrview.h"
  13. #include "OgreStringConverter.h"
  14. #include "tinyxml.h"
  15. //#include <stdio.h>
  16. #include "fromindextoname.h"
  17. #include "indextoparticlename.h"
  18. #include "importscenemesh.h"
  19. #include "importsceneparticle.h"
  20. #include "SkyStyleChoose.h"
  21. #include "movemeshdlg.h"
  22. #include "OISMouse.h"
  23. #include "rotatesetdlg.h"
  24. #include "SkyPlaneDlg.h"
  25. #include "SkyBoxDlg.h"
  26. #include "SkyDomeDlg.h"
  27. #include "setshadowtechnich.h"
  28. #include "scalesetdlg.h"
  29. #include "OgreInstancedGeometry.h"
  30. StringUtil strutil;
  31. SkyBoxDlg skyboxdlgv;
  32. SkyDomeDlg  skydomedlgv;
  33. SkyPlaneDlg  skyplanedlgv;
  34.  static  Root          *mRoot;
  35. static RenderWindow* mWindow;
  36. static SceneManager* mSceneMgr;
  37. static Camera* mCamera;
  38. bool btramove=false;
  39. bool bratate=false;
  40. bool bscaled=false;
  41. bool bimportworld=false;
  42.  SceneNode* ballnode;
  43.  Entity* ballent;
  44.   RaySceneQuery* rsq = 0;
  45. StringConverter *stingconverter;
  46. SkyStyleChoose  skystylechoosedlg;
  47.   bool bimportmesh=false;
  48. bool bimportscene=false;
  49.  static  SceneNode* currentnode;
  50.  static  SceneNode*  previousnode;
  51.  CString  meshfile;
  52. CPtrArray meshfileptr;
  53. CPtrArray parfileptr;
  54. CPtrArray  importmeshptr;
  55. CPtrArray  importparticleptr;
  56. MoveMeshDlg  movemeshdlg;
  57.  SceneNode* particlenode;
  58.  SceneNode* meshnode;
  59.  SceneNode*scenerootcc;
  60.  Entity* meshentity;
  61.  Entity *Particleaxesnode;
  62. char *str;
  63. CImportParticle2 ipdlg;
  64.  RotateSetDlg  rotatesetdlg;
  65. ScaleSetDlg  scalesetddlg;
  66. float scalddefw=0;
  67. float scalnowset;
  68. float scalpreset;
  69. CSetTetureDlg settexturedlg;
  70. //CImportParticle2 *IMPORTPARTICLE;
  71. CString particlename;
  72.  static int meshnumber=0;
  73.  static int  particlenumber=0;
  74. static int scenenumber=0;
  75. int scenemeshimportci=0;
  76. int  scenepartci=0;
  77. bool bsetskyplane=false;
  78. bool bsetskybox=false;
  79. bool bsetskydome=false;
  80. bool bsetskyall=false;
  81. bool bsetshadowtech=false;
  82.   Plane skyplane;
  83.    float rcolommm,gcolommm,bcolommm;
  84.    bool bsetfog=false;
  85.    SetShadowTechnich setshadowtecdlg;
  86.     static int mbrnum=0;
  87. SceneNode *axesXYZ;
  88. SceneNode *axesX;
  89. SceneNode *axesY;
  90. SceneNode *axesZ;
  91. SceneNode *axesarrayX;
  92. SceneNode *axesdownX;
  93. SceneNode *axesarrayY;
  94. SceneNode *axesdownY;
  95. SceneNode *axesarrayZ;
  96. SceneNode *axesdownZ;
  97. CString  worldgemotry;
  98. //SceneNode *particleaxesnode;
  99. Vector3 axesshow;
  100. bool bmovecurent=true;
  101. static bool bgetmovenode=true;
  102. SceneNode *movenodeccc;
  103. Entity *axecolor;
  104.  Entity *eneaxesarrayX;
  105.  Entity *eneaxesarrayY;
  106.  Entity *eneaxesarrayZ;
  107.  Entity *ent;
  108.  SceneNode *MOVENODE;
  109.   bool wejwjw=true;
  110.  Vector3 prexxxnode;
  111.  Vector3 nowxxxnode;
  112.  Vector3 changexxx;
  113.  Vector3 endnodexxx;
  114.  Vector3 statnodex;
  115. float movebuchang;
  116. bool bmrsX=false;
  117. bool bmrsY=false;
  118. bool bmrsZ=false;
  119. bool XYZscale=true;
  120. float forward=1;
  121. float rorateangle;
  122. bool bAxesXYZ=true;
  123. // OIS::MouseListener  moulis;
  124. // Event handler to add ability to alter curvature
  125. class TerrainFrameListener : public ExampleFrameListener
  126. {
  127. public:
  128. SceneManager* mSceneMgr;
  129. RenderWindow* win;
  130. public:
  131.     TerrainFrameListener(RenderWindow* win, Camera* cam,SceneManager* mSceneMgr)
  132.         : ExampleFrameListener(win, cam)
  133. {this->mSceneMgr=mSceneMgr;
  134. this->win=win;
  135.     }
  136.     bool frameStarted(const FrameEvent& evt)
  137.     {
  138.         if( ExampleFrameListener::frameStarted(evt) == false )
  139. return false;
  140. if(bsetskyall){
  141. if(bsetskyplane){
  142. skyplane.d =skyplanedlgv.skyplaneheigh;
  143.  skyplane.normal = -Vector3::UNIT_Y;
  144. CString skyplanema;
  145. skyplanema=skyplanedlgv.skyplanemarterial;
  146. if(skyplane.d==0) skyplane.d=5000;
  147. mSceneMgr->setSkyPlane(true, skyplane,skyplanema.GetBuffer(skyplanema.GetLength()),skyplanedlgv.skyplanedd,3);
  148. }
  149. else
  150. if(bsetskybox){
  151. CString skybmaterial;
  152. skybmaterial=skyboxdlgv.skyboxmater;
  153. mSceneMgr->setSkyBox(true,skybmaterial.GetBuffer(skybmaterial.GetLength()), 5000);
  154. }
  155. else
  156. if(bsetskydome){
  157. CString skdomemate;
  158. skdomemate=skydomedlgv.skydomemater;
  159. mSceneMgr->setSkyDome(true,skdomemate.GetBuffer(skdomemate.GetLength()));
  160. }
  161. bsetskyall=false;
  162. }
  163.       
  164. if(bsetfog){
  165.  ColourValue fadeColour(rcolommm/255,gcolommm/255,bcolommm/255);
  166.         mSceneMgr->setFog(  FOG_EXP2, fadeColour, .001, 500, 1000);
  167.         win->getViewport(0)->setBackgroundColour(fadeColour);
  168. bsetfog=false;
  169. bsetfog=false;
  170. }
  171. if(bsetshadowtech){
  172. if(setshadowtecdlg.shadowtecenshu==0)
  173. mSceneMgr->setShadowTechnique(SHADOWTYPE_NONE);
  174. else  
  175. if(setshadowtecdlg.shadowtecenshu==1)
  176. mSceneMgr->setShadowTechnique(SHADOWDETAILTYPE_ADDITIVE);
  177. else  
  178. if(setshadowtecdlg.shadowtecenshu==2)
  179. mSceneMgr->setShadowTechnique(SHADOWDETAILTYPE_MODULATIVE);
  180. else  
  181. if(setshadowtecdlg.shadowtecenshu==3)
  182. mSceneMgr->setShadowTechnique(SHADOWDETAILTYPE_INTEGRATED);
  183. else  
  184. if(setshadowtecdlg.shadowtecenshu==4)
  185. mSceneMgr->setShadowTechnique(SHADOWDETAILTYPE_STENCIL);
  186. else  
  187. if(setshadowtecdlg.shadowtecenshu==5)
  188. mSceneMgr->setShadowTechnique(SHADOWDETAILTYPE_TEXTURE);
  189. else  
  190. if(setshadowtecdlg.shadowtecenshu==6)
  191. mSceneMgr->setShadowTechnique(SHADOWTYPE_STENCIL_MODULATIVE);
  192. else  
  193. if(setshadowtecdlg.shadowtecenshu==7)
  194. mSceneMgr->setShadowTechnique(SHADOWTYPE_STENCIL_ADDITIVE);
  195. else  
  196. if(setshadowtecdlg.shadowtecenshu==8)
  197. mSceneMgr->setShadowTechnique(SHADOWTYPE_TEXTURE_MODULATIVE);
  198. else  
  199. if(setshadowtecdlg.shadowtecenshu==9)
  200. mSceneMgr->setShadowTechnique(SHADOWTYPE_TEXTURE_ADDITIVE);
  201. else  
  202. if(setshadowtecdlg.shadowtecenshu==10)
  203. mSceneMgr->setShadowTechnique(SHADOWTYPE_TEXTURE_ADDITIVE_INTEGRATED);
  204. else  
  205. if(setshadowtecdlg.shadowtecenshu==11)
  206. mSceneMgr->setShadowTechnique(SHADOWTYPE_TEXTURE_MODULATIVE_INTEGRATED);
  207. bsetshadowtech=false;
  208. }
  209. if(mKeyboard->isKeyDown(OIS::KC_X)){
  210. if(bAxesXYZ)
  211. {bmrsX=true;
  212.            bmrsY=false;
  213.           bmrsZ=false;
  214.   XYZscale=false;}}
  215. if(mKeyboard->isKeyDown(OIS::KC_Y)){
  216. if(bAxesXYZ){
  217. bmrsX=false;
  218.            bmrsY=true;
  219.           bmrsZ=false;
  220.   XYZscale=false;
  221.   bAxesXYZ=false;       }
  222.          }
  223. if(mKeyboard->isKeyDown(OIS::KC_Z)){
  224. if(bAxesXYZ){
  225.    bmrsX=false;
  226.            bmrsY=false;
  227.           bmrsZ=true;
  228.   XYZscale=false;
  229.  bAxesXYZ=false; }}
  230. if(mKeyboard->isKeyDown(OIS::KC_F4)){
  231. if(bAxesXYZ){
  232.    bmrsX=false;
  233.            bmrsY=false;
  234.           bmrsZ=false;
  235.   XYZscale=true;
  236.  bAxesXYZ=false; }}
  237. if(mKeyboard->isKeyDown(OIS::KC_UP)){forward=1;}
  238. if(mKeyboard->isKeyDown(OIS::KC_DOWN)){forward=-1;}
  239. return true;
  240.     }
  241.  bool frameEnded(const FrameEvent& evt)
  242.  {
  243.  
  244.   if(ExampleFrameListener::frameEnded(evt)==false)
  245.   return false;
  246.    
  247.  rsq->setRay(mCamera->getCameraToViewportRay(0.5, 0.5));
  248.  rsq->setSortByDistance(true);
  249.  
  250.   RaySceneQueryResult& rsqResult = rsq->execute();
  251.         RaySceneQueryResult::iterator ri = rsqResult.begin();
  252.         if (ri != rsqResult.end())
  253.         {
  254.             RaySceneQueryResultEntry& res = *ri;
  255. if(mMouse->getMouseState().buttonDown(OIS::MB_Left)){
  256. previousnode=currentnode;
  257. currentnode=ri->movable->getParentSceneNode();
  258. if(currentnode==axesarrayX||currentnode==axesarrayY||currentnode==axesarrayZ)
  259. {
  260.  eneaxesarrayX->setMaterialName("Examples/DarkMaterial");
  261.   eneaxesarrayY->setMaterialName("Examples/DarkMaterial");
  262.    eneaxesarrayZ->setMaterialName("Examples/DarkMaterial");
  263. axecolor=(Entity *)(currentnode->getAttachedObject(0));
  264. axecolor->setMaterialName("Examples/EnvMappedRustySteel");
  265. }
  266. else
  267. { previousnode->showBoundingBox(false);
  268.   currentnode->showBoundingBox(true);
  269.   axecolor->setMaterialName("Examples/DarkMaterial");
  270. }
  271. }
  272.             ballnode->setPosition(rsq->getRay().getPoint(res.distance));
  273. if(mKeyboard->isKeyDown(OIS::KC_F1)){
  274.  ballnode->setScale(0.01,0.01,0.01);}
  275. if(mKeyboard->isKeyDown(OIS::KC_F2)){
  276.  ballnode->setScale(0.1,0.1,0.1);}
  277. if(bimportmesh){
  278. if(mMouse->getMouseState().buttonDown(OIS::MB_Left)){
  279. meshnumber++;
  280. String str2;
  281. str2=str;
  282. meshentity=mSceneMgr->createEntity("MESH"+stingconverter->toString(meshnumber),str2);
  283. meshnode=mSceneMgr->getRootSceneNode()->createChildSceneNode("MESHNODE"+stingconverter->toString(meshnumber));
  284. meshnode->setPosition(rsq->getRay().getPoint(res.distance));
  285. meshnode->attachObject(meshentity);
  286. FromIndexToName *frtona= new FromIndexToName(meshnumber,str,meshfile);
  287. meshfileptr.Add(frtona);
  288. bimportmesh=false;
  289. }
  290. }
  291. if(ipdlg.bimportpaticle)
  292. {
  293. if(mMouse->getMouseState().buttonDown(OIS::MB_Left))
  294. {
  295. particlenumber++;
  296. static String str3;
  297. str3=ipdlg.particlenamechar;
  298. Particleaxesnode=mSceneMgr->createEntity("AXESDEJI"+stingconverter->toString(particlenumber),"axes.mesh");
  299. particlenode=mSceneMgr->getRootSceneNode()->createChildSceneNode("PARTICLENODE"+stingconverter->toString(particlenumber));
  300. particlenode->setPosition(rsq->getRay().getPoint(res.distance));
  301. particlenode->attachObject(mSceneMgr->createParticleSystem("PARTICLE"+stingconverter->toString(particlenumber),str3 ));
  302. particlenode->attachObject(Particleaxesnode);
  303. IndexToParticleName *indextoparticle=new IndexToParticleName(ipdlg.importpa);
  304. parfileptr.Add(indextoparticle);
  305. ipdlg.bimportpaticle=false;
  306. }
  307. }
  308. if(bimportscene)
  309. {
  310. if(mMouse->getMouseState().buttonDown(OIS::MB_Left))
  311. {
  312. scenenumber++;
  313. scenerootcc=mSceneMgr->getRootSceneNode()->createChildSceneNode("SCENEIMORTNODE"+stingconverter->toString(scenenumber));
  314. scenerootcc->setPosition(rsq->getRay().getPoint(res.distance));
  315. Vector3 ssss=rsq->getRay().getPoint(res.distance);
  316. for(static int ccc=0;ccc<importmeshptr.GetSize();ccc++){
  317. meshnumber++;
  318. CString  meshfilefff;
  319. meshfilefff=((ImportSceneMesh*)importmeshptr.GetAt(ccc))->meshfilenameddd;
  320. String meshfileggg=meshfilefff.GetBuffer(meshfilefff.GetLength());
  321. meshentity=mSceneMgr->createEntity("MESH"+stingconverter->toString(meshnumber),meshfileggg);
  322. meshnode=scenerootcc->createChildSceneNode("MESHNODE"+stingconverter->toString(meshnumber));
  323. meshnode->attachObject(meshentity);
  324. meshnode->translate(((ImportSceneMesh*)importmeshptr.GetAt(ccc))->pxddd,((ImportSceneMesh*)importmeshptr.GetAt(ccc))->pyddd,((ImportSceneMesh*)importmeshptr.GetAt(ccc))->pzddd);
  325. Real jiaopitch=((ImportSceneMesh*)importmeshptr.GetAt(ccc))->pitchddd;
  326. Radian radipitch(jiaopitch);
  327. meshnode->pitch(radipitch);
  328. Real jiaoroll=((ImportSceneMesh*)importmeshptr.GetAt(ccc))->pitchddd;
  329. Radian radiroll(jiaoroll);
  330. meshnode->roll(radiroll);
  331. Real jiaoyaw=((ImportSceneMesh*)importmeshptr.GetAt(ccc))->yawddd;
  332. Radian radiyaw(jiaoyaw);
  333. meshnode->yaw(radiyaw);
  334. meshnode->scale(((ImportSceneMesh*)importmeshptr.GetAt(ccc))->scalex,((ImportSceneMesh*)importmeshptr.GetAt(ccc))->scaley,((ImportSceneMesh*)importmeshptr.GetAt(ccc))->scalez);
  335. FromIndexToName *frtona= new FromIndexToName(1,"",meshfilefff);
  336. meshfileptr.Add(frtona);
  337. }
  338. for(static int eee=0;eee<importparticleptr.GetSize();eee++)
  339. {
  340. particlenumber++;
  341. CString  parfilefff;
  342. Particleaxesnode=mSceneMgr->createEntity("AXESDEJI"+stingconverter->toString(particlenumber),"axes.mesh");
  343. parfilefff=((ImportSceneParticle*)importparticleptr.GetAt(eee))->particlefilenameddd;
  344. String particlefileggg=parfilefff.GetBuffer(parfilefff.GetLength());
  345. particlenode=scenerootcc->createChildSceneNode("PARTICLENODE"+stingconverter->toString(particlenumber));
  346. particlenode->attachObject(mSceneMgr->createParticleSystem("PARTICLE"+stingconverter->toString(particlenumber),particlefileggg));
  347. particlenode->attachObject(Particleaxesnode);
  348. particlenode->translate(((ImportSceneParticle*)importparticleptr.GetAt(eee))->pxddd,((ImportSceneMesh*)importmeshptr.GetAt(eee))->pyddd,((ImportSceneMesh*)importmeshptr.GetAt(eee))->pzddd);
  349. Real jiaopitch=((ImportSceneParticle*)importparticleptr.GetAt(eee))->pitchddd;
  350. Radian radipitch(jiaopitch);
  351. particlenode->pitch(radipitch);
  352. Real jiaoroll=((ImportSceneParticle*)importparticleptr.GetAt(eee))->rollddd;
  353. Radian radiroll(jiaoroll);
  354. particlenode->roll(radiroll);
  355. Real jiaoyaw=((ImportSceneParticle*)importparticleptr.GetAt(eee))->yawddd;
  356. Radian radiyaw(jiaoyaw);
  357. particlenode->yaw(radiyaw);
  358. particlenode->scale(((ImportSceneParticle*)importparticleptr.GetAt(eee))->scalex,((ImportSceneParticle*)importparticleptr.GetAt(eee))->scaley,((ImportSceneParticle*)importparticleptr.GetAt(eee))->scalez);
  359. // particlenode->showBoundingBox(true);
  360. IndexToParticleName *indextoparticle=new IndexToParticleName(parfilefff);
  361. parfileptr.Add(indextoparticle);
  362. }
  363. bimportscene=false;
  364. }
  365. }
  366. if(settexturedlg.getbimporttexture()){
  367. static String stringtru;
  368. stringtru=settexturedlg.texturename;
  369. mSceneMgr->getEntity(currentnode->getAttachedObject(0)->getName())->setMaterialName(stringtru);
  370. settexturedlg.setbolfase();
  371. }
  372. if(bimportworld){
  373. char *worldg;
  374. worldg=worldgemotry.GetBuffer(worldgemotry.GetLength());
  375.  std::string terrain_cfg(worldg);
  376.         mSceneMgr -> setWorldGeometry( terrain_cfg );
  377. bimportworld=false;
  378. }
  379. if(btramove){
  380.          
  381.  
  382.  if(mKeyboard->isKeyDown(OIS::KC_X))
  383.  movenodeccc->translate(forward,0,0, Node::TransformSpace::TS_WORLD);
  384.  else
  385. if(mKeyboard->isKeyDown(OIS::KC_Y))
  386.  movenodeccc->translate(0,forward,0, Node::TransformSpace::TS_WORLD);
  387. else
  388.  
  389.  if(mKeyboard->isKeyDown(OIS::KC_Z))
  390.  movenodeccc->translate(0,0,forward, Node::TransformSpace::TS_WORLD);
  391.  
  392. }
  393. if(bratate){
  394.  if(mKeyboard->isKeyDown(OIS::KC_X))
  395.  movenodeccc->pitch(Degree(forward),Node::TransformSpace::TS_WORLD);      
  396. else
  397.  if(mKeyboard->isKeyDown(OIS::KC_Y))
  398.  movenodeccc->yaw(Degree(forward),Node::TransformSpace::TS_WORLD);
  399. else
  400. if(mKeyboard->isKeyDown(OIS::KC_Z))
  401.  movenodeccc->roll(Degree(forward),Node::TransformSpace::TS_WORLD);
  402. }
  403. if(bscaled){
  404. /*  if(forward==1) scalnowset*=scalddefw;
  405.  else scalnowset/=scalddefw;*/
  406. if(bmrsX)
  407.  {
  408.  if(mKeyboard->isKeyDown(OIS::KC_X)){
  409. // if(forward==-1) scalddefw
  410.  movenodeccc->scale(scalddefw,1,1);
  411.                              }
  412.      }else
  413.  if(bmrsY)
  414.  { if(mKeyboard->isKeyDown(OIS::KC_Y))
  415.   movenodeccc->scale(1,scalddefw,1);
  416. // Vector3 wordscale=movenodeccc->getScale();
  417. //  float scaljgwe;
  418. // if(forward==-1) scalnowset=1/scalnowset;
  419. //scaljgwe= scalnowset*(wordscale.x);
  420. // else scaljgwe= 1/(scaljgwe= scalnowset*(wordscale.x));
  421. // movenodeccc->scale(wordscale.x,scalnowset*(wordscale.y),wordscale.z);}
  422.  }else
  423.  if(bmrsZ)
  424.  { if(mKeyboard->isKeyDown(OIS::KC_Z))
  425.  movenodeccc->scale(1,1,scalddefw);
  426. // Vector3 wordscale=movenodeccc->getScale();
  427. //  if(forward==-1) scalnowset=1/scalnowset;
  428. // movenodeccc->scale(wordscale.x,wordscale.y,scalnowset*(wordscale.z));}
  429.  }else
  430.  if(XYZscale){
  431.  if(mKeyboard->isKeyDown(OIS::KC_F4))
  432.   movenodeccc->scale(scalddefw,scalddefw,scalddefw);
  433. // Vector3 wordscale=movenodeccc->getScale();
  434. //  if(forward==-1) scalnowset=1/scalnowset;
  435. // movenodeccc->scale(scalnowset*(wordscale.x),scalnowset*(wordscale.y),scalnowset*(wordscale.z));}
  436.  }
  437. // scalpreset=scalnowset;
  438. }
  439.  }
  440.  return true;
  441. }
  442. };
  443. using namespace Ogre;
  444. #ifdef _DEBUG
  445. #define new DEBUG_NEW
  446. #endif
  447. // COGRESceneMgrView
  448. IMPLEMENT_DYNCREATE(COGRESceneMgrView, CView)
  449. BEGIN_MESSAGE_MAP(COGRESceneMgrView, CView)
  450. // 标准打印命令
  451. ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
  452. ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
  453. ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
  454. ON_COMMAND(ID_32785, OnImportMesh)
  455. ON_COMMAND(ID_Menu32786, OnImportParticle)
  456. ON_COMMAND(ID_32787, OnImportScene)
  457. ON_COMMAND(ID_32792, OnSetTexture)
  458. ON_BN_CLICKED(IDC_BUTTON1, OnBnClickedImportParticle)
  459. ON_COMMAND(ID_FILE_SAVE, OnFileSave)
  460. ON_COMMAND(ID_32800, OnSetSky)
  461. ON_COMMAND(ID_32802, OnSetFogMenu)
  462. ON_COMMAND(ID_32803, OnSetShadowMenu)
  463. ON_COMMAND(ID_32796, OnTranslateMove)
  464. ON_COMMAND(ID_32798, OnTotateSce)
  465. ON_COMMAND(ID_32797, OnScaleScene)
  466. ON_COMMAND(ID_32795, OnDeleteSCENEMeshpa)
  467. ON_COMMAND(ID_32808, OnImportWorldGemotry)
  468. END_MESSAGE_MAP()
  469. // COGRESceneMgrView 构造/析构
  470.   
  471. /*  CEGUI::OgreCEGUIRenderer* mGUIRenderer;
  472.     CEGUI::System* mGUISystem;
  473. */
  474.  TerrainFrameListener* mFrameListener;
  475. COGRESceneMgrView::COGRESceneMgrView()
  476. {
  477. // TODO: 在此处添加构造代码
  478. mRoot=0;
  479. }
  480.     
  481. COGRESceneMgrView::~COGRESceneMgrView()
  482. {
  483. delete rsq;
  484. delete mRoot;
  485. }
  486.  
  487. BOOL COGRESceneMgrView::PreCreateWindow(CREATESTRUCT& cs)
  488. {
  489. // TODO: 在此处通过修改 CREATESTRUCT cs 来修改窗口类或
  490. // 样式
  491. return CView::PreCreateWindow(cs);
  492. }
  493. // COGRESceneMgrView 绘制
  494. void COGRESceneMgrView::OnDraw(CDC* /*pDC*/)
  495. {
  496. COGRESceneMgrDoc* pDoc = GetDocument();
  497. ASSERT_VALID(pDoc);
  498. if (!pDoc)
  499. return;
  500. // TODO: 在此处为本机数据添加绘制代码
  501. static bool once = true;
  502. // TODO: 在此处为本机数据添加绘制代码
  503. if(once)
  504. {
  505. once=false;
  506. //mRoot =((COGRESceneMgrApp*)AfxGetApp())->GetOgreRoot();
  507. mRoot= new Root();
  508.   ConfigFile cf;
  509.         cf.load("resources.cfg");
  510.         // Go through all sections & settings in the file
  511.         ConfigFile::SectionIterator seci = cf.getSectionIterator();
  512.         String secName, typeName, archName;
  513.         while (seci.hasMoreElements())
  514.         {
  515.             secName = seci.peekNextKey();
  516.             ConfigFile::SettingsMultiMap *settings = seci.getNext();
  517.             ConfigFile::SettingsMultiMap::iterator i;
  518.             for (i = settings->begin(); i != settings->end(); ++i)
  519.             {
  520.                 typeName = i->first;
  521.                 archName = i->second;
  522.                 ResourceGroupManager::getSingleton().addResourceLocation(
  523.                     archName, typeName, secName);
  524.             }
  525. }
  526. RenderSystemList* rl = Root::getSingleton().getAvailableRenderers();
  527. //D3D9RenderSystem 
  528. D3D9RenderSystem* rsys = NULL;
  529. RenderSystemList::iterator it = rl->begin();
  530. while( it != rl->end() )
  531.  Ogre::String rName = (*it)->getName();
  532.   if (rName == "Direct3D9 Rendering Subsystem")
  533.    break;
  534. it++;
  535. }
  536. rsys=(D3D9RenderSystem*)(&it);
  537. //mRoot->setRenderSystem( rsys ); 
  538.  if(mRoot->showConfigDialog())
  539.         {
  540.             // If returned true, user clicked OK so initialise
  541.             // Here we choose to let the system create a default rendering window by passing 'true'
  542.         mWindow = mRoot->initialise(true);
  543. }
  544.  mSceneMgr = mRoot->createSceneManager("TerrainSceneManager");
  545. // Create the camera
  546.         mCamera = mSceneMgr->createCamera("PlayerCam");
  547.         // Position it at 500 in Z direction
  548.         mCamera->setPosition(Vector3(0,0,500));
  549.         // Look back along -Z
  550.         mCamera->lookAt(Vector3(0,0,-300));
  551.         mCamera->setNearClipDistance(5);
  552. //mCamera->setFarClipDistance( 1000 );
  553. // Create one viewport, entire window
  554.         Viewport* vp = mWindow->addViewport(mCamera);
  555.         vp->setBackgroundColour(ColourValue(0,0,0));
  556.         // Alter the camera aspect ratio to match the viewport
  557.         mCamera->setAspectRatio(
  558.             Real(vp->getActualWidth()) / Real(vp->getActualHeight()));
  559.  TextureManager::getSingleton().setDefaultNumMipmaps(5);
  560. ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
  561. mCamera->setQueryFlags(0);
  562. //createScene();
  563. mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
  564.         // Create a point light
  565.         Light* l = mSceneMgr->createLight("MainLight");
  566.         // Accept default settings: point light, white diffuse, just set position
  567.         // NB I could attach the light to a SceneNode if I wanted it to move automatically with
  568.         //  other objects, but I don't
  569.         l->setPosition(20,80,50);
  570.  Entity* targetEnt = mSceneMgr->createEntity("testray", "sphere.mesh");
  571.         MaterialPtr mat = MaterialManager::getSingleton().create("targeter", 
  572.             ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
  573.         Pass* pass = mat->getTechnique(0)->getPass(0);
  574.         TextureUnitState* tex = pass->createTextureUnitState();
  575.         tex->setColourOperationEx(LBX_SOURCE1, LBS_MANUAL, LBS_CURRENT, 
  576.             ColourValue::Red);
  577.         pass->setLightingEnabled(false);
  578.         pass->setSceneBlending(SBT_ADD);
  579.         pass->setDepthWriteEnabled(false);
  580.         targetEnt->setMaterialName("targeter");
  581.         targetEnt->setCastShadows(false);
  582.         targetEnt->setQueryFlags(0);
  583.     ent = mSceneMgr->createEntity("head", "axes.mesh");
  584. ballent=mSceneMgr->createEntity("ball",mSceneMgr->PT_SPHERE);
  585. //ballent->setMaterialName("Examples/TextureEffect1");
  586. //ballent->setCastShadows(false);
  587. ballent->setQueryFlags(0);
  588.         // Set material loaded from Example.material
  589.  //   ent->setMaterialName("Examples/EnvMappedRustySteel");
  590.   //  ent->setMaterialName("Examples/EveningSkyBox");
  591.         // Add entity to the root scene node
  592.      
  593. SceneNode *nodehead=mSceneMgr->getRootSceneNode()->createChildSceneNode();
  594. nodehead->attachObject(ent);
  595. currentnode=nodehead;
  596. // nodehead->setScale(10,10,10);
  597. ballnode=mSceneMgr->getRootSceneNode()->createChildSceneNode("ballnodef");
  598. ballnode->attachObject(targetEnt);
  599. ballnode->setScale(0.1,0.1,0.1);
  600.         rsq = mSceneMgr->createRayQuery(Ray(mCamera->getPosition(), mCamera->getDirection()));
  601.         rsq->setSortByDistance(true, 1);
  602.      // rsq->setWorldFragmentType(SceneQuery::WFT_SINGLE_INTERSECTION);
  603. Plane plane;
  604. plane.normal = Vector3::UNIT_Y;
  605. plane.d = 100;
  606. MeshManager::getSingleton().createPlane("Myplane",
  607. ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane,
  608. 1500,1500,20,20,true,1,60,60,Vector3::UNIT_Z);
  609. Entity* pPlaneEnt = mSceneMgr->createEntity( "plane", "Myplane" );
  610. axecolor=pPlaneEnt;
  611. pPlaneEnt->setMaterialName("Examples/Rockwall");
  612. //pPlaneEnt->setCastShadows(false);
  613. mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(0,99,0))->attachObject(pPlaneEnt);
  614.  eneaxesarrayX = mSceneMgr->createEntity("ENTAXESARRAYX", "Pine1.mesh");
  615.  //eneaxesarrayX->setQueryFlags(0);
  616.  Entity *entaxesdownX=mSceneMgr->createEntity("ENTAXESDOWNX","pilon.mesh");
  617.  entaxesdownX->setQueryFlags(0);
  618.  eneaxesarrayX->setMaterialName("Examples/DarkMaterial");
  619. eneaxesarrayY = mSceneMgr->createEntity("ENTAXESARRAYY", "Pine1.mesh");
  620.  Entity *entaxesdownY =mSceneMgr->createEntity("ENTAXESDOWNY","pilon.mesh");
  621.   eneaxesarrayY->setMaterialName("Examples/DarkMaterial");
  622.  entaxesdownY->setQueryFlags(0);
  623.  
  624. eneaxesarrayZ = mSceneMgr->createEntity("ENTAXESARRAYZ", "Pine1.mesh");
  625.   eneaxesarrayZ->setMaterialName("Examples/DarkMaterial");
  626.  Entity *entaxesdownZ =mSceneMgr->createEntity("ENTAXESDOWNZ","pilon.mesh");
  627.  entaxesdownZ->setQueryFlags(0);
  628. axesXYZ=mSceneMgr->getRootSceneNode()->createChildSceneNode("AXESXYZ");
  629. axesX=axesXYZ->createChildSceneNode("AXESX");
  630. axesY=axesXYZ->createChildSceneNode("AXESY");
  631. axesZ=axesXYZ->createChildSceneNode("AXESZ");
  632. axesarrayX=axesX->createChildSceneNode("AXESARRAYX");
  633. axesarrayX->attachObject(eneaxesarrayX);
  634. axesarrayX->translate(0,45,0);
  635. axesdownX=axesX->createChildSceneNode("AXESDOWNX");
  636. axesdownX->attachObject(entaxesdownX);
  637. axesdownX->scale(0.01,0.09,0.01);
  638. axesX->roll(Degree(270));
  639. axesarrayY=axesY->createChildSceneNode("AXESARRAYY");
  640. axesarrayY->attachObject(eneaxesarrayY);
  641. axesarrayY->translate(0,45,0);
  642. axesdownY=axesY->createChildSceneNode("AXESDOWNY");
  643. axesdownY->attachObject(entaxesdownY);
  644. axesdownY->scale(0.01,0.09,0.01);
  645. axesarrayZ=axesZ->createChildSceneNode("AXESARRAYZ");
  646. axesarrayZ->attachObject(eneaxesarrayZ);
  647. axesarrayZ->translate(0,45,0);
  648. axesdownZ=axesZ->createChildSceneNode("AXESDOWNZ");
  649. axesdownZ->attachObject(entaxesdownZ);
  650. axesdownZ->scale(0.01,0.09,0.01);
  651. axesZ->pitch(Degree(90));
  652.  mFrameListener= new TerrainFrameListener(mWindow, mCamera,mSceneMgr);
  653.         mFrameListener->showDebugOverlay(true);
  654.         mRoot->addFrameListener(mFrameListener);
  655.   mRoot->startRendering();
  656. }
  657. }
  658. // COGRESceneMgrView 打印
  659. BOOL COGRESceneMgrView::OnPreparePrinting(CPrintInfo* pInfo)
  660. {
  661. // 默认准备
  662. return DoPreparePrinting(pInfo);
  663. }
  664. void COGRESceneMgrView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  665. {
  666. // TODO: 打印前添加额外的初始化
  667. }
  668. void COGRESceneMgrView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  669. {
  670. // TODO: 打印后添加清除过程
  671. }
  672. // COGRESceneMgrView 诊断
  673. #ifdef _DEBUG
  674. void COGRESceneMgrView::AssertValid() const
  675. {
  676. CView::AssertValid();
  677. }
  678. void COGRESceneMgrView::Dump(CDumpContext& dc) const
  679. {
  680. CView::Dump(dc);
  681. }
  682. COGRESceneMgrDoc* COGRESceneMgrView::GetDocument() const // 非调试版本是内联的
  683. {
  684. ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(COGRESceneMgrDoc)));
  685. return (COGRESceneMgrDoc*)m_pDocument;
  686. }
  687. #endif //_DEBUG
  688. // COGRESceneMgrView 消息处理程序
  689. void COGRESceneMgrView::OnImportMesh()
  690. {
  691. // TODO: 在此添加命令处理程序代码
  692. CFileDialog importmeshdlg(TRUE);
  693. //importmeshdlg.m_ofn.lpstrTile="wode";
  694. importmeshdlg.m_pOFN->lpstrTitle="导入网格对话框";
  695. importmeshdlg.m_pOFN->lpstrFilter="网格文件(*.mesh)*.mesh";
  696. if(IDOK==importmeshdlg.DoModal())
  697. {
  698. meshfile=importmeshdlg.GetFileName();
  699. str=meshfile.GetBuffer(meshfile.GetLength());
  700. bimportmesh=true;
  701. }
  702. }
  703. void COGRESceneMgrView::OnImportParticle()
  704. {
  705. // TODO: 在此添加命令处理程序代码
  706. ipdlg.DoModal();
  707. }
  708. void COGRESceneMgrView::OnImportScene()
  709. {
  710. // TODO: 在此添加命令处理程序代码
  711. CFileDialog importscenedlg(TRUE);
  712. importscenedlg.m_pOFN->lpstrFilter="场景文件(*.ogrescene.xml)*.xml";
  713. if(IDOK==importscenedlg.DoModal())
  714. {
  715. CString scenefilename;
  716. scenefilename=importscenedlg.GetFileName();
  717. TiXmlDocument *myDocument = new TiXmlDocument(scenefilename.GetBuffer(scenefilename.GetLength()));
  718.     myDocument->LoadFile();
  719. TiXmlElement *RootElement = myDocument->RootElement();
  720. TiXmlElement *FirstPerson = RootElement->FirstChildElement();
  721. TiXmlElement *loopelement=FirstPerson;
  722. while(loopelement){
  723. CString loopstr=loopelement->Value();
  724. //String  sfewf=loopelement->Value();
  725. //strutil.trim(sfewf);
  726. if(loopstr.Left(1)=="M")
  727. {
  728. TiXmlElement *meshnameele=loopelement->FirstChildElement();
  729. TiXmlText *meshnametext=(TiXmlText *)meshnameele->FirstChild();
  730. CString meshfilenamed=meshnametext->Value();
  731. TiXmlElement *positionele=meshnameele->NextSiblingElement();
  732. TiXmlElement *pxele=positionele->FirstChildElement();
  733. TiXmlText *pxval=(TiXmlText *)pxele->FirstChild();
  734. float px=(atof)(pxval->Value());
  735. TiXmlElement *pyele=pxele->NextSiblingElement();
  736. TiXmlText *pyval=(TiXmlText *)pyele->FirstChild();
  737. float py=(atof)(pyval->Value());
  738. TiXmlElement *pzele=pyele->NextSiblingElement();
  739. TiXmlText *pzval=(TiXmlText *)pzele->FirstChild();
  740. float pz=(atof)(pzval->Value());
  741. TiXmlElement *quaternionele=positionele->NextSiblingElement();
  742. TiXmlElement *pitchele=quaternionele->FirstChildElement();
  743. TiXmlText *pitchval=(TiXmlText *)pitchele->FirstChild();
  744. float pitchn=(atof)(pitchval->Value());
  745. TiXmlElement *rollele=pitchele->NextSiblingElement();
  746. TiXmlText *rollval=(TiXmlText *)rollele->FirstChild();
  747. float rolln=(atof)(rollval->Value());
  748. TiXmlElement *yawele=rollele->NextSiblingElement();
  749. TiXmlText *yawval=(TiXmlText *)yawele->FirstChild();
  750. float yawn=(atof)(yawval->Value());
  751. TiXmlElement *scaleele=quaternionele->NextSiblingElement();
  752. TiXmlElement *scalexele=scaleele->FirstChildElement();
  753. TiXmlText *scalexval=(TiXmlText *)scalexele->FirstChild();
  754. float scalexn=(atof)(scalexval->Value());
  755. TiXmlElement *scaleyele=scalexele->NextSiblingElement();
  756. TiXmlText *scaleyval=(TiXmlText *)scaleyele->FirstChild();
  757. float scaleyn=(atof)(scaleyval->Value());
  758. TiXmlElement *scalezele=scaleyele->NextSiblingElement();
  759. TiXmlText *scalezval=(TiXmlText *)scalezele->FirstChild();
  760. float scalezn=(atof)(scalezval->Value());
  761. ImportSceneMesh *scenemeshdate=new ImportSceneMesh(meshfilenamed,px,py,pz,
  762. pitchn,rolln,yawn,scalexn,scaleyn,scalezn);
  763. importmeshptr.Add(scenemeshdate);
  764. }
  765. if(loopstr.Left(1)=="P")
  766. {
  767. TiXmlElement *meshnameele=loopelement->FirstChildElement();
  768. TiXmlText *meshnametext=(TiXmlText *)meshnameele->FirstChild();
  769. CString meshfilenamed=meshnametext->Value();
  770. TiXmlElement *positionele=meshnameele->NextSiblingElement();
  771. TiXmlElement *pxele=positionele->FirstChildElement();
  772. TiXmlText *pxval=(TiXmlText *)pxele->FirstChild();
  773. float px=(atof)(pxval->Value());
  774. TiXmlElement *pyele=pxele->NextSiblingElement();
  775. TiXmlText *pyval=(TiXmlText *)pyele->FirstChild();
  776. float py=(atof)(pyval->Value());
  777. TiXmlElement *pzele=pyele->NextSiblingElement();
  778. TiXmlText *pzval=(TiXmlText *)pzele->FirstChild();
  779. float pz=(atof)(pzval->Value());
  780. TiXmlElement *quaternionele=positionele->NextSiblingElement();
  781. TiXmlElement *pitchele=quaternionele->FirstChildElement();
  782. TiXmlText *pitchval=(TiXmlText *)pitchele->FirstChild();
  783. float pitchn=(atof)(pitchval->Value());
  784. TiXmlElement *rollele=pitchele->NextSiblingElement();
  785. TiXmlText *rollval=(TiXmlText *)rollele->FirstChild();
  786. float rolln=(atof)(rollval->Value());
  787. TiXmlElement *yawele=rollele->NextSiblingElement();
  788. TiXmlText *yawval=(TiXmlText *)yawele->FirstChild();
  789. float yawn=(atof)(yawval->Value());
  790. TiXmlElement *scaleele=quaternionele->NextSiblingElement();
  791. TiXmlElement *scalexele=scaleele->FirstChildElement();
  792. TiXmlText *scalexval=(TiXmlText *)scalexele->FirstChild();
  793. float scalexn=(atof)(scalexval->Value());
  794. TiXmlElement *scaleyele=scalexele->NextSiblingElement();
  795. TiXmlText *scaleyval=(TiXmlText *)scaleyele->FirstChild();
  796. float scaleyn=(atof)(scaleyval->Value());
  797. TiXmlElement *scalezele=scaleyele->NextSiblingElement();
  798. TiXmlText *scalezval=(TiXmlText *)scalezele->FirstChild();
  799. float scalezn=(atof)(scalezval->Value());
  800. ImportSceneParticle *scenemeshdate=new ImportSceneParticle(meshfilenamed,px,py,pz,
  801. pitchn,rolln,yawn,scalexn,scaleyn,scalezn);
  802. importparticleptr.Add(scenemeshdate);
  803. }
  804. loopelement=loopelement->NextSiblingElement();
  805. }
  806. delete myDocument;
  807. bimportscene=true;
  808. }
  809. }
  810. void COGRESceneMgrView::OnSetTexture()
  811. {
  812. // TODO: 在此添加命令处理程序代码
  813. if(currentnode)
  814. settexturedlg.DoModal();
  815. }
  816. void COGRESceneMgrView::OnBnClickedImportParticle()
  817. {
  818. // TODO: 在此添加控件通知处理程序代码
  819. }
  820. void COGRESceneMgrView::OnFileSave()
  821. {
  822. // TODO: 在此添加命令处理程序代码
  823. CFileDialog savedlg(FALSE);
  824. savedlg.m_pOFN->lpstrTitle="场景保存";
  825. savedlg.m_pOFN->lpstrFilter="场景文件(*.ogrescene.xml)*.ogrescene.xml";
  826. if(IDOK==savedlg.DoModal())
  827. {
  828.   TiXmlDocument *myDocument = new TiXmlDocument();
  829.   TiXmlElement *RootElement = new TiXmlElement("Root");
  830.     myDocument->LinkEndChild(RootElement);
  831.   for(int i=1;i<meshnumber+1;i++){
  832.   Entity *meshentddd;
  833. meshentddd=mSceneMgr->getEntity("MESH"+stingconverter->toString(i));
  834. SceneNode *meshnodefff;
  835. meshnodefff=meshentddd->getParentSceneNode();
  836. Vector3 meshvecpo;
  837. meshvecpo=meshnodefff->getWorldPosition();
  838.   Quaternion meshquaternion;
  839.   meshquaternion=meshnodefff->getWorldOrientation();
  840.   Vector3 meshvecscale;
  841.   meshvecscale=meshnodefff->getScale();
  842.   TiXmlElement *mesheselement =new TiXmlElement("Meshes");
  843.   RootElement->LinkEndChild(mesheselement);
  844. TiXmlElement *meshesnameelement =new TiXmlElement("MeshesName");
  845.   mesheselement->LinkEndChild(meshesnameelement);
  846.  CString mesnfse=((FromIndexToName*)meshfileptr.GetAt(i-1))->meshnamestr;
  847.  char *megfer=mesnfse.GetBuffer(mesnfse.GetLength());
  848.  TiXmlText *meshtext=new TiXmlText(megfer);
  849.  
  850. meshesnameelement->LinkEndChild(meshtext);
  851.   TiXmlElement *positionelement=new TiXmlElement("Position");
  852.   mesheselement->LinkEndChild(positionelement);
  853. TiXmlElement *positionxelenment =new TiXmlElement("PositionX");
  854. positionelement->LinkEndChild(positionxelenment);
  855. char meshstrx[32];
  856. float positionx=meshvecpo.x;
  857. sprintf(meshstrx,"%fn",positionx);
  858. TiXmlText *positionxtext=new TiXmlText(meshstrx);
  859. positionxelenment->LinkEndChild(positionxtext);
  860. TiXmlElement *positionyelenment =new TiXmlElement("PositionY");
  861. positionelement->LinkEndChild(positionyelenment);
  862. char meshstry[32];
  863. float positiony=meshvecpo.y;
  864. sprintf(meshstry,"%fn",positiony);
  865. TiXmlText *positionytext=new TiXmlText(meshstry);
  866. positionyelenment->LinkEndChild(positionytext);
  867. TiXmlElement *positionzelenment =new TiXmlElement("PositionZ");
  868. positionelement->LinkEndChild(positionzelenment);
  869. char meshstrz[32];
  870. float positionz=meshvecpo.z;
  871. sprintf(meshstrz,"%fn",positionz);
  872. TiXmlText *positionztext=new TiXmlText(meshstrz);
  873. positionzelenment->LinkEndChild(positionztext);
  874. //meshquaternion.
  875. TiXmlElement *quaternionelement=new TiXmlElement("Quaternion");
  876. mesheselement->LinkEndChild(quaternionelement);
  877. TiXmlElement *pitchelement=new TiXmlElement("Pitch");
  878. quaternionelement->LinkEndChild(pitchelement);
  879. char meshpitch[32];
  880. Radian pitchnumr=meshquaternion.getPitch();
  881. //float pitchnumd=Math::RadiansToAngleUnits(pitchnumr.valueRadians());
  882. float pitchnumd=pitchnumr.valueRadians();
  883. sprintf(meshpitch,"%fn",pitchnumd);
  884. TiXmlText *pitchtext=new TiXmlText(meshpitch);
  885. pitchelement->LinkEndChild(pitchtext);
  886. TiXmlElement *rollelement=new TiXmlElement("Roll");
  887. quaternionelement->LinkEndChild(rollelement);
  888. char meshroll[32];
  889. Radian rollnumr=meshquaternion.getRoll();
  890. float rollnumd=Math::RadiansToAngleUnits(rollnumr.valueRadians());
  891. sprintf(meshroll,"%fn",rollnumd);
  892. TiXmlText *rolltext=new TiXmlText(meshroll);
  893. rollelement->LinkEndChild(rolltext);
  894. TiXmlElement *yawelement=new TiXmlElement("Yaw");
  895. quaternionelement->LinkEndChild(yawelement);
  896. char meshyaw[32];
  897. Radian yawnumr=meshquaternion.getYaw();
  898. float yawnumd=Math::RadiansToAngleUnits(yawnumr.valueRadians());
  899. sprintf(meshyaw,"%fn",yawnumd);
  900. TiXmlText *yawtext=new TiXmlText(meshyaw);
  901. yawelement->LinkEndChild(yawtext);
  902.  
  903.  TiXmlElement *scaleelement=new TiXmlElement("Scale");
  904.   mesheselement->LinkEndChild(scaleelement);
  905. TiXmlElement *scalexelement =new TiXmlElement("ScaleX");
  906. scaleelement->LinkEndChild(scalexelement);
  907. char meshscalex[32];
  908. float scalex=meshvecscale.x;
  909. sprintf(meshscalex,"%fn",scalex);
  910. TiXmlText *scalextext=new TiXmlText(meshscalex);
  911. scalexelement->LinkEndChild(scalextext);
  912. TiXmlElement *scaleyelenment =new TiXmlElement("ScaleY");
  913. scaleelement->LinkEndChild(scaleyelenment);
  914. char meshscaley[32];
  915. float scaley=meshvecscale.y;
  916. sprintf(meshscaley,"%fn",scaley);
  917. TiXmlText *scaleytext=new TiXmlText(meshscaley);
  918. scaleyelenment->LinkEndChild(scaleytext);
  919. TiXmlElement *scalezelement =new TiXmlElement("ScaleZ");
  920. scaleelement->LinkEndChild(scalezelement);
  921. char meshscalez[32];
  922. float scalez=meshvecscale.z;
  923. sprintf(meshscalez,"%fn",scalez);
  924. TiXmlText *scaleztext=new TiXmlText(meshscalez);
  925. scalezelement->LinkEndChild(scaleztext);
  926.  }
  927.   for(int i=1;i<particlenumber+1;i++){
  928.   ParticleSystem* psys;
  929.   psys=mSceneMgr->getParticleSystem("PARTICLE"+stingconverter->toString(i));
  930. SceneNode *particlenodefff;
  931. particlenodefff=psys->getParentSceneNode();
  932. Vector3 meshvecpo;
  933. meshvecpo=particlenodefff->getWorldPosition();
  934.   Quaternion meshquaternion;
  935.   meshquaternion=particlenodefff->getWorldOrientation();
  936.   Vector3 meshvecscale;
  937.   meshvecscale=particlenodefff->getScale();
  938.   TiXmlElement *mesheselement =new TiXmlElement("Particle");
  939.   RootElement->LinkEndChild(mesheselement);
  940.   TiXmlElement *particlefileelement =new TiXmlElement("ParticleName");
  941.   mesheselement->LinkEndChild(particlefileelement);
  942.   TiXmlText *parfilenameee=new TiXmlText(((IndexToParticleName*)(parfileptr.GetAt(i-1)))->parfilename);
  943. particlefileelement->LinkEndChild(parfilenameee);
  944.  // TiXmlText *meshtext=new TiXmlText();
  945.   TiXmlElement *positionelement=new TiXmlElement("Position");
  946.   mesheselement->LinkEndChild(positionelement);
  947. TiXmlElement *positionxelenment =new TiXmlElement("PositionX");
  948. positionelement->LinkEndChild(positionxelenment);
  949. char meshstrx[32];
  950. float positionx=meshvecpo.x;
  951. sprintf(meshstrx,"%fn",positionx);
  952. TiXmlText *positionxtext=new TiXmlText(meshstrx);
  953. positionxelenment->LinkEndChild(positionxtext);
  954. TiXmlElement *positionyelenment =new TiXmlElement("PositionY");
  955. positionelement->LinkEndChild(positionyelenment);
  956. char meshstry[32];
  957. float positiony=meshvecpo.y;
  958. sprintf(meshstry,"%fn",positiony);
  959. TiXmlText *positionytext=new TiXmlText(meshstry);
  960. positionyelenment->LinkEndChild(positionytext);
  961. TiXmlElement *positionzelenment =new TiXmlElement("PositionZ");
  962. positionelement->LinkEndChild(positionzelenment);
  963. char meshstrz[32];
  964. float positionz=meshvecpo.z;
  965. sprintf(meshstrz,"%fn",positionz);
  966. TiXmlText *positionztext=new TiXmlText(meshstrz);
  967. positionzelenment->LinkEndChild(positionztext);
  968. //meshquaternion.
  969. TiXmlElement *quaternionelement=new TiXmlElement("Quaternion");
  970. mesheselement->LinkEndChild(quaternionelement);
  971. TiXmlElement *pitchelement=new TiXmlElement("Pitch");
  972. quaternionelement->LinkEndChild(pitchelement);
  973. char meshpitch[32];
  974. Radian pitchnumr=meshquaternion.getPitch();
  975. //float pitchnumd=Math::RadiansToAngleUnits(pitchnumr.valueRadians());
  976. float pitchnumd=pitchnumr.valueRadians();
  977. sprintf(meshpitch,"%fn",pitchnumd);
  978. TiXmlText *pitchtext=new TiXmlText(meshpitch);
  979. pitchelement->LinkEndChild(pitchtext);
  980. TiXmlElement *rollelement=new TiXmlElement("Roll");
  981. quaternionelement->LinkEndChild(rollelement);
  982. char meshroll[32];
  983. Radian rollnumr=meshquaternion.getRoll();
  984. float rollnumd=Math::RadiansToAngleUnits(rollnumr.valueRadians());
  985. sprintf(meshroll,"%fn",rollnumd);
  986. TiXmlText *rolltext=new TiXmlText(meshroll);
  987. rollelement->LinkEndChild(rolltext);
  988. TiXmlElement *yawelement=new TiXmlElement("Yaw");
  989. quaternionelement->LinkEndChild(yawelement);
  990. char meshyaw[32];
  991. Radian yawnumr=meshquaternion.getYaw();
  992. float yawnumd=Math::RadiansToAngleUnits(yawnumr.valueRadians());
  993. sprintf(meshyaw,"%fn",yawnumd);
  994. TiXmlText *yawtext=new TiXmlText(meshyaw);
  995. yawelement->LinkEndChild(yawtext);
  996.  
  997.  TiXmlElement *scaleelement=new TiXmlElement("Scale");
  998.   mesheselement->LinkEndChild(scaleelement);
  999. TiXmlElement *scalexelement =new TiXmlElement("ScaleX");
  1000. scaleelement->LinkEndChild(scalexelement);
  1001. char meshscalex[32];
  1002. float scalex=meshvecscale.x;
  1003. sprintf(meshscalex,"%fn",scalex);
  1004. TiXmlText *scalextext=new TiXmlText(meshscalex);
  1005. scalexelement->LinkEndChild(scalextext);
  1006. TiXmlElement *scaleyelenment =new TiXmlElement("ScaleY");
  1007. scaleelement->LinkEndChild(scaleyelenment);
  1008. char meshscaley[32];
  1009. float scaley=meshvecscale.y;
  1010. sprintf(meshscaley,"%fn",scaley);
  1011. TiXmlText *scaleytext=new TiXmlText(meshscaley);
  1012. scaleyelenment->LinkEndChild(scaleytext);
  1013. TiXmlElement *scalezelement =new TiXmlElement("ScaleZ");
  1014. scaleelement->LinkEndChild(scalezelement);
  1015. char meshscalez[32];
  1016. float scalez=meshvecscale.z;
  1017. sprintf(meshscalez,"%fn",scalez);
  1018. TiXmlText *scaleztext=new TiXmlText(meshscalez);
  1019. scalezelement->LinkEndChild(scaleztext);
  1020.  }
  1021.  
  1022. CString scenefilename;
  1023. scenefilename=savedlg.GetFileName();
  1024. char *scenefilebuffer;
  1025. scenefilebuffer=scenefilename.GetBuffer(scenefilename.GetLength());
  1026. //sprintf(scenefilebuffer,"%s.xml",scenefilebuffer);
  1027.  myDocument->SaveFile(scenefilebuffer);
  1028. }
  1029. }
  1030. void COGRESceneMgrView::OnSetSky()
  1031. {
  1032. // TODO: 在此添加命令处理程序代码
  1033. if(IDOK==skystylechoosedlg.DoModal())
  1034. {
  1035. UpdateData();
  1036. if(1==skystylechoosedlg.SkyRadio)
  1037. {
  1038. if(IDOK==skyplanedlgv.DoModal())
  1039. {
  1040. // skyplanedlgv.GetDlgItemText(
  1041. bsetskyplane=true;
  1042. bsetskyall=true;
  1043. if(skyplanedlgv.skyplanemarterial=="")
  1044. MessageBox("没有选择天空材质!");
  1045. if(skyplanedlgv.skyplanedd==0) MessageBox("没有选择天空宽度!");
  1046. if(skyplanedlgv.skyplaneheigh==0) MessageBox("没有选择天空高度!");
  1047. }
  1048. }
  1049. else
  1050. if(2==skystylechoosedlg.SkyRadio)
  1051. {
  1052. if(IDOK==skyboxdlgv.DoModal())
  1053. {bsetskybox=true;
  1054. bsetskyall=true;}
  1055. }
  1056. else
  1057. if(3==skystylechoosedlg.SkyRadio)
  1058. {
  1059. if(IDOK==skydomedlgv.DoModal())
  1060. {bsetskydome=true;
  1061. bsetskyall=true;}
  1062. }
  1063. else MessageBox("未选择");
  1064. }
  1065. }
  1066. void COGRESceneMgrView::OnSetFogMenu()
  1067. {
  1068. // TODO: 在此添加命令处理程序代码
  1069. CColorDialog colordlg;
  1070. if(IDOK==colordlg.DoModal())
  1071. {
  1072. COLORREF  RGbdd=colordlg.m_cc.rgbResult;
  1073. //ColourValue fadeColour=RGbdd;
  1074. WORD  RGCOLOR=LOWORD(RGbdd);
  1075. WORD  BNCOLOR=HIWORD(RGbdd);
  1076.   BYTE rcolor=LOBYTE(RGCOLOR);
  1077.   BYTE gcolor=HIBYTE(RGCOLOR);
  1078.   BYTE bcolor=LOBYTE(BNCOLOR);
  1079.   int rccc=rcolor;
  1080.   int gccc=gcolor;
  1081.   int bccc=bcolor;
  1082.  rcolommm=rccc;
  1083.  gcolommm=gccc;
  1084.  bcolommm=bccc;
  1085. bsetfog=true;
  1086. }
  1087. }
  1088. void COGRESceneMgrView::OnSetShadowMenu()
  1089. {
  1090. if(IDOK==setshadowtecdlg.DoModal())
  1091. {
  1092. //if(setshadowtecdlg.shadowtecenshu==1) MessageBox("11111111");
  1093. bsetshadowtech=true;
  1094. }
  1095. }
  1096. void COGRESceneMgrView::OnTranslateMove()
  1097. {
  1098. // TODO: 在此添加命令处理程序代码
  1099. if(currentnode){ movenodeccc=currentnode;
  1100. /*if(IDOK==movemeshdlg.DoModal())
  1101. {
  1102. if(movemeshdlg.slidebuchang==false)
  1103. {movebuchang=movemeshdlg.ZiDingyiBuchang;
  1104. if(movebuchang==0) MessageBox("步长不可为零!");
  1105. }else movebuchang=movemeshdlg.MoveBuChang.GetPos();
  1106. */
  1107.  btramove=true;
  1108.  bratate=false;
  1109.  bscaled=false;
  1110. bgetmovenode=true;
  1111.  bmovecurent=true;
  1112.  wejwjw=true;
  1113. bAxesXYZ=true;
  1114. //}
  1115. }else MessageBox("未选择任何需要移动物体!");
  1116. }
  1117. void COGRESceneMgrView::OnTotateSce()
  1118. {
  1119. // TODO: 在此添加命令处理程序代码
  1120. if(currentnode){movenodeccc=currentnode;
  1121. /*if(IDOK==rotatesetdlg.DoModal()){
  1122. if(rotatesetdlg.makesurecustom)
  1123. {rorateangle=rotatesetdlg.ROTATEANGLECU;
  1124.    if(rorateangle==0) MessageBox("角度不设为零!");}
  1125. else rorateangle=rotatesetdlg.RotateSliderCtrl.GetPos();*/
  1126.  btramove=false;
  1127.  bratate=true;
  1128.  bscaled=false;
  1129.  bAxesXYZ=true; //}
  1130.         }else MessageBox("未选择任何需要旋转物体!");
  1131. }
  1132. void COGRESceneMgrView::OnScaleScene()
  1133. {
  1134. // TODO: 在此添加命令处理程序代码
  1135. if(currentnode){movenodeccc=currentnode;
  1136. if(IDOK==scalesetddlg.DoModal()){
  1137. if(scalesetddlg.bsetscalecustom){
  1138. scalddefw=scalesetddlg.SCALEFLAOTSET;
  1139. }else scalddefw=(scalesetddlg.SCALESETSLEDER.GetPos())/10000;
  1140. if(scalddefw==0) MessageBox("旋转参数不能为零!");
  1141. scalnowset=scalddefw;
  1142.  btramove=false;
  1143.  bratate=false;
  1144.  bscaled=true;
  1145. bAxesXYZ=true;
  1146. }}else MessageBox("未选中任何物体!");
  1147. }
  1148. void COGRESceneMgrView::OnDeleteSCENEMeshpa()
  1149. {
  1150. // TODO: 在此添加命令处理程序代码
  1151. currentnode->detachAllObjects();
  1152. }
  1153. void COGRESceneMgrView::OnImportWorldGemotry()
  1154. {
  1155. // TODO: 在此添加命令处理程序代码
  1156. CFileDialog importworld(TRUE);
  1157. importworld.m_pOFN->lpstrTitle="导入世界地图";
  1158. importworld.m_pOFN->lpstrFilter="地图文件(*.cfg)*.cfg";
  1159. if(IDOK==importworld.DoModal())
  1160. {worldgemotry=importworld.GetFileName();
  1161. bimportworld=true;
  1162.  }
  1163. }