SceneWindow.cc 80 KB

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