EditorCamera.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. #ifndef EDITORCAMERA_H
  2. #define EDITORCAMERA_H
  3. /*************************************************************************************************\
  4. EditorCamera.h : Interface for the EditorCamera component.
  5. //---------------------------------------------------------------------------//
  6. // Copyright (C) Microsoft Corporation. All rights reserved. //
  7. //===========================================================================//
  8. \*************************************************************************************************/
  9. #ifndef CAMERA_H
  10. #include "Camera.h"
  11. #endif
  12. #ifndef EDITOROBJECTMGR_H
  13. #include "EditorObjectMgr.h"
  14. #endif
  15. #ifndef OBJSTATUS_H
  16. #include "objstatus.h"
  17. #endif
  18. //*************************************************************************************************
  19. /**************************************************************************************************
  20. CLASS DESCRIPTION
  21. EditorCamera: draws the terrain and objects and stuff
  22. **************************************************************************************************/
  23. extern bool useShadows;
  24. extern bool s_bSensorMapEnabled;
  25. extern bool drawOldWay;
  26. extern bool useFog;
  27. extern MidLevelRenderer::MLRClipper * theClipper;
  28. bool useLOSAngle = false;
  29. class EditorCamera : public Camera
  30. {
  31. //Data Members
  32. //-------------
  33. public:
  34. AppearancePtr compass;
  35. AppearancePtr theSky;
  36. bool drawCompass;
  37. float lastShadowLightPitch;
  38. long cameraLineChanged;
  39. long oldSkyNumber;
  40. EditorCamera (void)
  41. {
  42. init();
  43. }
  44. virtual void init (void)
  45. {
  46. Camera::init();
  47. compass = NULL;
  48. drawCompass = true;
  49. cameraLineChanged = 0;
  50. theSky = NULL;
  51. }
  52. virtual void reset (void)
  53. {
  54. //Must toss these between map loads to clear out their texture memory!!
  55. delete compass;
  56. compass = NULL;
  57. delete theSky;
  58. theSky = NULL;
  59. }
  60. virtual void render (void)
  61. {
  62. //------------------------------------------------------
  63. // At present, these actually draw. Later they will
  64. // add elements to the draw list and sort and draw.
  65. // The later time has arrived. We begin sorting immediately.
  66. // NO LONGER NEED TO SORT!
  67. // ZBuffer time has arrived. Share and Enjoy!
  68. // Everything SIMPLY draws at the execution point into the zBuffer
  69. // at the correct depth. Miracles occur at that point!
  70. // Big code change but it removes a WHOLE bunch of code and memory!
  71. //--------------------------------------------------------
  72. // Get new viewport values to scale stuff. No longer uses
  73. // VFX stuff for this. ALL GOS NOW!
  74. gos_GetViewport(&viewMulX, &viewMulY, &viewAddX, &viewAddY);
  75. //--------------------------------------------------------
  76. // Get new viewport values to scale stuff. No longer uses
  77. // VFX stuff for this. ALL GOS NOW!
  78. screenResolution.x = viewMulX;
  79. screenResolution.y = viewMulY;
  80. calculateProjectionConstants();
  81. TG_Shape::SetViewport(viewMulX,viewMulY,viewAddX,viewAddY);
  82. globalScaleFactor = getScaleFactor();
  83. globalScaleFactor *= viewMulX / Environment.screenWidth; //Scale Mechs to ScreenRES
  84. //-----------------------------------------------
  85. // Set Ambient for this pass of rendering
  86. DWORD lightRGB = (ambientRed<<16)+(ambientGreen<<8)+ambientBlue;
  87. eye->setLightColor(1,lightRGB);
  88. eye->setLightIntensity(1,1.0);
  89. MidLevelRenderer::MLRState default_state;
  90. default_state.SetBackFaceOn();
  91. default_state.SetDitherOn();
  92. default_state.SetTextureCorrectionOn();
  93. default_state.SetZBufferCompareOn();
  94. default_state.SetZBufferWriteOn();
  95. default_state.SetFilterMode(MidLevelRenderer::MLRState::BiLinearFilterMode);
  96. float z = 1.0f;
  97. Stuff::RGBAColor fColor;
  98. fColor.red = (float)((fogColor >> 16) & 0xff);
  99. fColor.green = (float)((fogColor >> 8) & 0xff);
  100. fColor.blue = (float)((fogColor) & 0xff);
  101. MidLevelRenderer::PerspectiveMode = usePerspective;
  102. theClipper->StartDraw(cameraOrigin, cameraToClip, fColor, &fColor, default_state, &z);
  103. MidLevelRenderer::GOSVertex::farClipReciprocal = (1.0f-cameraToClip(2, 2))/cameraToClip(3, 2);
  104. if (active && turn > 1)
  105. {
  106. if (theSky)
  107. theSky->render(1);
  108. land->render(); //render the Terrain
  109. //If you ever want craters in the editor, just turn this on. No way to save 'em though!
  110. //craterManager->render(); //render the craters and footprints
  111. //Only the GameCamera knows about this. Heidi, override this function in EditorCamera
  112. //and have your objectManager draw.
  113. if (!s_bSensorMapEnabled)
  114. EditorObjectMgr::instance()->render(); //render all other objects
  115. land->renderWater();
  116. if (!s_bSensorMapEnabled && useShadows)
  117. EditorObjectMgr::instance()->renderShadows(); //render all other objects
  118. if (!drawOldWay)
  119. {
  120. if (compass && (turn > 3) && drawCompass)
  121. compass->render(-1); //Force this to zBuffer in front of everything
  122. }
  123. if (!drawOldWay)
  124. mcTextureManager->renderLists();
  125. //theClipper->RenderNow(); //Draw the FX
  126. /* The editor interface needs to be drawn last, as it draws things "on top" of the
  127. rendered scene. */
  128. if ( EditorInterface::instance() )
  129. {
  130. EditorInterface::instance()->render();
  131. /* We need to call renderLists() again to render the "object placement" cursor
  132. that, if active, was placed in a render list in the "EditorInterface::instance()->render()"
  133. call. renderLists() seems to have an automatic mechanism for not redrawing
  134. things it has already drawn. Pretty much everything else drawn by
  135. EditorInterface is "rendered immediately" (not placed in a renderList). */
  136. mcTextureManager->renderLists();
  137. }
  138. }
  139. //-----------------------------------------------------
  140. if (drawOldWay)
  141. {
  142. gos_SetRenderState( gos_State_ZCompare, 0);
  143. gos_SetRenderState( gos_State_ZWrite, 0);
  144. gos_SetRenderState( gos_State_Perspective, 1);
  145. if (compass && (turn > 3) && drawCompass)
  146. compass->render();
  147. }
  148. }
  149. virtual long activate (void)
  150. {
  151. // If camera is already active, just return
  152. if (ready && active)
  153. return(NO_ERR);
  154. //Can set initial position and stuff here.
  155. //updateDaylight(true);
  156. lastShadowLightPitch = lightPitch;
  157. allNormal();
  158. return NO_ERR;
  159. }
  160. virtual long update (void)
  161. {
  162. // calculate new near and far plane distance based on
  163. // Current altitude above terrain.
  164. float anglePercent = (projectionAngle - MIN_PERSPECTIVE) / (MAX_PERSPECTIVE - MIN_PERSPECTIVE);
  165. float testMax = Camera::AltitudeMaximumLo + ((Camera::AltitudeMaximumHi - Camera::AltitudeMaximumLo) * anglePercent);
  166. float altitudePercent = (cameraAltitude - AltitudeMinimum) / (testMax - AltitudeMinimum);
  167. Camera::NearPlaneDistance = MinNearPlane + ((MaxNearPlane - MinNearPlane) * altitudePercent);
  168. Camera::FarPlaneDistance = MinFarPlane + ((MaxFarPlane - MinFarPlane) * altitudePercent);
  169. if (!compass && (turn > 3)) //Create it!
  170. {
  171. //Gotta check for the list too because a NEW map has no objects on it and this list
  172. // Doesn't exist until objects are placed. Strange but true...
  173. if ( !appearanceTypeList )
  174. {
  175. appearanceTypeList = new AppearanceTypeList;
  176. gosASSERT(appearanceTypeList != NULL);
  177. appearanceTypeList->init(2048000);
  178. }
  179. AppearanceType* appearanceType = appearanceTypeList->getAppearance( BLDG_TYPE << 24, "compass" );
  180. compass = new BldgAppearance;
  181. compass->init( appearanceType );
  182. }
  183. if (!theSky && (turn > 3))
  184. {
  185. //Startup the SKYBox
  186. long appearanceType = (GENERIC_APPR_TYPE << 24);
  187. AppearanceTypePtr genericAppearanceType = NULL;
  188. genericAppearanceType = appearanceTypeList->getAppearance(appearanceType,"skybox");
  189. if (!genericAppearanceType)
  190. {
  191. char msg[1024];
  192. sprintf(msg,"No Generic Appearance Named %s","skybox");
  193. Fatal(0,msg);
  194. }
  195. theSky = new GenericAppearance;
  196. gosASSERT(theSky != NULL);
  197. //--------------------------------------------------------------
  198. gosASSERT(genericAppearanceType->getAppearanceClass() == GENERIC_APPR_TYPE);
  199. theSky->init((GenericAppearanceType*)genericAppearanceType, NULL);
  200. theSky->setSkyNumber(EditorData::instance->TheSkyNumber());
  201. oldSkyNumber = EditorData::instance->TheSkyNumber();
  202. }
  203. //Did they change the skyNumber on us?
  204. if (theSky && (oldSkyNumber != EditorData::instance->TheSkyNumber()))
  205. {
  206. theSky->setSkyNumber(EditorData::instance->TheSkyNumber());
  207. oldSkyNumber = EditorData::instance->TheSkyNumber();
  208. }
  209. long result = Camera::update();
  210. if ((cameraLineChanged + 10) < turn)
  211. {
  212. if (userInput->getKeyDown(KEY_BACKSLASH) && !userInput->ctrl() && !userInput->alt() && !userInput->shift())
  213. {
  214. drawCompass ^= true;
  215. cameraLineChanged = turn;
  216. }
  217. }
  218. #define MAX_SHADOW_PITCH_CHANGE (5.0f)
  219. //Always recalc here or shadows never change in editor!!
  220. forceShadowRecalc = true;
  221. if (compass && (turn > 3))
  222. {
  223. bool oldFog = useFog;
  224. bool oldShadows = useShadows;
  225. useFog = false;
  226. useShadows = false;
  227. Stuff::Vector3D pos = getPosition();
  228. compass->setObjectParameters(pos,0.0f,false,0,0);
  229. compass->setMoverParameters(0.0f);
  230. compass->setGesture(0);
  231. compass->setObjStatus(OBJECT_STATUS_DESTROYED);
  232. compass->setInView(true);
  233. compass->setVisibility(true,true);
  234. compass->setFilterState(true);
  235. compass->setIsHudElement();
  236. compass->update(); //Force it to try and draw or stuff will not work!
  237. if (theSky)
  238. {
  239. Stuff::Vector3D pos = getPosition();
  240. theSky->setObjectParameters(pos,0.0f,false,0,0);
  241. theSky->setMoverParameters(0.0f);
  242. theSky->setGesture(0);
  243. theSky->setObjStatus(OBJECT_STATUS_NORMAL);
  244. theSky->setInView(true);
  245. theSky->setVisibility(true,true);
  246. theSky->setFilterState(true);
  247. theSky->setIsHudElement();
  248. theSky->update(); //Force it to try and draw or stuff will not work!
  249. }
  250. useFog = oldFog;
  251. useShadows = oldShadows;
  252. }
  253. return result;
  254. }
  255. };
  256. //*************************************************************************************************
  257. #endif // end of file ( EditorCamera.h )