SceneWindow.cc 80 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #include "graphics/dgl.h"
  23. #include "gui/guiTypes.h"
  24. #include "gui/guiCanvas.h"
  25. #include "console/console.h"
  26. #include "console/consoleTypes.h"
  27. #include "math/mMathFn.h"
  28. #include "2d/sceneobject/SceneObject.h"
  29. #include "2d/core/Utility.h"
  30. #include "2d/gui/SceneWindow.h"
  31. #include "gui/containers/guiSceneScrollCtrl.h"
  32. #ifndef _ASSET_MANAGER_H_
  33. #include "assets/assetManager.h"
  34. #endif
  35. // Script bindings.
  36. #include "SceneWindow_ScriptBinding.h"
  37. // Debug Profiling.
  38. #include "debug/profiler.h"
  39. // Input event names.
  40. static StringTableEntry inputEventEnterName = StringTable->insert("onTouchEnter");
  41. static StringTableEntry inputEventLeaveName = StringTable->insert("onTouchLeave");
  42. static StringTableEntry inputEventDownName = StringTable->insert("onTouchDown");
  43. static StringTableEntry inputEventUpName = StringTable->insert("onTouchUp");
  44. static StringTableEntry inputEventMovedName = StringTable->insert("onTouchMoved");
  45. static StringTableEntry inputEventDraggedName = StringTable->insert("onTouchDragged");
  46. static StringTableEntry mouseEventMiddleMouseDownName = StringTable->insert("onMiddleMouseDown");
  47. static StringTableEntry mouseEventMiddleMouseUpName = StringTable->insert("onMiddleMouseUp");
  48. static StringTableEntry mouseEventMiddleMouseDraggedName= StringTable->insert("onMiddleMouseDragged");
  49. static StringTableEntry mouseEventRightMouseDownName = StringTable->insert("onRightMouseDown");
  50. static StringTableEntry mouseEventRightMouseUpName = StringTable->insert("onRightMouseUp");
  51. static StringTableEntry mouseEventRightMouseDraggedName= StringTable->insert("onRightMouseDragged");
  52. static StringTableEntry mouseEventWheelUpName = StringTable->insert("onMouseWheelUp");
  53. static StringTableEntry mouseEventWheelDownName = StringTable->insert("onMouseWheelDown");
  54. static StringTableEntry mouseEventEnterName = StringTable->insert("onTouchEnter");
  55. static StringTableEntry mouseEventLeaveName = StringTable->insert("onTouchLeave");
  56. //-----------------------------------------------------------------------------
  57. IMPLEMENT_CONOBJECT(SceneWindow);
  58. //-----------------------------------------------------------------------------
  59. static EnumTable::Enums interpolationModeLookup[] =
  60. {
  61. { SceneWindow::LINEAR, "LINEAR" },
  62. { SceneWindow::SIGMOID, "SIGMOID" },
  63. };
  64. static EnumTable interpolationModeTable(sizeof(interpolationModeLookup) / sizeof(EnumTable::Enums), &interpolationModeLookup[0]);
  65. //-----------------------------------------------------------------------------
  66. SceneWindow::CameraInterpolationMode SceneWindow::getInterpolationModeEnum(const char* label)
  67. {
  68. // Search for Mnemonic.
  69. for(U32 i = 0; i < (sizeof(interpolationModeLookup) / sizeof(EnumTable::Enums)); i++)
  70. if( dStricmp(interpolationModeLookup[i].label, label) == 0)
  71. return((CameraInterpolationMode)interpolationModeLookup[i].index);
  72. // Warn.
  73. Con::warnf( "SceneWindow::getInterpolationModeEnum() - Invalid interpolation mode '%s'.", label );
  74. return SceneWindow::INVALID_INTERPOLATION_MODE;
  75. }
  76. //-----------------------------------------------------------------------------
  77. SceneWindow::SceneWindow() : mpScene(NULL),
  78. mLockMouse(false),
  79. mWindowDirty(true),
  80. mRenderLayerMask(MASK_ALL),
  81. mRenderGroupMask(MASK_ALL),
  82. mBackgroundColor( "Black" ),
  83. mUseBackgroundColor(false),
  84. mCameraInterpolationMode(SIGMOID),
  85. mMaxQueueItems(64),
  86. mCameraTransitionTime(2.0f),
  87. mMovingCamera(false),
  88. mpMountedTo(NULL),
  89. mCameraMounted(false),
  90. mCameraShaking(false),
  91. mCameraShakeOffset(0.0f,0.0f),
  92. mViewLimitActive(false),
  93. mUseWindowInputEvents(true),
  94. mUseObjectInputEvents(false),
  95. mInputEventGroupMaskFilter(MASK_ALL),
  96. mInputEventLayerMaskFilter(MASK_ALL),
  97. mInputEventInvisibleFilter( true ),
  98. mProcessAudioListener(false),
  99. mShowScrollBar(false),
  100. mMouseWheelScrolls(false)
  101. {
  102. // Set Vector Associations.
  103. VECTOR_SET_ASSOCIATION( mCameraQueue );
  104. VECTOR_SET_ASSOCIATION( mInputEventQuery );
  105. VECTOR_SET_ASSOCIATION( mInputEventEntering );
  106. VECTOR_SET_ASSOCIATION( mInputEventLeaving );
  107. // Turn-on Tick Processing.
  108. setProcessTicks( true );
  109. mThumbProfile = NULL;
  110. mTrackProfile = NULL;
  111. mArrowProfile = NULL;
  112. mScrollBar = new GuiSceneScrollCtrl(this);
  113. mScrollBar->mForceVScrollBar = GuiScrollCtrl::ScrollBarDynamic;
  114. mScrollBar->mForceHScrollBar = GuiScrollCtrl::ScrollBarDynamic;
  115. mUseConstantHeightThumb = false;
  116. mScrollBarThickness = 16;
  117. mShowArrowButtons = true;
  118. mThumbProfile = mScrollBar->mThumbProfile;
  119. mThumbProfile->incRefCount();
  120. mTrackProfile = mScrollBar->mTrackProfile;
  121. mThumbProfile->incRefCount();
  122. mArrowProfile = mScrollBar->mArrowProfile;
  123. mThumbProfile->incRefCount();
  124. mRendersChildren = false;
  125. mIsContainer = false;
  126. }
  127. //-----------------------------------------------------------------------------
  128. SceneWindow::~SceneWindow()
  129. {
  130. delete mScrollBar;
  131. }
  132. //-----------------------------------------------------------------------------
  133. bool SceneWindow::onAdd()
  134. {
  135. // Call parent.
  136. if(!Parent::onAdd())
  137. return false;
  138. // Register input sets.
  139. mInputEventWatching.registerObject();
  140. mInputListeners.registerObject();
  141. // Reset the camera position.
  142. setCameraPosition( Vector2::getZero() );
  143. // Reset the camera size.
  144. setCameraSize( Vector2( 100.0f, 75.0f ) );
  145. // Reset the camera zoom.
  146. setCameraZoom( 1.0f );
  147. // Zero Camera Time.
  148. zeroCameraTime();
  149. // Return Okay.
  150. return true;
  151. }
  152. //-----------------------------------------------------------------------------
  153. void SceneWindow::onRemove()
  154. {
  155. // Reset Scene.
  156. resetScene();
  157. // Unregister input sets.
  158. mInputEventWatching.unregisterObject();
  159. mInputListeners.unregisterObject();
  160. // Call Parent.
  161. Parent::onRemove();
  162. }
  163. //-----------------------------------------------------------------------------
  164. void SceneWindow::initPersistFields()
  165. {
  166. // Call Parent.
  167. Parent::initPersistFields();
  168. // Add Fields.
  169. addField( "lockMouse", TypeBool, Offset(mLockMouse, SceneWindow) );
  170. addField( "UseWindowInputEvents", TypeBool, Offset(mUseWindowInputEvents, SceneWindow) );
  171. addField( "UseObjectInputEvents", TypeBool, Offset(mUseObjectInputEvents, SceneWindow) );
  172. // Background color.
  173. addField("UseBackgroundColor", TypeBool, Offset(mUseBackgroundColor, SceneWindow), &writeUseBackgroundColor, "" );
  174. addField("BackgroundColor", TypeColorF, Offset(mBackgroundColor, SceneWindow), &writeBackgroundColor, "" );
  175. //Standard scroll bar settings
  176. addProtectedField("constantThumbHeight", TypeBool, Offset(mUseConstantHeightThumb, SceneWindow), &setConstantThumbFn, &defaultProtectedGetFn, &writeScrollSettingFn, "");
  177. addProtectedField("scrollBarThickness", TypeS32, Offset(mScrollBarThickness, SceneWindow), &setScrollBarThicknessFn, &defaultProtectedGetFn, &writeScrollSettingFn, "");
  178. addProtectedField("showArrowButtons", TypeBool, Offset(mShowArrowButtons, SceneWindow), &setShowArrowButtonsFn, &defaultProtectedGetFn, &writeScrollSettingFn, "");
  179. addProtectedField("thumbProfile", TypeGuiProfile, Offset(mThumbProfile, SceneWindow), &setThumbProfileFn, &defaultProtectedGetFn, &writeScrollSettingFn, "");
  180. addProtectedField("trackProfile", TypeGuiProfile, Offset(mTrackProfile, SceneWindow), &setTrackProfileFn, &defaultProtectedGetFn, &writeScrollSettingFn, "");
  181. addProtectedField("arrowProfile", TypeGuiProfile, Offset(mArrowProfile, SceneWindow), &setArrowProfileFn, &defaultProtectedGetFn, &writeScrollSettingFn, "");
  182. }
  183. bool SceneWindow::onWake()
  184. {
  185. if (!Parent::onWake())
  186. {
  187. return false;
  188. }
  189. if (mThumbProfile != NULL)
  190. mThumbProfile->incRefCount();
  191. if (mTrackProfile != NULL)
  192. mTrackProfile->incRefCount();
  193. if (mArrowProfile != NULL)
  194. mArrowProfile->incRefCount();
  195. if(mShowScrollBar)
  196. {
  197. mScrollBar->onWake();
  198. }
  199. return true;
  200. }
  201. void SceneWindow::onSleep()
  202. {
  203. Parent::onSleep();
  204. if (mThumbProfile != NULL)
  205. mThumbProfile->decRefCount();
  206. if (mTrackProfile != NULL)
  207. mTrackProfile->decRefCount();
  208. if (mArrowProfile != NULL)
  209. mArrowProfile->decRefCount();
  210. if(mScrollBar->mAwake)
  211. {
  212. mScrollBar->onSleep();
  213. }
  214. }
  215. void SceneWindow::setUseConstantThumbHeight(const bool setting)
  216. {
  217. if (setting == mUseConstantHeightThumb)
  218. return;
  219. mUseConstantHeightThumb = setting;
  220. mScrollBar->mUseConstantHeightThumb = setting;
  221. }
  222. void SceneWindow::setScrollBarThickness(const S32 thickness)
  223. {
  224. if (thickness == mScrollBarThickness)
  225. return;
  226. mScrollBarThickness = thickness;
  227. mScrollBar->mScrollBarThickness = thickness;
  228. }
  229. void SceneWindow::setShowArrowButtons(const bool setting)
  230. {
  231. if (setting == mShowArrowButtons)
  232. return;
  233. mShowArrowButtons = setting;
  234. mScrollBar->mShowArrowButtons = setting;
  235. }
  236. void SceneWindow::setControlThumbProfile(GuiControlProfile* prof)
  237. {
  238. AssertFatal(prof, "SceneWindow::setControlThumbProfile: invalid thumb profile");
  239. if (prof == mThumbProfile)
  240. return;
  241. if (mAwake && mThumbProfile->mRefCount > 0)
  242. mThumbProfile->decRefCount();
  243. mThumbProfile = prof;
  244. if (mAwake)
  245. mThumbProfile->incRefCount();
  246. mScrollBar->setControlThumbProfile(prof);
  247. }
  248. void SceneWindow::setControlTrackProfile(GuiControlProfile* prof)
  249. {
  250. AssertFatal(prof, "SceneWindow::setControlTrackProfile: invalid track profile");
  251. if (prof == mTrackProfile)
  252. return;
  253. if (mAwake && mTrackProfile->mRefCount > 0)
  254. mTrackProfile->decRefCount();
  255. mTrackProfile = prof;
  256. if (mAwake)
  257. mTrackProfile->incRefCount();
  258. mScrollBar->setControlTrackProfile(prof);
  259. }
  260. void SceneWindow::setControlArrowProfile(GuiControlProfile* prof)
  261. {
  262. AssertFatal(prof, "SceneWindow::setControlArrowProfile: invalid Arrow profile");
  263. if (prof == mArrowProfile)
  264. return;
  265. if (mAwake && mArrowProfile->mRefCount > 0)
  266. mArrowProfile->decRefCount();
  267. mArrowProfile = prof;
  268. if (mAwake)
  269. mArrowProfile->incRefCount();
  270. mScrollBar->setControlArrowProfile(prof);
  271. }
  272. //-----------------------------------------------------------------------------
  273. void SceneWindow::setScene( Scene* pScene )
  274. {
  275. // Detach (if needed)
  276. resetScene();
  277. // Attach the Window.
  278. pScene->attachSceneWindow( this );
  279. // Set scene.
  280. mpScene = pScene;
  281. }
  282. //-----------------------------------------------------------------------------
  283. void SceneWindow::resetScene( void )
  284. {
  285. // Detach from scene (if attached).
  286. if ( getScene() )
  287. {
  288. getScene()->detachSceneWindow( this );
  289. }
  290. // Are we mounted to an object?
  291. if ( isCameraMounted() )
  292. {
  293. // Yes, so dismount object.
  294. dismount();
  295. }
  296. // Clear input event watched objects.
  297. mInputEventWatching.clear();
  298. // Reset scene.
  299. mpScene = NULL;
  300. }
  301. //-----------------------------------------------------------------------------
  302. void SceneWindow::setCameraPosition( const Vector2& position )
  303. {
  304. // Are we mounted to an object?
  305. if ( isCameraMounted() )
  306. {
  307. // Yes, so cannot use this command.
  308. Con::warnf("SceneWindow::setCameraPosition() - Cannot use this command when camera is mounted!");
  309. return;
  310. }
  311. // Stop Camera Move ( if any ).
  312. if ( mMovingCamera ) stopCameraMove();
  313. // Fetch the camera size.
  314. const Vector2 cameraSize = getCameraSize();
  315. // Set Camera Target.
  316. mCameraCurrent.mSourceArea = RectF( position.x - (cameraSize.x * 0.5f), position.y - (cameraSize.y * 0.5f), cameraSize.x, cameraSize.y );
  317. // Set Camera Target to Current.
  318. mCameraTarget = mCameraCurrent;
  319. //Update the Scroll Bar
  320. updateScrollBar();
  321. }
  322. //-----------------------------------------------------------------------------
  323. void SceneWindow::setCameraSize( const Vector2& size )
  324. {
  325. // Stop Camera Move ( if any ).
  326. if ( mMovingCamera ) stopCameraMove();
  327. // Fetch the current position.
  328. const Vector2 position = getCameraPosition();
  329. // Set Camera Target.
  330. mCameraCurrent.mSourceArea = RectF( position.x - (size.x * 0.5f), position.y - (size.y * 0.5f), size.x, size.y );
  331. // Set Camera Target to Current.
  332. mCameraTarget = mCameraCurrent;
  333. //Update the Scroll Bar
  334. updateScrollBar();
  335. }
  336. //-----------------------------------------------------------------------------
  337. void SceneWindow::setCameraArea( const RectF& cameraWindow )
  338. {
  339. // Are we mounted to an object?
  340. if ( isCameraMounted() )
  341. {
  342. // Yes, so cannot use this command.
  343. Con::warnf("SceneWindow::setCameraArea - Cannot use this command when camera is mounted!");
  344. return;
  345. }
  346. // Stop Camera Move ( if any ).
  347. if ( mMovingCamera ) stopCameraMove();
  348. // Set Camera Target.
  349. mCameraCurrent.mSourceArea = cameraWindow;
  350. mCameraCurrent.mCameraZoom = 1.0f;
  351. mCameraCurrent.mCameraAngle = 0.0f;
  352. // Set Camera Target to Current.
  353. mCameraTarget = mCameraCurrent;
  354. //Update the Scroll Bar
  355. updateScrollBar();
  356. }
  357. //-----------------------------------------------------------------------------
  358. void SceneWindow::setCameraZoom( const F32 zoomFactor )
  359. {
  360. // Stop Camera Move ( if any ).
  361. if ( mMovingCamera ) stopCameraMove();
  362. // Set Camera Target.
  363. mCameraCurrent.mCameraZoom = getMax( zoomFactor, 0.000001f );
  364. // Set Camera Target to Current.
  365. mCameraTarget = mCameraCurrent;
  366. //Update the Scroll Bar
  367. updateScrollBar();
  368. }
  369. //-----------------------------------------------------------------------------
  370. void SceneWindow::setCameraAngle( const F32 cameraAngle )
  371. {
  372. // Stop Camera Move ( if any ).
  373. if ( mMovingCamera ) stopCameraMove();
  374. // Set Camera Target.
  375. mCameraCurrent.mCameraAngle = mFmod( cameraAngle, b2_pi2 );
  376. // Set Camera Target to Current.
  377. mCameraTarget = mCameraCurrent;
  378. //Update the Scroll Bar
  379. updateScrollBar();
  380. }
  381. //-----------------------------------------------------------------------------
  382. void SceneWindow::setTargetCameraPosition( const Vector2& position )
  383. {
  384. // Are we mounted to an object?
  385. if ( isCameraMounted() )
  386. {
  387. // Yes, so cannot use this command.
  388. Con::warnf("SceneWindow::setTargetCameraPosition - Cannot use this command when camera is mounted!");
  389. return;
  390. }
  391. // Stop Camera Move ( if any ).
  392. if ( mMovingCamera ) stopCameraMove();
  393. // Fetch the camera size.
  394. const Vector2 cameraSize = getTargetCameraSize();
  395. // Set Camera Target.
  396. mCameraTarget.mSourceArea = RectF( position.x - (cameraSize.x*0.5f), position.y - (cameraSize.y*0.5f), cameraSize.x, cameraSize.y );
  397. //Update the Scroll Bar
  398. updateScrollBar();
  399. }
  400. //-----------------------------------------------------------------------------
  401. void SceneWindow::setTargetCameraSize( const Vector2& size )
  402. {
  403. // Stop Camera Move ( if any ).
  404. if ( mMovingCamera ) stopCameraMove();
  405. // Fetch the current position.
  406. const Vector2 position = getTargetCameraPosition();
  407. // Set Camera Target.
  408. mCameraTarget.mSourceArea = RectF( position.x - (size.x * 0.5f), position.y - (size.y * 0.5f), size.x, size.y );
  409. //Update the Scroll Bar
  410. updateScrollBar();
  411. }
  412. //-----------------------------------------------------------------------------
  413. void SceneWindow::setTargetCameraArea( const RectF& cameraWindow )
  414. {
  415. // Are we mounted to an object?
  416. if ( isCameraMounted() )
  417. {
  418. // Yes, so cannot use this command.
  419. Con::warnf("SceneWindow::setTargetCameraArea - Cannot use this command when camera is mounted!");
  420. return;
  421. }
  422. // Stop Camera Move ( if any ).
  423. if ( mMovingCamera ) stopCameraMove();
  424. // Set Camera Target.
  425. mCameraTarget.mSourceArea = cameraWindow;
  426. //Update the Scroll Bar
  427. updateScrollBar();
  428. }
  429. //-----------------------------------------------------------------------------
  430. void SceneWindow::setTargetCameraZoom( const F32 zoomFactor )
  431. {
  432. // Stop Camera Move ( if any ).
  433. if ( mMovingCamera ) stopCameraMove();
  434. // Set Camera Target.
  435. mCameraTarget.mCameraZoom = getMax( zoomFactor, 0.000001f );
  436. //Update the Scroll Bar
  437. updateScrollBar();
  438. }
  439. //-----------------------------------------------------------------------------
  440. void SceneWindow::setTargetCameraAngle( const F32 cameraAngle )
  441. {
  442. // Stop Camera Move ( if any ).
  443. if ( mMovingCamera ) stopCameraMove();
  444. // Set Camera Target.
  445. mCameraTarget.mCameraAngle = mFmod( cameraAngle, b2_pi2 );
  446. //Update the Scroll Bar
  447. updateScrollBar();
  448. }
  449. //-----------------------------------------------------------------------------
  450. void SceneWindow::setCameraInterpolationTime( const F32 interpolationTime )
  451. {
  452. // Set Interpolation Time.
  453. mCameraTransitionTime = interpolationTime;
  454. }
  455. //-----------------------------------------------------------------------------
  456. void SceneWindow::setCameraInterpolationMode( const CameraInterpolationMode interpolationMode )
  457. {
  458. // Set Interpolation Mode.
  459. mCameraInterpolationMode = interpolationMode;
  460. }
  461. //-----------------------------------------------------------------------------
  462. void SceneWindow::setProcessAudioListener(bool mval)
  463. {
  464. mProcessAudioListener = mval;
  465. }
  466. //-----------------------------------------------------------------------------
  467. void SceneWindow::startCameraMove( const F32 interpolationTime )
  468. {
  469. // Stop move if we're at target already.
  470. if ( mCameraCurrent.mSourceArea.point == mCameraTarget.mSourceArea.point &&
  471. mCameraCurrent.mSourceArea.extent == mCameraTarget.mSourceArea.extent &&
  472. mIsEqual( mCameraCurrent.mCameraZoom, mCameraTarget.mCameraZoom ) &&
  473. mIsEqual( mCameraTarget.mCameraAngle, mCameraTarget.mCameraAngle ) )
  474. {
  475. // Reset Camera Move.
  476. mMovingCamera = false;
  477. // Return here.
  478. return;
  479. }
  480. else
  481. {
  482. // Stop Camera Move ( if any ).
  483. if ( mMovingCamera ) stopCameraMove();
  484. }
  485. // Set Camera Interpolation Time.
  486. setCameraInterpolationTime( interpolationTime );
  487. // Zero Camera Time.
  488. zeroCameraTime();
  489. // Set Source Camera.
  490. mCameraSource = mCameraCurrent;
  491. // Set Camera Move.
  492. mMovingCamera = true;
  493. // Complete camera move if interpolate time is zero.
  494. if ( mIsZero(mCameraTransitionTime) ) completeCameraMove();
  495. // Queue Current Camera.
  496. mCameraQueue.push_back( mCameraCurrent );
  497. // Clamp Queue Size.
  498. if ( mCameraQueue.size() > mMaxQueueItems ) mCameraQueue.pop_front();
  499. //Update the Scroll Bar
  500. updateScrollBar();
  501. }
  502. //-----------------------------------------------------------------------------
  503. void SceneWindow::stopCameraMove( void )
  504. {
  505. // Quit if we're not moving.
  506. if ( !mMovingCamera ) return;
  507. // Reset Tick Camera Time.
  508. resetTickCameraTime();
  509. // Set target to Current.
  510. mCameraTarget = mCameraCurrent;
  511. // Reset Camera Move.
  512. mMovingCamera = false;
  513. //Update the Scroll Bar
  514. updateScrollBar();
  515. }
  516. //-----------------------------------------------------------------------------
  517. void SceneWindow::completeCameraMove( void )
  518. {
  519. // Quit if we're not moving.
  520. if ( !mMovingCamera ) return;
  521. // Reset Tick Camera Time.
  522. resetTickCameraTime();
  523. // Move straight to target.
  524. mCameraCurrent = mCameraTarget;
  525. // Reset Camera Move.
  526. mMovingCamera = false;
  527. //Update the Scroll Bar
  528. updateScrollBar();
  529. }
  530. //-----------------------------------------------------------------------------
  531. void SceneWindow::undoCameraMove( const F32 interpolationTime )
  532. {
  533. // Are we mounted to an object?
  534. if ( isCameraMounted() )
  535. {
  536. // Yes, so cannot use this command.
  537. Con::warnf("SceneWindow::undoCameraMove - Cannot use this command when camera is mounted!");
  538. return;
  539. }
  540. // Quit if we've got no queued targets.
  541. if ( mCameraQueue.size() == 0 ) return;
  542. // Stop Camera Move ( if any ).
  543. if ( mMovingCamera ) stopCameraMove();
  544. // Set Camera Interpolation Time.
  545. setCameraInterpolationTime( interpolationTime );
  546. // Zero Camera Time.
  547. zeroCameraTime();
  548. // Set Source Camera.
  549. mCameraSource = mCameraCurrent;
  550. // Set Camera Move.
  551. mMovingCamera = true;
  552. // Fetch Last Queued Camera Target.
  553. mCameraTarget = mCameraQueue.last();
  554. // Remove Last Target.
  555. mCameraQueue.pop_back();
  556. // Complete camera move if interpolate time is zero.
  557. if ( mIsZero(mCameraTransitionTime) ) completeCameraMove();
  558. //Update the Scroll Bar
  559. updateScrollBar();
  560. }
  561. //-----------------------------------------------------------------------------
  562. void SceneWindow::updateCamera( void )
  563. {
  564. // Calculate Normalised Time.
  565. const F32 normCameraTime = mRenderCameraTime / mCameraTransitionTime;
  566. // Have we finished the interpolation?
  567. if ( mGreaterThanOrEqual(normCameraTime, 1.0f) )
  568. {
  569. // Yes, so complete camera move.
  570. completeCameraMove();
  571. // Finish here.
  572. return;
  573. }
  574. if(!mCameraMounted)
  575. {
  576. // Interpolate Camera Window/Zoom.
  577. mCameraCurrent.mSourceArea.point.x = interpolate( mCameraSource.mSourceArea.point.x, mCameraTarget.mSourceArea.point.x, normCameraTime );
  578. mCameraCurrent.mSourceArea.point.y = interpolate( mCameraSource.mSourceArea.point.y, mCameraTarget.mSourceArea.point.y, normCameraTime );
  579. mCameraCurrent.mSourceArea.extent.x = interpolate( mCameraSource.mSourceArea.extent.x, mCameraTarget.mSourceArea.extent.x, normCameraTime );
  580. mCameraCurrent.mSourceArea.extent.y = interpolate( mCameraSource.mSourceArea.extent.y, mCameraTarget.mSourceArea.extent.y, normCameraTime );
  581. mCameraCurrent.mCameraAngle = interpolate( mCameraSource.mCameraAngle, mCameraTarget.mCameraAngle, normCameraTime );
  582. }
  583. //Do the zoom regardless of the mount state.
  584. mCameraCurrent.mCameraZoom = interpolate(mCameraSource.mCameraZoom, mCameraTarget.mCameraZoom, normCameraTime);
  585. //Update the Scroll Bar
  586. updateScrollBar();
  587. }
  588. //-----------------------------------------------------------------------------
  589. F32 SceneWindow::interpolate( F32 from, F32 to, F32 delta )
  590. {
  591. // Linear.
  592. if ( mCameraInterpolationMode == LINEAR )
  593. return mLerp( from, to, delta );
  594. // Sigmoid.
  595. else if ( mCameraInterpolationMode == SIGMOID )
  596. return mSmoothStep( from, to, delta );
  597. // Hmmm...
  598. else
  599. return from;
  600. }
  601. //-----------------------------------------------------------------------------
  602. void SceneWindow::startCameraShake( const F32 magnitude, const F32 time )
  603. {
  604. // Is the time zero?
  605. if ( mIsZero( time ) && mIsZero( magnitude ) )
  606. {
  607. // Yes, so simply stop the camera shaking.
  608. stopCameraShake();
  609. // Finish here.
  610. return;
  611. }
  612. // Set Current Shake.
  613. mCurrentShake = mFabs(magnitude);
  614. // Set Shake Life.
  615. mShakeLife = time;
  616. // Calculate Shake Ramp.
  617. mShakeRamp = mCurrentShake / mShakeLife;
  618. // Flag camera shaking.
  619. mCameraShaking = true;
  620. }
  621. //-----------------------------------------------------------------------------
  622. void SceneWindow::stopCameraShake( void )
  623. {
  624. // Flag camera not shaking.
  625. mCameraShaking = false;
  626. // Reset Shake Offset.
  627. mCameraShakeOffset.setZero();
  628. }
  629. //-----------------------------------------------------------------------------
  630. void SceneWindow::mount( SceneObject* pSceneObject, const Vector2& mountOffset, const F32 mountForce, const bool sendToMount, const bool mountAngle )
  631. {
  632. // Sanity!
  633. AssertFatal( pSceneObject != NULL, "Scene object cannot be NULL." );
  634. // Cannot mount if not in a scene.
  635. if ( !mpScene )
  636. {
  637. // Warn!
  638. Con::warnf("Cannot mount scene window (%d) to a scene object (%d) if scene window is not attached to a scene.", getId(), pSceneObject->getId() );
  639. return;
  640. }
  641. // Fetch objects' scene.
  642. const Scene* pScene = pSceneObject->getScene();
  643. // Scene object must be in a scene.
  644. if ( !pScene )
  645. {
  646. // Warn!
  647. Con::warnf("Cannot mount scene window (%d) to a scene object (%d) that is not in a scene.", getId(), pSceneObject->getId() );
  648. return;
  649. }
  650. // Scene object must be in same scene as the one the scene window is attached to.
  651. if ( pScene != mpScene )
  652. {
  653. // Warn!
  654. Con::warnf("Cannot mount scene window (%d) to a scene object (%d) that are not using the same scene.", getId(), pSceneObject->getId() );
  655. return;
  656. }
  657. // Are we mounted to an object?
  658. if ( isCameraMounted() )
  659. {
  660. // Yes, so dismount object.
  661. dismount();
  662. }
  663. //Are we using scroll bars? If so that's done now.
  664. mShowScrollBar = false;
  665. // Set Mount Object Reference.
  666. mpMountedTo = pSceneObject;
  667. // Store Mount Offset.
  668. mMountOffset = mountOffset;
  669. // Set Mount Force.
  670. mMountForce = mountForce;
  671. // Set Mount Angle.
  672. mMountAngle = mountAngle;
  673. // Add Camera Mount Reference.
  674. pSceneObject->addCameraMountReference( this );
  675. // Flag Camera mounted.
  676. mCameraMounted = true;
  677. // Send directly to mount (if selected).
  678. if ( sendToMount )
  679. {
  680. // Fetch Mount Position.
  681. const Vector2& mountPos = mpMountedTo->getBody()->GetWorldPoint( mountOffset );
  682. // Calculate Window Half-Dimensions.
  683. const F32 halfWidth = mCameraCurrent.mSourceArea.len_x() * 0.5f;
  684. const F32 halfHeight = mCameraCurrent.mSourceArea.len_y() * 0.5f;
  685. // Set Current View to Object Position.
  686. mCameraCurrent.mSourceArea.point.set( mountPos.x - halfWidth, mountPos.y - halfHeight );
  687. }
  688. // Reset Tick Camera Position.
  689. resetTickCameraPosition();
  690. }
  691. //-----------------------------------------------------------------------------
  692. void SceneWindow::dismount( void )
  693. {
  694. // Nothing to do if we're not mounted!
  695. if (!isCameraMounted() )
  696. return;
  697. // Remove Camera Mount Reference.
  698. mpMountedTo->removeCameraMountReference();
  699. // Reset Camera Object Mount.
  700. mpMountedTo = NULL;
  701. // Flag Camera not mounted.
  702. mCameraMounted = false;
  703. // Reset Tick Camera Position.
  704. resetTickCameraPosition();
  705. }
  706. //-----------------------------------------------------------------------------
  707. void SceneWindow::dismountMe(SceneObject* pSceneObject)
  708. {
  709. // Are we mounted to the specified object?
  710. if (isCameraMounted() && pSceneObject != mpMountedTo)
  711. {
  712. // No, so warn.
  713. Con::warnf("SceneWindow::dismountMe() - Object is not mounted by the camera!");
  714. return;
  715. }
  716. // Dismount Object.
  717. dismount();
  718. }
  719. //-----------------------------------------------------------------------------
  720. void SceneWindow::setViewLimitOn( const Vector2& limitMin, const Vector2& limitMax )
  721. {
  722. // Activate View Limit.
  723. mViewLimitActive = true;
  724. // Set View Limit Min/Max.
  725. mViewLimitMin = limitMin;
  726. mViewLimitMax = limitMax;
  727. // Calculate Camera Area.
  728. mViewLimitArea = mViewLimitMax - mViewLimitMin;
  729. //Update the Scroll Bar
  730. updateScrollBar();
  731. }
  732. //-----------------------------------------------------------------------------
  733. void SceneWindow::clampCameraViewLimit( void )
  734. {
  735. // Finish if the view-limit is not on or the camera is moving.
  736. if ( !mViewLimitActive || mMovingCamera )
  737. return;
  738. // Calculate Current Camera View.
  739. calculateCameraView( &mCameraCurrent );
  740. // Calculate the source and destination centres.
  741. const Point2F sourceCentre = mCameraCurrent.mSourceArea.centre();
  742. const Point2F destinationCentre = mCameraCurrent.mDestinationArea.centre();
  743. // Are the source and destination areas the same?
  744. if ( sourceCentre != destinationCentre )
  745. {
  746. // No, so adjust the source position to be at the same position as the destination i.e. don't change the source area.
  747. mCameraCurrent.mSourceArea.point += destinationCentre - sourceCentre;
  748. }
  749. }
  750. //-----------------------------------------------------------------------------
  751. void SceneWindow::setShowScrollBar(bool setting)
  752. {
  753. //Warn if we don't have a view limit
  754. if(setting && !mViewLimitActive)
  755. {
  756. Con::warnf("SceneWindow::setShowScrollBar - View Limit must be turned off for scroll bars to appear!");
  757. }
  758. // Unmount the camera if it is mounted
  759. if(setting && isCameraMounted())
  760. {
  761. dismount();
  762. }
  763. mShowScrollBar = setting;
  764. if(setting)
  765. {
  766. //now wake the scrollbar
  767. if(mAwake)
  768. {
  769. mScrollBar->onWake();
  770. }
  771. updateScrollBar();
  772. }
  773. }
  774. void SceneWindow::updateScrollBar()
  775. {
  776. if (mShowScrollBar)
  777. {
  778. mScrollBar->computeSizes();
  779. }
  780. }
  781. //-----------------------------------------------------------------------------
  782. void SceneWindow::setObjectInputEventFilter( const U32 groupMask, const U32 layerMask, const bool useInvisible )
  783. {
  784. // Set Object Mouse Event Filter.
  785. mInputEventGroupMaskFilter = groupMask;
  786. mInputEventLayerMaskFilter = layerMask;
  787. mInputEventInvisibleFilter = useInvisible;
  788. }
  789. //-----------------------------------------------------------------------------
  790. void SceneWindow::setObjectInputEventGroupFilter( const U32 groupMask )
  791. {
  792. mInputEventGroupMaskFilter = groupMask;
  793. // Clear existing watched input events.
  794. clearWatchedInputEvents();
  795. }
  796. //-----------------------------------------------------------------------------
  797. void SceneWindow::setObjectInputEventLayerFilter( const U32 layerMask )
  798. {
  799. mInputEventLayerMaskFilter = layerMask;
  800. // Clear existing watched input events.
  801. clearWatchedInputEvents();
  802. }
  803. //-----------------------------------------------------------------------------
  804. void SceneWindow::setObjectInputEventInvisibleFilter( const bool useInvisible )
  805. {
  806. mInputEventInvisibleFilter = useInvisible;
  807. // Clear existing watched input events.
  808. clearWatchedInputEvents();
  809. }
  810. //-----------------------------------------------------------------------------
  811. void SceneWindow::addInputListener( SimObject* pSimObject )
  812. {
  813. // Sanity!
  814. AssertFatal( pSimObject != NULL, "SceneWindow::addInputEventListener() - Cannot add NULL object as input event listener." );
  815. // Ignore if the object is already a listener.
  816. if ( mInputListeners.find( pSimObject ) != mInputListeners.end() )
  817. return;
  818. // Add as listener.
  819. mInputListeners.addObject( pSimObject );
  820. }
  821. //-----------------------------------------------------------------------------
  822. void SceneWindow::removeInputListener( SimObject* pSimObject )
  823. {
  824. mInputListeners.removeObject( pSimObject );
  825. }
  826. //-----------------------------------------------------------------------------
  827. void SceneWindow::setMousePosition( const Vector2& mousePosition )
  828. {
  829. // Fetch Canvas.
  830. GuiCanvas* pCanvas = getRoot();
  831. // Canvas available?
  832. if ( pCanvas )
  833. {
  834. // Are we bound to a scene?
  835. if ( getScene() )
  836. {
  837. Vector2 windowMousePosition;
  838. // Yes, so convert window into scene coordinates...
  839. sceneToWindowPoint( mousePosition, windowMousePosition );
  840. // Copy into a compatible format for TGE.
  841. Point2I localWindowPosition( S32(windowMousePosition.x), S32(windowMousePosition.y) );
  842. // Set Cursor Position.
  843. pCanvas->setCursorPos( localToGlobalCoord(localWindowPosition) );
  844. }
  845. else
  846. {
  847. // No, so error.
  848. Con::warnf("SceneObject::setMousePosition() - No scene attached to window!");
  849. return;
  850. }
  851. }
  852. }
  853. //-----------------------------------------------------------------------------
  854. Vector2 SceneWindow::getMousePosition( void )
  855. {
  856. // Calculate Current Camera View.
  857. calculateCameraView( &mCameraCurrent );
  858. // Fetch Canvas.
  859. GuiCanvas* pCanvas = getRoot();
  860. // World Mouse Position.
  861. Vector2 worldMousePoint(0, 0);
  862. // Canvas available?
  863. if ( pCanvas )
  864. {
  865. // Yes, so fetch local GUI coordinates.
  866. const Vector2 localGuiPoint = globalToLocalCoord( pCanvas->getCursorPos() );
  867. // Are we bound to a scene?
  868. if ( getScene() )
  869. {
  870. // Yes, so convert window into scene coordinates...
  871. windowToScenePoint(localGuiPoint, worldMousePoint);
  872. }
  873. else
  874. {
  875. // No, so use window screen coordinates.
  876. worldMousePoint = localGuiPoint;
  877. }
  878. }
  879. #if 0
  880. else
  881. {
  882. // No, so warn
  883. Con::warnf("SceneWindow::getMousePosition() - Window not attached to canvas!" );
  884. }
  885. #endif
  886. // Return World Mouse Position.
  887. return worldMousePoint;
  888. }
  889. //-----------------------------------------------------------------------------
  890. void SceneWindow::windowToScenePoint( const Vector2& srcPoint, Vector2& dstPoint ) const
  891. {
  892. // Return Conversion.
  893. dstPoint.Set( (srcPoint.x * mCameraCurrent.mSceneWindowScale.x) + mCameraCurrent.mSceneMin.x, mCameraCurrent.mSceneMax.y - (srcPoint.y * mCameraCurrent.mSceneWindowScale.y) );
  894. }
  895. //-----------------------------------------------------------------------------
  896. void SceneWindow::sceneToWindowPoint( const Vector2& srcPoint, Vector2& dstPoint ) const
  897. {
  898. // Return Conversion.
  899. dstPoint.Set( (srcPoint.x - mCameraCurrent.mSceneMin.x) / mCameraCurrent.mSceneWindowScale.x, (mCameraCurrent.mSceneMax.y - srcPoint.y) / mCameraCurrent.mSceneWindowScale.y );
  900. }
  901. //-----------------------------------------------------------------------------
  902. bool SceneWindow::dispatchInputEvent( StringTableEntry name, const GuiEvent& event )
  903. {
  904. // Debug Profiling.
  905. PROFILE_SCOPE(SceneWindow_DispatchInputEvent);
  906. // Dispatch input event to window if appropriate.
  907. bool windowConsumedEvent = false;
  908. if ( getUseWindowInputEvents() )
  909. windowConsumedEvent = sendWindowInputEvent( name, event );
  910. // Dispatch input event to scene objects if appropriate.
  911. bool objectConsumedEvent = false;
  912. if ( getUseObjectInputEvents() )
  913. objectConsumedEvent = sendObjectInputEvent( name, event );
  914. return !(windowConsumedEvent || objectConsumedEvent);
  915. }
  916. //-----------------------------------------------------------------------------
  917. bool SceneWindow::sendWindowInputEvent( StringTableEntry name, const GuiEvent& event )
  918. {
  919. // Debug Profiling.
  920. PROFILE_SCOPE(SceneWindow_SendWindowInputEvent);
  921. bool consumed = false;
  922. Vector2 worldMousePoint;
  923. // Calculate Current Camera View.
  924. calculateCameraView( &mCameraCurrent );
  925. // Convert to local gui coordinates.
  926. const Vector2 localGuiPoint = globalToLocalCoord(event.mousePoint);
  927. // Are we bound to a scene?
  928. if ( getScene() )
  929. {
  930. // Yes, so convert window into scene coordinates...
  931. windowToScenePoint(localGuiPoint, worldMousePoint);
  932. }
  933. else
  934. {
  935. // No, so use window screen coordinates.
  936. worldMousePoint = localGuiPoint;
  937. }
  938. // Argument Buffers.
  939. char argBuffer[3][64];
  940. // Format Event-Modifier Buffer.
  941. dSprintf(argBuffer[0], 64, "%d", event.eventID);
  942. // Format Mouse-Position Buffer.
  943. dSprintf(argBuffer[1], 64, "%g %g", worldMousePoint.x, worldMousePoint.y);
  944. // Format Mouse-Click Count Buffer.
  945. dSprintf(argBuffer[2], 64, "%d", event.mouseClickCount);
  946. // Call Scripts.
  947. consumed = dAtob(Con::executef(this, 4, name, argBuffer[0], argBuffer[1], argBuffer[2]));
  948. // Iterate listeners.
  949. for( SimSet::iterator listenerItr = mInputListeners.begin(); listenerItr != mInputListeners.end(); ++listenerItr )
  950. {
  951. // Call scripts on listener.
  952. Con::executef( *listenerItr, 4, name, argBuffer[0], argBuffer[1], argBuffer[2] );
  953. }
  954. return consumed;
  955. }
  956. //-----------------------------------------------------------------------------
  957. bool SceneWindow::sendObjectInputEvent( StringTableEntry name, const GuiEvent& event )
  958. {
  959. // Debug Profiling.
  960. PROFILE_SCOPE(SceneWindow_SendObjectInputEvent);
  961. bool consumed = false;
  962. // Finish if we're not bound to a scene?
  963. if ( !getScene() ) return consumed;
  964. // Only process appropriate input events.
  965. if ( !( name == inputEventDownName ||
  966. name == inputEventUpName ||
  967. name == inputEventMovedName ||
  968. name == inputEventDraggedName ) )
  969. return consumed;
  970. // Convert Event-Position into scene coordinates.
  971. Vector2 worldMousePoint;
  972. windowToScenePoint(Vector2(globalToLocalCoord(event.mousePoint)), worldMousePoint);
  973. // Fetch old pick count.
  974. const U32 oldPickCount = (U32)mInputEventWatching.size();
  975. // Fetch world query and clear results.
  976. WorldQuery* pWorldQuery = getScene()->getWorldQuery( true );
  977. // Set filter.
  978. WorldQueryFilter queryFilter( mInputEventLayerMaskFilter, mInputEventGroupMaskFilter, true, mInputEventInvisibleFilter, true, true );
  979. pWorldQuery->setQueryFilter( queryFilter );
  980. // Perform world query.
  981. const U32 newPickCount = pWorldQuery->anyQueryPoint( worldMousePoint );
  982. // Early-out if nothing to do.
  983. if ( newPickCount == 0 && oldPickCount == 0 )
  984. return consumed;
  985. // Fetch results.
  986. mInputEventQuery = pWorldQuery->getQueryResults();
  987. pWorldQuery->clearQuery();
  988. // Determine "enter" events.
  989. for( U32 newIndex = 0; newIndex < newPickCount; ++newIndex )
  990. {
  991. // Fetch new scene object.
  992. SceneObject* pNewSceneObject = mInputEventQuery[newIndex].mpSceneObject;
  993. // Ignore object if it's not using input events.
  994. // NOTE:- We only check this for "enter" events in-case the option is
  995. // changed whilst it's currently picked. We want to guarantee
  996. // that any "enter" event is paired with a "leave" event.
  997. if ( !pNewSceneObject->getUseInputEvents() )
  998. continue;
  999. bool alreadyPresent = false;
  1000. for ( U32 oldIndex = 0; oldIndex < oldPickCount; ++oldIndex )
  1001. {
  1002. // Skip if scene object is not present...
  1003. if ( mInputEventWatching[oldIndex] != pNewSceneObject )
  1004. continue;
  1005. // Flag as already present.
  1006. alreadyPresent = true;
  1007. break;
  1008. }
  1009. // Add scene object as entering if not already present.
  1010. if ( !alreadyPresent )
  1011. mInputEventEntering.push_back( pNewSceneObject );
  1012. }
  1013. // Determine "leave" events.
  1014. for ( U32 oldIndex = 0; oldIndex < oldPickCount; ++oldIndex )
  1015. {
  1016. // Fetch old scene object.
  1017. SceneObject* pOldSceneObject = dynamic_cast<SceneObject*>( mInputEventWatching[oldIndex] );
  1018. // Sanity!
  1019. AssertFatal( pOldSceneObject != NULL, "Invalid object found in mouse-event pick vector." );
  1020. bool stillPresent = false;
  1021. for( U32 newIndex = 0; newIndex < newPickCount; ++newIndex )
  1022. {
  1023. // Skip if scene object is not present.
  1024. if ( mInputEventQuery[newIndex].mpSceneObject != pOldSceneObject )
  1025. continue;
  1026. // Flag as still present.
  1027. stillPresent = true;
  1028. break;
  1029. }
  1030. // Add scene object as leaving if not still present.
  1031. if ( !stillPresent )
  1032. mInputEventLeaving.push_back( pOldSceneObject );
  1033. }
  1034. for ( U32 index = 0; index < (U32)mInputEventQuery.size(); ++index )
  1035. {
  1036. // Fetch scene object.
  1037. SceneObject* pSceneObject = mInputEventQuery[index].mpSceneObject;
  1038. // Ignore object if it's not using input events.
  1039. if ( !pSceneObject->getUseInputEvents() )
  1040. continue;
  1041. // Emit event.
  1042. consumed = pSceneObject->onInputEvent( name, event, worldMousePoint );
  1043. }
  1044. // Process "leave" events.
  1045. for ( U32 index = 0; index < (U32)mInputEventLeaving.size(); ++index )
  1046. {
  1047. // Fetch scene object.
  1048. SceneObject* pSceneObject = mInputEventLeaving[index];
  1049. // Emit event.
  1050. pSceneObject->onInputEvent( inputEventLeaveName, event, worldMousePoint );
  1051. // Remove scene object.
  1052. mInputEventWatching.removeObject( pSceneObject );
  1053. }
  1054. // Process "enter" events.
  1055. for ( U32 index = 0; index < (U32)mInputEventEntering.size(); ++index )
  1056. {
  1057. // Fetch scene object.
  1058. SceneObject* pSceneObject = mInputEventEntering[index];
  1059. // Emit event.
  1060. pSceneObject->onInputEvent( inputEventEnterName, event, worldMousePoint );
  1061. // Process "moved" or "dragged" events.
  1062. if ( name == inputEventMovedName || name == inputEventDraggedName )
  1063. consumed = pSceneObject->onInputEvent( name, event, worldMousePoint );
  1064. // Add scene object.
  1065. mInputEventWatching.addObject( pSceneObject );
  1066. }
  1067. // Clear input event vectors.
  1068. mInputEventQuery.clear();
  1069. mInputEventEntering.clear();
  1070. mInputEventLeaving.clear();
  1071. return consumed;
  1072. }
  1073. //-----------------------------------------------------------------------------
  1074. void SceneWindow::onTouchEnter( const GuiEvent& event )
  1075. {
  1076. // Dispatch input event.
  1077. dispatchInputEvent(mouseEventEnterName, event);
  1078. }
  1079. //-----------------------------------------------------------------------------
  1080. void SceneWindow::onTouchLeave( const GuiEvent& event )
  1081. {
  1082. if (mShowScrollBar)
  1083. {
  1084. mScrollBar->onTouchLeave(event);
  1085. }
  1086. // Dispatch input event.
  1087. dispatchInputEvent(mouseEventLeaveName, event);
  1088. }
  1089. //-----------------------------------------------------------------------------
  1090. void SceneWindow::onTouchDown( const GuiEvent& event )
  1091. {
  1092. if (mShowScrollBar)
  1093. {
  1094. mScrollBar->curHitRegion = mScrollBar->findHitRegion(mScrollBar->globalToLocalCoord(event.mousePoint));
  1095. if (mScrollBar->curHitRegion != GuiScrollCtrl::Content)
  1096. {
  1097. setUpdate();
  1098. mScrollBar->onTouchDown(event);
  1099. return;
  1100. }
  1101. }
  1102. // Lock Mouse (if necessary).
  1103. if(mLockMouse)
  1104. mouseLock();
  1105. // Dispatch input event.
  1106. mPassEventThru = dispatchInputEvent( inputEventDownName, event);
  1107. }
  1108. //-----------------------------------------------------------------------------
  1109. void SceneWindow::onTouchUp( const GuiEvent& event )
  1110. {
  1111. // Lock Mouse (if necessary).
  1112. if(mLockMouse)
  1113. mouseUnlock();
  1114. // Dispatch input event.
  1115. mPassEventThru = dispatchInputEvent(inputEventUpName, event);
  1116. }
  1117. //-----------------------------------------------------------------------------
  1118. void SceneWindow::onTouchMove( const GuiEvent& event )
  1119. {
  1120. if (mShowScrollBar)
  1121. {
  1122. mScrollBar->onTouchMove(event);
  1123. }
  1124. // Dispatch input event.
  1125. mPassEventThru = dispatchInputEvent(inputEventMovedName, event);
  1126. }
  1127. //-----------------------------------------------------------------------------
  1128. void SceneWindow::onTouchDragged( const GuiEvent& event )
  1129. {
  1130. // Dispatch input event.
  1131. mPassEventThru = dispatchInputEvent(inputEventDraggedName, event);
  1132. }
  1133. //-----------------------------------------------------------------------------
  1134. void SceneWindow::onMiddleMouseDown( const GuiEvent& event )
  1135. {
  1136. // Lock Mouse (if necessary).
  1137. if(mLockMouse)
  1138. mouseLock();
  1139. // Dispatch input event.
  1140. mPassEventThru = dispatchInputEvent(mouseEventMiddleMouseDownName, event);
  1141. }
  1142. //-----------------------------------------------------------------------------
  1143. void SceneWindow::onMiddleMouseUp( const GuiEvent& event )
  1144. {
  1145. // Lock Mouse (if necessary).
  1146. if(mLockMouse)
  1147. mouseUnlock();
  1148. // Dispatch input event.
  1149. mPassEventThru = dispatchInputEvent(mouseEventMiddleMouseUpName, event);
  1150. }
  1151. //-----------------------------------------------------------------------------
  1152. void SceneWindow::onMiddleMouseDragged( const GuiEvent& event )
  1153. {
  1154. // Dispatch input event.
  1155. mPassEventThru = dispatchInputEvent(mouseEventMiddleMouseDraggedName, event);
  1156. }
  1157. //-----------------------------------------------------------------------------
  1158. void SceneWindow::onRightMouseDown( const GuiEvent& event )
  1159. {
  1160. // Lock Mouse (if necessary).
  1161. if(mLockMouse)
  1162. mouseLock();
  1163. // Dispatch input event.
  1164. mPassEventThru = dispatchInputEvent(mouseEventRightMouseDownName, event);
  1165. }
  1166. //-----------------------------------------------------------------------------
  1167. void SceneWindow::onRightMouseUp( const GuiEvent& event )
  1168. {
  1169. // Lock Mouse (if necessary).
  1170. if(mLockMouse)
  1171. mouseUnlock();
  1172. // Dispatch input event.
  1173. mPassEventThru = dispatchInputEvent(mouseEventRightMouseUpName, event);
  1174. }
  1175. //-----------------------------------------------------------------------------
  1176. void SceneWindow::onRightMouseDragged( const GuiEvent& event )
  1177. {
  1178. // Dispatch input event.
  1179. mPassEventThru = dispatchInputEvent(mouseEventRightMouseDraggedName, event);
  1180. }
  1181. //-----------------------------------------------------------------------------
  1182. void SceneWindow::onMouseWheelUp( const GuiEvent& event )
  1183. {
  1184. if (mShowScrollBar && ((mMouseWheelScrolls && !(event.modifier & SI_SHIFT)) || (!mMouseWheelScrolls && (event.modifier & SI_SHIFT))))
  1185. {
  1186. mScrollBar->onMouseWheelUp(event);
  1187. return;
  1188. }
  1189. // Call Parent.
  1190. Parent::onMouseWheelUp( event );
  1191. // Dispatch input event.
  1192. mPassEventThru = dispatchInputEvent(mouseEventWheelUpName, event);
  1193. }
  1194. //-----------------------------------------------------------------------------
  1195. void SceneWindow::onMouseWheelDown( const GuiEvent& event )
  1196. {
  1197. if (mShowScrollBar && ((mMouseWheelScrolls && !(event.modifier & SI_SHIFT)) || (!mMouseWheelScrolls && (event.modifier & SI_SHIFT))))
  1198. {
  1199. mScrollBar->onMouseWheelDown(event);
  1200. return;
  1201. }
  1202. // Call Parent.
  1203. Parent::onMouseWheelDown( event );
  1204. // Dispatch input event.
  1205. mPassEventThru = dispatchInputEvent(mouseEventWheelDownName, event);
  1206. }
  1207. //-----------------------------------------------------------------------------
  1208. void SceneWindow::calculateCameraMount( const F32 elapsedTime )
  1209. {
  1210. // Debug Profiling.
  1211. PROFILE_SCOPE(SceneWindow_CalculateCameraMount);
  1212. // Fetch Mount Position.
  1213. const Vector2& mountPos = mpMountedTo->getBody()->GetWorldPoint( mMountOffset );
  1214. // Set Pre-Tick Position.
  1215. mPreTickPosition = mPostTickPosition;
  1216. // Set Current Camera Position.
  1217. mCameraCurrent.mSourceArea.point = mPreTickPosition;
  1218. // Calculate Window Half-Dimensions.
  1219. const F32 halfWidth = mCameraCurrent.mSourceArea.len_x() * 0.5f;
  1220. const F32 halfHeight = mCameraCurrent.mSourceArea.len_y() * 0.5f;
  1221. // Calculate Target Position.
  1222. const Point2F targetPos = Point2F( mountPos.x - halfWidth, mountPos.y - halfHeight );
  1223. // Mount the angle?
  1224. if ( mMountAngle )
  1225. mCameraCurrent.mCameraAngle = -mpMountedTo->getAngle();
  1226. // Rigid Mount?
  1227. if ( mIsZero( mMountForce ) )
  1228. {
  1229. // Yes, so easy post-tick position.
  1230. mPostTickPosition = targetPos;
  1231. return;
  1232. }
  1233. // Calculate Time/Force Product.
  1234. const F32 timeForce = elapsedTime * mMountForce;
  1235. // Will we exceed our step?
  1236. if ( timeForce > 1.0f )
  1237. {
  1238. // Yes, so clamp at step.
  1239. mPostTickPosition = targetPos;
  1240. return;
  1241. }
  1242. else
  1243. {
  1244. // No, so calculate Direction to move.
  1245. const Point2F direction = (targetPos - mPreTickPosition) * timeForce;
  1246. // Calculate post-tick position.
  1247. mPostTickPosition = mPreTickPosition + direction;
  1248. return;
  1249. }
  1250. }
  1251. //-----------------------------------------------------------------------------
  1252. void SceneWindow::calculateCameraView( CameraView* pCameraView )
  1253. {
  1254. // Debug Profiling.
  1255. PROFILE_SCOPE(SceneWindow_CalculateCameraView);
  1256. // Calculate Zoom Reciprocal.
  1257. const F32 zoomRecip = pCameraView->mCameraZoom > 0.0f ? 1.0f / pCameraView->mCameraZoom : pCameraView->mCameraZoom;
  1258. // Calculate Zoom X/Y Factors.
  1259. const F32 zoomFactorX = (pCameraView->mSourceArea.len_x() - (pCameraView->mSourceArea.len_x() * zoomRecip))/2;
  1260. const F32 zoomFactorY = (pCameraView->mSourceArea.len_y() - (pCameraView->mSourceArea.len_y() * zoomRecip))/2;
  1261. // Fetch Camera View.
  1262. pCameraView->mDestinationArea = pCameraView->mSourceArea;
  1263. // Inset Window by Zoom Factor (if it's big enough to do so).
  1264. if ( pCameraView->mDestinationArea.extent.x > (zoomFactorX*2.0f) &&
  1265. pCameraView->mDestinationArea.extent.y > (zoomFactorY*2.0f) )
  1266. {
  1267. pCameraView->mDestinationArea.inset( zoomFactorX, zoomFactorY );
  1268. }
  1269. // Ensure we've got a valid window.
  1270. if ( !pCameraView->mDestinationArea.isValidRect() )
  1271. // Make it real!
  1272. pCameraView->mDestinationArea.extent = Point2F(1,1);
  1273. // Calculate Scene Min/Max.
  1274. pCameraView->mSceneMin.x = pCameraView->mDestinationArea.point.x;
  1275. pCameraView->mSceneMin.y = pCameraView->mDestinationArea.point.y;
  1276. pCameraView->mSceneMax.x = pCameraView->mDestinationArea.point.x + pCameraView->mDestinationArea.len_x();
  1277. pCameraView->mSceneMax.y = pCameraView->mDestinationArea.point.y + pCameraView->mDestinationArea.len_y();
  1278. // Is View Limit Active?
  1279. if ( mViewLimitActive )
  1280. {
  1281. // Yes, so is the limit area X less than the current view X?
  1282. if ( mViewLimitArea.x < pCameraView->mDestinationArea.len_x() )
  1283. {
  1284. // Yes, so calculate center of view.
  1285. const F32 viewCenterX = mViewLimitMin.x + ( mViewLimitArea.x * 0.5f );
  1286. // Half Camera Width.
  1287. const F32 halfCameraX = pCameraView->mDestinationArea.len_x() * 0.5f;
  1288. // Calculate Min/Max X.
  1289. pCameraView->mSceneMin.x = viewCenterX - halfCameraX;
  1290. pCameraView->mSceneMax.x = viewCenterX + halfCameraX;
  1291. }
  1292. else
  1293. {
  1294. // No, so calculate window min overlap.
  1295. const F32 windowMinOverlapX = getMax(0.0f, mViewLimitMin.x - pCameraView->mSceneMin.x);
  1296. // Calculate window max overlap.
  1297. const F32 windowMaxOverlapX = getMin(0.0f, mViewLimitMax.x - pCameraView->mSceneMax.x);
  1298. // Adjust Window.
  1299. pCameraView->mSceneMin.x += windowMinOverlapX + windowMaxOverlapX;
  1300. pCameraView->mSceneMax.x += windowMinOverlapX + windowMaxOverlapX;
  1301. }
  1302. // Is the limit area Y less than the current view Y?
  1303. if ( mViewLimitArea.y < pCameraView->mDestinationArea.len_y() )
  1304. {
  1305. // Yes, so calculate center of view.
  1306. const F32 viewCenterY = mViewLimitMin.y + ( mViewLimitArea.y * 0.5f );
  1307. // Half Camera Height.
  1308. const F32 halfCameraY = pCameraView->mDestinationArea.len_y() * 0.5f;
  1309. // Calculate Min/Max Y.
  1310. pCameraView->mSceneMin.y = viewCenterY - halfCameraY;
  1311. pCameraView->mSceneMax.y = viewCenterY + halfCameraY;
  1312. }
  1313. else
  1314. {
  1315. // No, so calculate window min overlap.
  1316. const F32 windowMinOverlapY = getMax(0.0f, mViewLimitMin.y - pCameraView->mSceneMin.y);
  1317. // Calculate window max overlap.
  1318. const F32 windowMaxOverlapY = getMin(0.0f, mViewLimitMax.y - pCameraView->mSceneMax.y);
  1319. // Adjust Window.
  1320. pCameraView->mSceneMin.y += windowMinOverlapY + windowMaxOverlapY;
  1321. pCameraView->mSceneMax.y += windowMinOverlapY + windowMaxOverlapY;
  1322. }
  1323. // Recalculate destination area.
  1324. pCameraView->mDestinationArea.point = pCameraView->mSceneMin;
  1325. pCameraView->mDestinationArea.extent = pCameraView->mSceneMax - pCameraView->mSceneMin;
  1326. }
  1327. // Calculate Scene Window Scale.
  1328. pCameraView->mSceneWindowScale.x = (pCameraView->mSceneMax.x - pCameraView->mSceneMin.x) / mBounds.len_x();
  1329. pCameraView->mSceneWindowScale.y = (pCameraView->mSceneMax.y - pCameraView->mSceneMin.y) / mBounds.len_y();
  1330. }
  1331. //-----------------------------------------------------------------------------
  1332. void SceneWindow::resize(const Point2I &newPosition, const Point2I &newExtent)
  1333. {
  1334. // Resize Parent.
  1335. Parent::resize( newPosition, newExtent);
  1336. //Update the Scroll Bar
  1337. updateScrollBar();
  1338. // Argument Buffer.
  1339. char argBuffer[64];
  1340. // Format Buffer.
  1341. dSprintf( argBuffer, 64, "%d %d %d %d", newPosition.x, newPosition.y, newExtent.x, newExtent.y );
  1342. // Resize Callback.
  1343. if(this->getNamespace())
  1344. Con::executef( this, 2, "onExtentChange", argBuffer );
  1345. }
  1346. //-----------------------------------------------------------------------------
  1347. void SceneWindow::processTick( void )
  1348. {
  1349. // Debug Profiling.
  1350. PROFILE_SCOPE(SceneWindow_ProcessTick);
  1351. Point2F PreMove_CameraPos = mCameraCurrent.mSourceArea.centre();
  1352. F32 PreMove_CameraZoom = mCameraCurrent.mCameraZoom;
  1353. // Are we moving the camera.
  1354. if ( mMovingCamera )
  1355. {
  1356. // Yes, so add Elapsed Time (scaled appropriately).
  1357. mCurrentCameraTime += Tickable::smTickSec;
  1358. // Update Tick Camera Time.
  1359. updateTickCameraTime();
  1360. // Update Camera.
  1361. updateCamera();
  1362. }
  1363. // Is the Camera Shaking?
  1364. if ( mCameraShaking )
  1365. {
  1366. // Reduce Shake Life.
  1367. mShakeLife -= Tickable::smTickSec;
  1368. // Is the Shake still active?
  1369. if ( mShakeLife > 0.0f )
  1370. {
  1371. // Calculate Current Shake.
  1372. mCurrentShake -= mShakeRamp * Tickable::smTickSec;
  1373. // Clamp Shake.
  1374. mCurrentShake = getMax(mCurrentShake, 0.0f);
  1375. // Calculate the Screen Shake-Ratio.
  1376. const Point2F shakeRatio( mCameraCurrent.mDestinationArea.len_x() / F32(mBounds.len_x()), mCameraCurrent.mDestinationArea.len_y() / F32(mBounds.len_y()) );
  1377. // Calculate the Camera Shake Magnitude based upon the Screen Shake-Ratio.
  1378. const F32 shakeMagnitudeX = mCurrentShake * shakeRatio.x * 0.5f;
  1379. const F32 shakeMagnitudeY = mCurrentShake * shakeRatio.y * 0.5f;
  1380. // Choose a random Shake.
  1381. mCameraShakeOffset.Set( CoreMath::mGetRandomF( -shakeMagnitudeX, shakeMagnitudeX ), CoreMath::mGetRandomF( -shakeMagnitudeY, shakeMagnitudeY ) );
  1382. }
  1383. else
  1384. {
  1385. // No, so stop shake.
  1386. stopCameraShake();
  1387. }
  1388. }
  1389. if (mProcessAudioListener)
  1390. {
  1391. F32 listenervelocity[] = { 0.f, 0.f, 0.f };
  1392. Point2F campos = mCameraCurrent.mSourceArea.centre();
  1393. if (campos != PreMove_CameraPos)
  1394. {
  1395. listenervelocity[0] = (campos.x - PreMove_CameraPos.x) * Tickable::smTickSec;
  1396. listenervelocity[1] = (campos.y - PreMove_CameraPos.y) * Tickable::smTickSec;
  1397. listenervelocity[2] = (mCameraCurrent.mCameraZoom - PreMove_CameraZoom) * Tickable::smTickSec;
  1398. }
  1399. F32 listenerpos[] = { campos.x, campos.y, 5.f };
  1400. alListenerfv(AL_POSITION, listenerpos);
  1401. alListenerfv(AL_VELOCITY, listenervelocity);
  1402. }
  1403. }
  1404. //-----------------------------------------------------------------------------
  1405. void SceneWindow::interpolateTick( F32 timeDelta )
  1406. {
  1407. // Are we moving the camera.
  1408. if ( mMovingCamera )
  1409. {
  1410. // Calculate Render Tick Position.
  1411. mRenderCameraTime = (mPreCameraTime * timeDelta) + ((1.0f-timeDelta) * mPostCameraTime);
  1412. // Update Camera.
  1413. updateCamera();
  1414. }
  1415. }
  1416. //-----------------------------------------------------------------------------
  1417. void SceneWindow::interpolateCameraMount( const F32 timeDelta )
  1418. {
  1419. // Camera Mounted?
  1420. if ( !isCameraMounted() ) return;
  1421. // Calculate position.
  1422. mCameraCurrent.mSourceArea.point = (mPreTickPosition * timeDelta) + ((1.0f-timeDelta) * mPostTickPosition);
  1423. }
  1424. //-----------------------------------------------------------------------------
  1425. void SceneWindow::zeroCameraTime( void )
  1426. {
  1427. // Reset Camera Time.
  1428. mRenderCameraTime = mPreCameraTime = mPostCameraTime = mCurrentCameraTime = 0.0f;
  1429. }
  1430. //-----------------------------------------------------------------------------
  1431. void SceneWindow::resetTickCameraTime( void )
  1432. {
  1433. // Reset Camera Time.
  1434. mRenderCameraTime = mPreCameraTime = mPostCameraTime = mCurrentCameraTime;
  1435. }
  1436. //-----------------------------------------------------------------------------
  1437. void SceneWindow::updateTickCameraTime( void )
  1438. {
  1439. // Store Pre Camera Time.
  1440. mPreCameraTime = mPostCameraTime;
  1441. // Store Current Camera Time.
  1442. mPostCameraTime = mCurrentCameraTime;
  1443. // Render Camera Time is at Pre-Tick Time.
  1444. mRenderCameraTime = mPreCameraTime;
  1445. }
  1446. //-----------------------------------------------------------------------------
  1447. void SceneWindow::resetTickCameraPosition( void )
  1448. {
  1449. mPreTickPosition = mPostTickPosition = mCameraCurrent.mSourceArea.point;
  1450. }
  1451. //-----------------------------------------------------------------------------
  1452. void SceneWindow::onRender( Point2I offset, const RectI& updateRect )
  1453. {
  1454. // Debug Profiling.
  1455. PROFILE_SCOPE(SceneWindow_onRender);
  1456. //save the old clip
  1457. RectI oldClipRect = dglGetClipRect();
  1458. //clip to the updateRect
  1459. dglSetClipRect(updateRect);
  1460. // Fetch scene.
  1461. Scene* pScene = getScene();
  1462. // Cannot render without scene!
  1463. if ( !pScene )
  1464. return;
  1465. // Calculate current camera View ( if needed ).
  1466. calculateCameraView( &mCameraCurrent );
  1467. // Fetch current camera.
  1468. const Point2F& sceneWindowScale = mCameraCurrent.mSceneWindowScale;
  1469. Point2F sceneMin = mCameraCurrent.mSceneMin;
  1470. Point2F sceneMax = mCameraCurrent.mSceneMax;
  1471. // Fetch bounds.
  1472. const RectI& bounds = getBounds();
  1473. const Point2I globalTopLeft( updateRect.point.x, updateRect.point.y );
  1474. const Point2I globalBottomRight( updateRect.point.x + updateRect.extent.x, updateRect.point.y + updateRect.extent.y );
  1475. const Point2I localTopLeft = globalToLocalCoord( globalTopLeft );
  1476. const Point2I localBottomRight = globalToLocalCoord( globalBottomRight );
  1477. // Clip top?
  1478. if ( localTopLeft.y > 0 )
  1479. {
  1480. sceneMax.y -= localTopLeft.y * sceneWindowScale.y;
  1481. }
  1482. // Clip left?
  1483. if ( localTopLeft.x > 0 )
  1484. {
  1485. sceneMin.x += localTopLeft.x * sceneWindowScale.x;
  1486. }
  1487. // Clip bottom?
  1488. if ( localBottomRight.y < bounds.extent.y )
  1489. {
  1490. sceneMin.y += (bounds.extent.y - localBottomRight.y ) * sceneWindowScale.y;
  1491. }
  1492. // Clip right?
  1493. if ( localBottomRight.x < bounds.extent.x )
  1494. {
  1495. sceneMax.x -= (bounds.extent.x - localBottomRight.x ) * sceneWindowScale.x;
  1496. }
  1497. // Add camera shake offset if active.
  1498. if ( mCameraShaking )
  1499. {
  1500. sceneMin += mCameraShakeOffset;
  1501. sceneMax += mCameraShakeOffset;
  1502. }
  1503. // Setup new logical coordinate system.
  1504. glMatrixMode(GL_PROJECTION);
  1505. glPushMatrix();
  1506. glLoadIdentity();
  1507. // Set orthographic projection.
  1508. glOrtho( sceneMin.x, sceneMax.x, sceneMin.y, sceneMax.y, 0.0f, MAX_LAYERS_SUPPORTED );
  1509. // Set ModelView.
  1510. glMatrixMode(GL_MODELVIEW);
  1511. glPushMatrix();
  1512. glLoadIdentity();
  1513. // Disable Alpha Test by default
  1514. glDisable( GL_ALPHA_TEST );
  1515. glDisable( GL_DEPTH_TEST );
  1516. // Get Debug Stats.
  1517. DebugStats& debugStats = pScene->getDebugStats();
  1518. // Create a scene render state.
  1519. SceneRenderState sceneRenderState(
  1520. mCameraCurrent.mDestinationArea,
  1521. mCameraCurrent.mDestinationArea.centre(),
  1522. mCameraCurrent.mCameraAngle,
  1523. mRenderLayerMask,
  1524. mRenderGroupMask,
  1525. Vector2( mCameraCurrent.mSceneWindowScale ),
  1526. &debugStats,
  1527. this );
  1528. // Clear the background color if requested.
  1529. if ( mUseBackgroundColor )
  1530. {
  1531. // Enable the scissor.
  1532. const RectI& clipRect = dglGetClipRect();
  1533. glEnable(GL_SCISSOR_TEST );
  1534. glScissor( clipRect.point.x, Platform::getWindowSize().y - (clipRect.point.y + clipRect.extent.y), clipRect.len_x(), clipRect.len_y() );
  1535. // Clear the background.
  1536. glClearColor( mBackgroundColor.red, mBackgroundColor.green, mBackgroundColor.blue, mBackgroundColor.alpha );
  1537. glClear(GL_COLOR_BUFFER_BIT);
  1538. // Disable the scissor.
  1539. glDisable( GL_SCISSOR_TEST );
  1540. }
  1541. // Render View.
  1542. pScene->sceneRender( &sceneRenderState );
  1543. // Restore Matrices.
  1544. glMatrixMode(GL_MODELVIEW);
  1545. glPopMatrix();
  1546. glMatrixMode(GL_PROJECTION);
  1547. glPopMatrix();
  1548. glMatrixMode(GL_MODELVIEW);
  1549. // Render the metrics.
  1550. renderMetricsOverlay( offset, updateRect );
  1551. // Render scrollBar.
  1552. if (mShowScrollBar)
  1553. {
  1554. mScrollBar->onRender(offset, updateRect);
  1555. }
  1556. // Render Children.
  1557. renderChildControls( offset, mBounds, updateRect );
  1558. // Update Window.
  1559. setUpdate();
  1560. //return the clip rect
  1561. dglSetClipRect(oldClipRect);
  1562. }
  1563. //------------------------------------------------------------------------------
  1564. void SceneWindow::renderMetricsOverlay( Point2I offset, const RectI& updateRect )
  1565. {
  1566. // Debug Profiling.
  1567. PROFILE_SCOPE(SceneWindow_RenderMetricsOverlay);
  1568. // Fetch scene.
  1569. Scene* pScene = getScene();
  1570. #if 0
  1571. // Force on debug rendering.
  1572. pScene->setDebugOn( 0xFFFFFFFF );
  1573. #endif
  1574. // Fetch full metrics mode.
  1575. const bool fullMetrics = pScene->getDebugMask() & Scene::SCENE_DEBUG_METRICS;
  1576. const bool fpsMetrics = pScene->getDebugMask() & Scene::SCENE_DEBUG_FPS_METRICS;
  1577. // Finish if should not or cannot render.
  1578. if ( ( !fullMetrics && !fpsMetrics ) ||
  1579. mProfile == NULL ||
  1580. !mProfile->getFont(mFontSizeAdjust) )
  1581. return;
  1582. // Fetch the font.
  1583. GFont* font = mProfile->getFont(mFontSizeAdjust);
  1584. // Blending for banner background.
  1585. glEnable ( GL_BLEND );
  1586. glBlendFunc ( GL_SRC_ALPHA , GL_ONE_MINUS_SRC_ALPHA );
  1587. // Set banner background color.
  1588. const ColorI& fillColor = mProfile->mFillColor;
  1589. const F32 colorScale = 1.0f / 255.0f;
  1590. glColor4f( fillColor.red * colorScale, fillColor.green * colorScale, fillColor.blue * colorScale, fillColor.alpha * colorScale );
  1591. // Fetch debug scene object.
  1592. SceneObject* pDebugSceneObject = pScene->getDebugSceneObject();
  1593. // Get Debug Stats.
  1594. DebugStats& debugStats = pScene->getDebugStats();
  1595. // Set metrics offset
  1596. const S32 metricsOffset = (S32)font->getStrWidth( "WWWWWWWWWWWW" );
  1597. // Set Banner Height.
  1598. F32 bannerLineHeight = fullMetrics ? 17.0f : 1.0f;
  1599. // Add an extra line if we're monitoring a scene object.
  1600. if ( pDebugSceneObject != NULL )
  1601. bannerLineHeight += 5.0f;
  1602. U32 bannerHeight = (U32)((bannerLineHeight * (F32)font->getHeight()));
  1603. // Calculate Debug Banner Offset.
  1604. Point2I bannerOffset = updateRect.point + Point2I(8,8);
  1605. GLfloat sWindowVertices[] = {
  1606. (GLfloat)updateRect.point.x, (GLfloat)updateRect.point.y,
  1607. (GLfloat)updateRect.point.x + updateRect.extent.x, (GLfloat)updateRect.point.y,
  1608. (GLfloat)updateRect.point.x, (GLfloat)updateRect.point.y + bannerHeight + 16,
  1609. (GLfloat)updateRect.point.x + updateRect.extent.x, (GLfloat)updateRect.point.y + bannerHeight + 16
  1610. };
  1611. glVertexPointer(2, GL_FLOAT, 0, sWindowVertices);
  1612. glEnableClientState(GL_VERTEX_ARRAY);
  1613. glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
  1614. glDisableClientState(GL_VERTEX_ARRAY);
  1615. // Disable Banner Blending.
  1616. glDisable ( GL_BLEND );
  1617. // Set Debug Text color.
  1618. dglSetBitmapModulation( mProfile->mFontColor );
  1619. // ****************************************************************
  1620. // Draw Banner Text.
  1621. // ****************************************************************
  1622. F32 linePositionY = 0.25f;
  1623. F32 linePositionOffsetY = font->getHeight() * 1.25f;
  1624. if ( fullMetrics )
  1625. {
  1626. // Rendering.
  1627. dglDrawText( font, bannerOffset + Point2I(0,(S32)linePositionY), "Render", NULL );
  1628. dSprintf( mDebugText, sizeof( mDebugText ), "- FPS=%4.1f<%4.1f/%4.1f>, Frames=%u, Picked=%d<%d>, RenderRequests=%d<%d>, RenderFallbacks=%d<%d>",
  1629. debugStats.fps, debugStats.minFPS, debugStats.maxFPS,
  1630. debugStats.frameCount,
  1631. debugStats.renderPicked, debugStats.maxRenderPicked,
  1632. debugStats.renderRequests, debugStats.maxRenderRequests,
  1633. debugStats.renderFallbacks, debugStats.maxRenderFallbacks );
  1634. dglDrawText( font, bannerOffset + Point2I(metricsOffset,(S32)linePositionY), mDebugText, NULL );
  1635. linePositionY += linePositionOffsetY;
  1636. // Scene.
  1637. dglDrawText( font, bannerOffset + Point2I(0,(S32)linePositionY), "Scene", NULL );
  1638. dSprintf( mDebugText, sizeof( mDebugText ), "- Count=%d, Index=%d, Time=%0.1fs, Objects=%d<%d>(Global=%d), Enabled=%d<%d>, Visible=%d<%d>, Awake=%d<%d>, Controllers=%d",
  1639. Scene::getGlobalSceneCount(), pScene->getSceneIndex(),
  1640. pScene->getSceneTime(),
  1641. debugStats.objectsCount, debugStats.maxObjectsCount, SceneObject::getGlobalSceneObjectCount(),
  1642. debugStats.objectsEnabled, debugStats.maxObjectsEnabled,
  1643. debugStats.objectsVisible, debugStats.maxObjectsVisible,
  1644. debugStats.objectsAwake, debugStats.maxObjectsAwake,
  1645. pScene->getControllers() == NULL ? 0 : pScene->getControllers()->size() );
  1646. dglDrawText( font, bannerOffset + Point2I(metricsOffset,(S32)linePositionY), mDebugText, NULL );
  1647. linePositionY += linePositionOffsetY;
  1648. // Camera Window #1.
  1649. dglDrawText( font, bannerOffset + Point2I(0,(S32)linePositionY), "Camera", NULL );
  1650. Vector2 cameraPosition = getCameraPosition();
  1651. dSprintf( mDebugText, sizeof( mDebugText ), "- Pos=(%0.1f,%0.1f), Size=(%0.1f,%0.1f), Zoom=%0.1f, Angle=%0.1f, Lower=(%0.1f,%0.1f), Upper=(%0.1f,%0.1f)",
  1652. cameraPosition.x,
  1653. cameraPosition.y,
  1654. mCameraCurrent.mSourceArea.extent.x,
  1655. mCameraCurrent.mSourceArea.extent.y,
  1656. mCameraCurrent.mCameraZoom,
  1657. mRadToDeg(mCameraCurrent.mCameraAngle),
  1658. mCameraCurrent.mSourceArea.point.x,
  1659. mCameraCurrent.mSourceArea.point.y,
  1660. mCameraCurrent.mSourceArea.point.x + mCameraCurrent.mSourceArea.extent.x,
  1661. mCameraCurrent.mSourceArea.point.y + mCameraCurrent.mSourceArea.extent.y );
  1662. dglDrawText( font, bannerOffset + Point2I(metricsOffset,(S32)linePositionY), mDebugText, NULL );
  1663. linePositionY += linePositionOffsetY;
  1664. // Camera Window #2.
  1665. Point2I windowExtent = getExtent();
  1666. Vector2 windowScale = getCameraWindowScale();
  1667. dSprintf( mDebugText, sizeof( mDebugText ), "- Window=(%d,%d), WorldScale=(%0.3f,%0.3f), RenderScale=(%0.3f,%0.3f)",
  1668. windowExtent.x, windowExtent.y,
  1669. windowScale.x, windowScale.y,
  1670. 1.0f / windowScale.x, 1.0f / windowScale.y);
  1671. dglDrawText( font, bannerOffset + Point2I(metricsOffset,(S32)linePositionY), mDebugText, NULL );
  1672. linePositionY += linePositionOffsetY;
  1673. // Batching #1.
  1674. dglDrawText( font, bannerOffset + Point2I(0,(S32)linePositionY), "Batching", NULL );
  1675. dSprintf( mDebugText, sizeof( mDebugText ), "- %sTris=%d<%d>, MaxTriDraw=%d, MaxVerts=%d, Strict=%d<%d>, Sorted=%d<%d>",
  1676. pScene->getBatchingEnabled() ? "" : "(OFF) ",
  1677. debugStats.batchTrianglesSubmitted, debugStats.maxBatchTrianglesSubmitted,
  1678. debugStats.batchMaxTriangleDrawn,
  1679. debugStats.batchMaxVertexBuffer,
  1680. debugStats.batchDrawCallsStrict, debugStats.maxBatchDrawCallsStrict,
  1681. debugStats.batchDrawCallsSorted, debugStats.maxBatchDrawCallsSorted
  1682. );
  1683. dglDrawText( font, bannerOffset + Point2I(metricsOffset,(S32)linePositionY), mDebugText, NULL );
  1684. linePositionY += linePositionOffsetY;
  1685. // Batching #2.
  1686. dSprintf( mDebugText, sizeof( mDebugText ), "- Flush=%d<%d>, BlendFlush=%d<%d>, ColorFlush=%d<%d>, AlphaFlush=%d<%d>, TexFlush=%d<%d>",
  1687. debugStats.batchFlushes, debugStats.maxBatchFlushes,
  1688. debugStats.batchBlendStateFlush, debugStats.maxBatchBlendStateFlush,
  1689. debugStats.batchColorStateFlush, debugStats.maxBatchColorStateFlush,
  1690. debugStats.batchAlphaStateFlush, debugStats.maxBatchAlphaStateFlush,
  1691. debugStats.batchTextureChangeFlush, debugStats.maxBatchTextureChangeFlushes
  1692. );
  1693. dglDrawText( font, bannerOffset + Point2I(metricsOffset,(S32)linePositionY), mDebugText, NULL );
  1694. linePositionY += linePositionOffsetY;
  1695. // Batching #3.
  1696. dSprintf( mDebugText, sizeof( mDebugText ), "- IsolatedFlush=%d<%d>, FullFlush=%d<%d>, LayerFlush=%d<%d>, NoBatchFlush=%d<%d>, AnonFlush=%d<%d>",
  1697. debugStats.batchIsolatedFlush, debugStats.maxBatchIsolatedFlush,
  1698. debugStats.batchBufferFullFlush, debugStats.maxBatchBufferFullFlush,
  1699. debugStats.batchLayerFlush, debugStats.maxBatchLayerFlush,
  1700. debugStats.batchNoBatchFlush, debugStats.maxBatchNoBatchFlush,
  1701. debugStats.batchAnonymousFlush, debugStats.maxBatchAnonymousFlush
  1702. );
  1703. dglDrawText( font, bannerOffset + Point2I(metricsOffset,(S32)linePositionY), mDebugText, NULL );
  1704. linePositionY += linePositionOffsetY;
  1705. // Textures.
  1706. dglDrawText( font, bannerOffset + Point2I(0,(S32)linePositionY), "Textures", NULL );
  1707. dSprintf( mDebugText, sizeof( mDebugText ), "- TextureCount=%d, TextureSize=%d, TextureWaste=%d, BitmapSize=%d",
  1708. TextureManager::getTextureResidentCount(),
  1709. TextureManager::getTextureResidentSize(),
  1710. TextureManager::getTextureResidentWasteSize(),
  1711. TextureManager::getBitmapResidentSize()
  1712. );
  1713. dglDrawText( font, bannerOffset + Point2I(metricsOffset,(S32)linePositionY), mDebugText, NULL );
  1714. linePositionY += linePositionOffsetY;
  1715. // Physics.
  1716. dglDrawText( font, bannerOffset + Point2I(0,(S32)linePositionY), "Physics", NULL );
  1717. dSprintf( mDebugText, sizeof( mDebugText ), "- Bodies=%d<%d>, Joints=%d<%d>, Contacts=%d<%d>, Proxies=%d<%d>",
  1718. debugStats.bodyCount, debugStats.maxBodyCount,
  1719. debugStats.jointCount, debugStats.maxJointCount,
  1720. debugStats.contactCount, debugStats.maxContactCount,
  1721. debugStats.proxyCount, debugStats.maxProxyCount );
  1722. dglDrawText( font, bannerOffset + Point2I(metricsOffset,(S32)linePositionY), mDebugText, NULL );
  1723. linePositionY += linePositionOffsetY;
  1724. const b2Profile& worldProfile = debugStats.worldProfile;
  1725. const b2Profile& maxWorldProfile = debugStats.maxWorldProfile;
  1726. // Physics timings #1.
  1727. dglDrawText( font, bannerOffset + Point2I(0,(S32)linePositionY), "Timings", NULL );
  1728. dSprintf( mDebugText, sizeof( mDebugText ), "- Step=%0.0f<%0.0f>, Collide=%0.0f<%0.0f>, BroadPhase=%0.0f<%0.0f>",
  1729. worldProfile.step, maxWorldProfile.step,
  1730. worldProfile.collide, maxWorldProfile.collide,
  1731. worldProfile.broadphase, maxWorldProfile.broadphase );
  1732. dglDrawText( font, bannerOffset + Point2I(metricsOffset,(S32)linePositionY), mDebugText, NULL );
  1733. linePositionY += linePositionOffsetY;
  1734. // Physics timings #2.
  1735. dSprintf( mDebugText, sizeof( mDebugText ), "- Solve=%0.0f<%0.0f>, SolveInit=%0.0f<%0.0f>, SolveVel=%0.0f<%0.0f>, SolvePos=%0.0f<%0.0f>, SolveTOI=%0.0f<%0.0f>",
  1736. worldProfile.solve, maxWorldProfile.solve,
  1737. worldProfile.solveInit, maxWorldProfile.solveInit,
  1738. worldProfile.solveVelocity, maxWorldProfile.solveVelocity,
  1739. worldProfile.solvePosition, maxWorldProfile.solvePosition,
  1740. worldProfile.solveTOI, maxWorldProfile.solveTOI );
  1741. dglDrawText( font, bannerOffset + Point2I(metricsOffset,(S32)linePositionY), mDebugText, NULL );
  1742. linePositionY += linePositionOffsetY;
  1743. // Physics spatial tree.
  1744. dglDrawText( font, bannerOffset + Point2I(0,(S32)linePositionY), "Partition", NULL );
  1745. const b2World* pWorld = pScene->getWorld();
  1746. const S32 treeBalance = pWorld->GetTreeBalance();
  1747. const S32 treeHeight = pWorld->GetTreeHeight();
  1748. const F32 treeQuality = pWorld->GetTreeQuality();
  1749. dSprintf( mDebugText, sizeof( mDebugText ), "- Balance=%d, Height=%d, Quality=%0.2f",
  1750. treeBalance,
  1751. treeHeight,
  1752. treeQuality );
  1753. dglDrawText( font, bannerOffset + Point2I(metricsOffset,(S32)linePositionY), mDebugText, NULL );
  1754. linePositionY += linePositionOffsetY;
  1755. // Particles.
  1756. dglDrawText( font, bannerOffset + Point2I(0,(S32)linePositionY), "Particles", NULL );
  1757. dSprintf( mDebugText, sizeof( mDebugText ), "- Allocated=%d, Used=%d<%d>, Free=%d",
  1758. debugStats.particlesAlloc,
  1759. debugStats.particlesUsed, debugStats.maxParticlesUsed,
  1760. debugStats.particlesFree );
  1761. dglDrawText( font, bannerOffset + Point2I(metricsOffset,(S32)linePositionY), mDebugText, NULL );
  1762. linePositionY += linePositionOffsetY;
  1763. // Asset Manager.
  1764. dglDrawText( font, bannerOffset + Point2I(0,(S32)linePositionY), "Assets", NULL );
  1765. dSprintf( mDebugText, sizeof( mDebugText ), "- AcquiredRefs=%d, Declared=%d, Referenced=%d, LoadedInternal=%d<%d>, LoadedExternal=%d<%d>, LoadedPrivate=%d<%d>",
  1766. AssetDatabase.getAcquiredReferenceCount(),
  1767. AssetDatabase.getDeclaredAssetCount(),
  1768. AssetDatabase.getReferencedAssetCount(),
  1769. AssetDatabase.getLoadedInternalAssetCount(), AssetDatabase.getMaxLoadedInternalAssetCount(),
  1770. AssetDatabase.getLoadedExternalAssetCount(), AssetDatabase.getMaxLoadedExternalAssetCount(),
  1771. AssetDatabase.getLoadedPrivateAssetCount(), AssetDatabase.getMaxLoadedPrivateAssetCount() );
  1772. dglDrawText( font, bannerOffset + Point2I(metricsOffset,(S32)linePositionY), mDebugText, NULL );
  1773. linePositionY += linePositionOffsetY;
  1774. }
  1775. else if ( fpsMetrics )
  1776. {
  1777. // Rendering.
  1778. dSprintf( mDebugText, sizeof( mDebugText ), "FPS=%4.1f<%4.1f/%4.1f>",
  1779. debugStats.fps, debugStats.minFPS, debugStats.maxFPS );
  1780. dglDrawText( font, bannerOffset + Point2I(0,(S32)linePositionY), mDebugText, NULL );
  1781. linePositionY += linePositionOffsetY;
  1782. }
  1783. // Monitored scene object.
  1784. if ( pDebugSceneObject != NULL )
  1785. {
  1786. // SceneObject #1.
  1787. dglDrawText( font, bannerOffset + Point2I(0,(S32)linePositionY), "SceneObject", NULL );
  1788. const b2Vec2 position = pDebugSceneObject->getRenderPosition();
  1789. const F32 angle = mRadToDeg( pDebugSceneObject->getRenderAngle() );
  1790. const Vector2 size = pDebugSceneObject->getSize();
  1791. const U32 sceneLayer = pDebugSceneObject->getSceneLayer();
  1792. const U32 sceneGroup = pDebugSceneObject->getSceneGroup();
  1793. const U32 serialId = pDebugSceneObject->getSerialId();
  1794. StringTableEntry renderGroup = pDebugSceneObject->getRenderGroup();
  1795. dSprintf( mDebugText, sizeof( mDebugText ), "- Id=%d, Pos=(%0.3f,%0.3f), Angle=%0.3f, Size=(%0.3f,%0.3f), Layer=%d, Group=%d, SerialId=%d, RenderGroup='%s'",
  1796. pDebugSceneObject->getId(),
  1797. position.x, position.y,
  1798. angle,
  1799. size.x, size.y,
  1800. sceneLayer,
  1801. sceneGroup,
  1802. serialId,
  1803. renderGroup
  1804. );
  1805. dglDrawText( font, bannerOffset + Point2I(metricsOffset,(S32)linePositionY), mDebugText, NULL );
  1806. linePositionY += linePositionOffsetY;
  1807. // SceneObject #2.
  1808. const char* pBodyType = SceneObject::getBodyTypeDescription(pDebugSceneObject->getBodyType());
  1809. const bool enabled = pDebugSceneObject->isEnabled();
  1810. const bool active = pDebugSceneObject->getActive();
  1811. const bool visible = pDebugSceneObject->getVisible();
  1812. const bool isBullet = pDebugSceneObject->getBullet();
  1813. const bool awake = pDebugSceneObject->getAwake();
  1814. const bool sleepingAllowed = pDebugSceneObject->getSleepingAllowed();
  1815. dSprintf( mDebugText, sizeof( mDebugText ), "- Body=%s, Enabled=%d, Active=%d, Visible=%d, Bullet=%d, Awake=%d, CanSleep=%d",
  1816. pBodyType,
  1817. enabled,
  1818. active,
  1819. visible,
  1820. isBullet,
  1821. awake,
  1822. sleepingAllowed
  1823. );
  1824. dglDrawText( font, bannerOffset + Point2I(metricsOffset,(S32)linePositionY), mDebugText, NULL );
  1825. linePositionY += linePositionOffsetY;
  1826. // SceneObject #3.
  1827. const Vector2 linearVelocity = pDebugSceneObject->getLinearVelocity();
  1828. const F32 angularVelocity = pDebugSceneObject->getAngularVelocity();
  1829. const F32 linearDamping = pDebugSceneObject->getLinearDamping();
  1830. const F32 angularDamping = pDebugSceneObject->getAngularDamping();
  1831. const Vector2 localCenter = pDebugSceneObject->getLocalCenter();
  1832. dSprintf( mDebugText, sizeof( mDebugText ), "- LinVel=(%0.3f,%0.3f), AngVel=%0.3f, LinDamp=%0.3f, AngDamp=%0.3f, Com=(%0.3f,%0.3f)",
  1833. linearVelocity.x, linearVelocity.y,
  1834. angularVelocity,
  1835. linearDamping,
  1836. angularDamping,
  1837. localCenter.x, localCenter.y
  1838. );
  1839. dglDrawText( font, bannerOffset + Point2I(metricsOffset,(S32)linePositionY), mDebugText, NULL );
  1840. linePositionY += linePositionOffsetY;
  1841. // SceneObject #4.
  1842. const bool collisionSuppress = pDebugSceneObject->getCollisionSuppress();
  1843. const U32 collisionLayerMask = pDebugSceneObject->getCollisionLayerMask();
  1844. const U32 collisionGroupMask = pDebugSceneObject->getCollisionGroupMask();
  1845. const U32 collisionShapeCount = pDebugSceneObject->getCollisionShapeCount();
  1846. dSprintf( mDebugText, sizeof( mDebugText ), "- Shapes=%d, ColSuppress=%d, ColLayer=%0.8x, ColGroup=%0.8x",
  1847. collisionShapeCount,
  1848. collisionSuppress,
  1849. collisionLayerMask,
  1850. collisionGroupMask
  1851. );
  1852. dglDrawText( font, bannerOffset + Point2I(metricsOffset,(S32)linePositionY), mDebugText, NULL );
  1853. }
  1854. // Clear Bitmap Modulation.
  1855. dglClearBitmapModulation();
  1856. }