sceneObject.cpp 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 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 "platform/platform.h"
  23. #include "scene/sceneObject.h"
  24. #include "platform/profiler.h"
  25. #include "console/consoleTypes.h"
  26. #include "console/engineAPI.h"
  27. #include "console/simPersistID.h"
  28. #include "sim/netConnection.h"
  29. #include "core/stream/bitStream.h"
  30. #include "scene/sceneManager.h"
  31. #include "scene/sceneTracker.h"
  32. #include "scene/sceneRenderState.h"
  33. #include "scene/zones/sceneZoneSpace.h"
  34. #include "collision/extrudedPolyList.h"
  35. #include "collision/earlyOutPolyList.h"
  36. #include "collision/optimizedPolyList.h"
  37. #include "math/mPolyhedron.h"
  38. #include "gfx/bitmap/gBitmap.h"
  39. #include "math/util/frustum.h"
  40. #include "math/mathIO.h"
  41. #include "math/mTransform.h"
  42. #include "T3D/gameBase/gameProcess.h"
  43. #ifdef GHOSTSCOPING
  44. #include "T3D/gameBase/gameConnection.h"
  45. #endif
  46. IMPLEMENT_CONOBJECT(SceneObject);
  47. ConsoleDocClass( SceneObject,
  48. "@brief A networkable object that exists in the 3D world.\n\n"
  49. "The SceneObject class provides the foundation for 3D objects in the Engine. It "
  50. "exposes the functionality for:\n\n"
  51. "<ul><li>Position, rotation and scale within the world.</li>"
  52. "<li>Working with a scene graph (in the Zone and Portal sections), allowing efficient "
  53. "and robust rendering of the game scene.</li>"
  54. "<li>Various helper functions, including functions to get bounding information "
  55. "and momentum/velocity.</li>"
  56. "<li>Mounting one SceneObject to another.</li>"
  57. "<li>An interface for collision detection, as well as ray casting.</li>"
  58. "<li>Lighting. SceneObjects can register lights both at lightmap generation "
  59. "time, and dynamic lights at runtime (for special effects, such as from flame "
  60. "or a projectile, or from an explosion).</li></ul>\n\n"
  61. "You do not typically work with SceneObjects themselves. The SceneObject provides a reference "
  62. "within the game world (the scene), but does not render to the client on its own. The "
  63. "same is true of collision detection beyond that of the bounding box. Instead you "
  64. "use one of the many classes that derrive from SceneObject, such as TSStatic.\n\n"
  65. "@section SceneObject_Hiding Difference Between setHidden() and isRenderEnabled\n\n"
  66. "When it comes time to decide if a SceneObject should render or not, there are two "
  67. "methods that can stop the SceneObject from rendering at all. You need to be aware of "
  68. "the differences between these two methods as they impact how the SceneObject is networked "
  69. "from the server to the client.\n\n"
  70. "The first method of manually controlling if a SceneObject is rendered is through its "
  71. "SceneObject::isRenderEnabled property. When set to false the SceneObject is considered invisible but "
  72. "still present within the scene. This means it still takes part in collisions and continues "
  73. "to be networked.\n\n"
  74. "The second method is using the setHidden() method. This will actually remove a SceneObject "
  75. "from the scene and it will no longer be networked from the server to the cleint. Any client-side "
  76. "ghost of the object will be deleted as the server no longer considers the object to be in scope.\n\n"
  77. "@ingroup gameObjects\n"
  78. );
  79. Signal< void( SceneObject* ) > SceneObject::smSceneObjectAdd;
  80. Signal< void( SceneObject* ) > SceneObject::smSceneObjectRemove;
  81. //-----------------------------------------------------------------------------
  82. SceneObject::SceneObject()
  83. {
  84. mContainer = 0;
  85. mTypeMask = DefaultObjectType;
  86. mCollisionCount = 0;
  87. mGlobalBounds = false;
  88. mObjScale.set(1,1,1);
  89. mObjToWorld.identity();
  90. mWorldToObj.identity();
  91. mObjBox = Box3F(Point3F(0, 0, 0), Point3F(0, 0, 0));
  92. mWorldBox = Box3F(Point3F(0, 0, 0), Point3F(0, 0, 0));
  93. mWorldSphere = SphereF(Point3F(0, 0, 0), 0);
  94. mRenderObjToWorld.identity();
  95. mRenderWorldToObj.identity();
  96. mRenderWorldBox = Box3F(Point3F(0, 0, 0), Point3F(0, 0, 0));
  97. mRenderWorldSphere = SphereF(Point3F(0, 0, 0), 0);
  98. mContainerSeqKey = 0;
  99. mBinRefHead = NULL;
  100. mSceneManager = NULL;
  101. mNumCurrZones = 0;
  102. mZoneRefHead = NULL;
  103. mZoneRefDirty = false;
  104. mBinMinX = 0xFFFFFFFF;
  105. mBinMaxX = 0xFFFFFFFF;
  106. mBinMinY = 0xFFFFFFFF;
  107. mBinMaxY = 0xFFFFFFFF;
  108. mLightPlugin = NULL;
  109. mMount.object = NULL;
  110. mMount.link = NULL;
  111. mMount.list = NULL;
  112. mMount.node = -1;
  113. mMount.xfm = MatrixF::Identity;
  114. mMountPID = NULL;
  115. mSceneObjectLinks = NULL;
  116. mObjectFlags.set( RenderEnabledFlag | SelectionEnabledFlag );
  117. mIsScopeAlways = false;
  118. }
  119. //-----------------------------------------------------------------------------
  120. SceneObject::~SceneObject()
  121. {
  122. AssertFatal( mZoneRefHead == NULL && mBinRefHead == NULL,
  123. "SceneObject::~SceneObject - Object still linked in reference lists!");
  124. AssertFatal( !mSceneObjectLinks,
  125. "SceneObject::~SceneObject() - object is still linked to SceneTrackers" );
  126. unlink();
  127. }
  128. //-----------------------------------------------------------------------------
  129. bool SceneObject::castRayRendered(const Point3F &start, const Point3F &end, RayInfo *info)
  130. {
  131. // By default, all ray checking against the rendered mesh will be passed
  132. // on to the collision mesh. This saves having to define both methods
  133. // for simple objects.
  134. return castRay( start, end, info );
  135. }
  136. //-----------------------------------------------------------------------------
  137. bool SceneObject::containsPoint( const Point3F& point )
  138. {
  139. // If it's not in the AABB, then it can't be in the OBB either,
  140. // so early out.
  141. if( !mWorldBox.isContained( point ) )
  142. return false;
  143. // Transform point into object space and test it against
  144. // our object space bounding box.
  145. Point3F objPoint( 0, 0, 0 );
  146. getWorldTransform().mulP( point, &objPoint );
  147. objPoint.convolveInverse( getScale() );
  148. return ( mObjBox.isContained( objPoint ) );
  149. }
  150. //-----------------------------------------------------------------------------
  151. bool SceneObject::collideBox(const Point3F &start, const Point3F &end, RayInfo *info)
  152. {
  153. const F32 * pStart = (const F32*)start;
  154. const F32 * pEnd = (const F32*)end;
  155. const F32 * pMin = (const F32*)mObjBox.minExtents;
  156. const F32 * pMax = (const F32*)mObjBox.maxExtents;
  157. F32 maxStartTime = -1;
  158. F32 minEndTime = 1;
  159. F32 startTime;
  160. F32 endTime;
  161. // used for getting normal
  162. U32 hitIndex = 0xFFFFFFFF;
  163. U32 side;
  164. // walk the axis
  165. for(U32 i = 0; i < 3; i++)
  166. {
  167. //
  168. if(pStart[i] < pEnd[i])
  169. {
  170. if(pEnd[i] < pMin[i] || pStart[i] > pMax[i])
  171. return(false);
  172. F32 dist = pEnd[i] - pStart[i];
  173. startTime = (pStart[i] < pMin[i]) ? (pMin[i] - pStart[i]) / dist : -1;
  174. endTime = (pEnd[i] > pMax[i]) ? (pMax[i] - pStart[i]) / dist : 1;
  175. side = 1;
  176. }
  177. else
  178. {
  179. if(pStart[i] < pMin[i] || pEnd[i] > pMax[i])
  180. return(false);
  181. F32 dist = pStart[i] - pEnd[i];
  182. startTime = (pStart[i] > pMax[i]) ? (pStart[i] - pMax[i]) / dist : -1;
  183. endTime = (pEnd[i] < pMin[i]) ? (pStart[i] - pMin[i]) / dist : 1;
  184. side = 0;
  185. }
  186. //
  187. if(startTime > maxStartTime)
  188. {
  189. maxStartTime = startTime;
  190. hitIndex = i * 2 + side;
  191. }
  192. if(endTime < minEndTime)
  193. minEndTime = endTime;
  194. if(minEndTime < maxStartTime)
  195. return(false);
  196. }
  197. // fail if inside
  198. if(maxStartTime < 0.f)
  199. return(false);
  200. //
  201. static Point3F boxNormals[] = {
  202. Point3F( 1, 0, 0),
  203. Point3F(-1, 0, 0),
  204. Point3F( 0, 1, 0),
  205. Point3F( 0,-1, 0),
  206. Point3F( 0, 0, 1),
  207. Point3F( 0, 0,-1),
  208. };
  209. //
  210. AssertFatal(hitIndex != 0xFFFFFFFF, "SceneObject::collideBox");
  211. info->t = maxStartTime;
  212. info->object = this;
  213. mObjToWorld.mulV(boxNormals[hitIndex], &info->normal);
  214. info->material = 0;
  215. return(true);
  216. }
  217. //-----------------------------------------------------------------------------
  218. void SceneObject::disableCollision()
  219. {
  220. mCollisionCount++;
  221. AssertFatal(mCollisionCount < 50, "SceneObject::disableCollision called 50 times on the same object. Is this inside a circular loop?" );
  222. }
  223. //-----------------------------------------------------------------------------
  224. void SceneObject::enableCollision()
  225. {
  226. if (mCollisionCount)
  227. --mCollisionCount;
  228. }
  229. //-----------------------------------------------------------------------------
  230. bool SceneObject::onAdd()
  231. {
  232. if ( !Parent::onAdd() )
  233. return false;
  234. mIsScopeAlways = mNetFlags.test( ScopeAlways );
  235. mWorldToObj = mObjToWorld;
  236. mWorldToObj.affineInverse();
  237. resetWorldBox();
  238. setRenderTransform(mObjToWorld);
  239. resolveMountPID();
  240. smSceneObjectAdd.trigger(this);
  241. return true;
  242. }
  243. //-----------------------------------------------------------------------------
  244. void SceneObject::onRemove()
  245. {
  246. smSceneObjectRemove.trigger(this);
  247. unmount();
  248. plUnlink();
  249. Parent::onRemove();
  250. }
  251. //-----------------------------------------------------------------------------
  252. void SceneObject::addToScene()
  253. {
  254. if( mSceneManager )
  255. return;
  256. if( isClientObject() )
  257. gClientSceneGraph->addObjectToScene( this );
  258. else
  259. gServerSceneGraph->addObjectToScene( this );
  260. }
  261. //-----------------------------------------------------------------------------
  262. void SceneObject::removeFromScene()
  263. {
  264. if( !mSceneManager )
  265. return;
  266. mSceneManager->removeObjectFromScene( this );
  267. }
  268. //-----------------------------------------------------------------------------
  269. void SceneObject::onDeleteNotify( SimObject *obj )
  270. {
  271. // We are comparing memory addresses so even if obj really is not a
  272. // ProcessObject this cast shouldn't break anything.
  273. if ( obj == mAfterObject )
  274. mAfterObject = NULL;
  275. if ( obj == mMount.object )
  276. unmount();
  277. Parent::onDeleteNotify( obj );
  278. }
  279. //-----------------------------------------------------------------------------
  280. void SceneObject::inspectPostApply()
  281. {
  282. if( isServerObject() )
  283. setMaskBits( MountedMask );
  284. Parent::inspectPostApply();
  285. }
  286. //-----------------------------------------------------------------------------
  287. void SceneObject::setGlobalBounds()
  288. {
  289. mGlobalBounds = true;
  290. mObjBox.minExtents.set( -1e10, -1e10, -1e10 );
  291. mObjBox.maxExtents.set( 1e10, 1e10, 1e10 );
  292. if( mSceneManager )
  293. mSceneManager->notifyObjectDirty( this );
  294. }
  295. //-----------------------------------------------------------------------------
  296. void SceneObject::setTransform( const MatrixF& mat )
  297. {
  298. // This test is a bit expensive so turn it off in release.
  299. #ifdef TORQUE_DEBUG
  300. //AssertFatal( mat.isAffine(), "SceneObject::setTransform() - Bad transform (non affine)!" );
  301. #endif
  302. PROFILE_SCOPE( SceneObject_setTransform );
  303. // Update the transforms.
  304. mObjToWorld = mWorldToObj = mat;
  305. mWorldToObj.affineInverse();
  306. // Update the world-space AABB.
  307. resetWorldBox();
  308. // If we're in a SceneManager, sync our scene state.
  309. if( mSceneManager != NULL )
  310. mSceneManager->notifyObjectDirty( this );
  311. setRenderTransform( mat );
  312. }
  313. //-----------------------------------------------------------------------------
  314. void SceneObject::setScale( const VectorF &scale )
  315. {
  316. AssertFatal( !mIsNaN( scale ), "SceneObject::setScale() - The scale is NaN!" );
  317. // Avoid unnecessary scaling operations.
  318. if ( mObjScale.equal( scale ) )
  319. return;
  320. mObjScale = scale;
  321. setTransform(MatrixF(mObjToWorld));
  322. // Make sure that any subclasses of me get a chance to react to the
  323. // scale being changed.
  324. onScaleChanged();
  325. setMaskBits( ScaleMask );
  326. }
  327. //-----------------------------------------------------------------------------
  328. void SceneObject::resetWorldBox()
  329. {
  330. AssertFatal(mObjBox.isValidBox(), "SceneObject::resetWorldBox - Bad object box!");
  331. mWorldBox = mObjBox;
  332. mWorldBox.minExtents.convolve(mObjScale);
  333. mWorldBox.maxExtents.convolve(mObjScale);
  334. mObjToWorld.mul(mWorldBox);
  335. AssertFatal(mWorldBox.isValidBox(), "SceneObject::resetWorldBox - Bad world box!");
  336. // Create mWorldSphere from mWorldBox
  337. mWorldBox.getCenter(&mWorldSphere.center);
  338. mWorldSphere.radius = (mWorldBox.maxExtents - mWorldSphere.center).len();
  339. // Update tracker links.
  340. for( SceneObjectLink* link = mSceneObjectLinks; link != NULL;
  341. link = link->getNextLink() )
  342. link->update();
  343. }
  344. //-----------------------------------------------------------------------------
  345. void SceneObject::resetObjectBox()
  346. {
  347. AssertFatal( mWorldBox.isValidBox(), "SceneObject::resetObjectBox - Bad world box!" );
  348. mObjBox = mWorldBox;
  349. mWorldToObj.mul( mObjBox );
  350. Point3F objScale( mObjScale );
  351. objScale.setMax( Point3F( (F32)POINT_EPSILON, (F32)POINT_EPSILON, (F32)POINT_EPSILON ) );
  352. mObjBox.minExtents.convolveInverse( objScale );
  353. mObjBox.maxExtents.convolveInverse( objScale );
  354. AssertFatal( mObjBox.isValidBox(), "SceneObject::resetObjectBox - Bad object box!" );
  355. // Update the mWorldSphere from mWorldBox
  356. mWorldBox.getCenter( &mWorldSphere.center );
  357. mWorldSphere.radius = ( mWorldBox.maxExtents - mWorldSphere.center ).len();
  358. // Update scene managers.
  359. for( SceneObjectLink* link = mSceneObjectLinks; link != NULL;
  360. link = link->getNextLink() )
  361. link->update();
  362. }
  363. //-----------------------------------------------------------------------------
  364. void SceneObject::setRenderTransform(const MatrixF& mat)
  365. {
  366. PROFILE_START(SceneObj_setRenderTransform);
  367. mRenderObjToWorld = mRenderWorldToObj = mat;
  368. mRenderWorldToObj.affineInverse();
  369. AssertFatal(mObjBox.isValidBox(), "Bad object box!");
  370. resetRenderWorldBox();
  371. PROFILE_END();
  372. }
  373. //-----------------------------------------------------------------------------
  374. void SceneObject::resetRenderWorldBox()
  375. {
  376. AssertFatal( mObjBox.isValidBox(), "Bad object box!" );
  377. mRenderWorldBox = mObjBox;
  378. mRenderWorldBox.minExtents.convolve( mObjScale );
  379. mRenderWorldBox.maxExtents.convolve( mObjScale );
  380. mRenderObjToWorld.mul( mRenderWorldBox );
  381. AssertFatal( mRenderWorldBox.isValidBox(), "Bad world box!" );
  382. // Create mRenderWorldSphere from mRenderWorldBox.
  383. mRenderWorldBox.getCenter( &mRenderWorldSphere.center );
  384. mRenderWorldSphere.radius = ( mRenderWorldBox.maxExtents - mRenderWorldSphere.center ).len();
  385. }
  386. //-----------------------------------------------------------------------------
  387. void SceneObject::setHidden( bool hidden )
  388. {
  389. if( hidden != isHidden() )
  390. {
  391. // Add/remove the object from the scene. Removing it
  392. // will also cause the NetObject to go out of scope since
  393. // the container query will not find it anymore. However,
  394. // ScopeAlways objects need to be treated separately as we
  395. // do next.
  396. if( !hidden )
  397. addToScene();
  398. else
  399. removeFromScene();
  400. // ScopeAlways objects stay in scope no matter what, i.e. even
  401. // if they aren't in the scene query anymore. So, to force ghosts
  402. // to go away, we need to clear ScopeAlways while we are hidden.
  403. if( hidden && mIsScopeAlways )
  404. clearScopeAlways();
  405. else if( !hidden && mIsScopeAlways )
  406. setScopeAlways();
  407. Parent::setHidden( hidden );
  408. }
  409. }
  410. //-----------------------------------------------------------------------------
  411. void SceneObject::initPersistFields()
  412. {
  413. addGroup( "Transform" );
  414. addProtectedField( "position", TypeMatrixPosition, Offset( mObjToWorld, SceneObject ),
  415. &_setFieldPosition, &defaultProtectedGetFn,
  416. "Object world position." );
  417. addProtectedField( "rotation", TypeMatrixRotation, Offset( mObjToWorld, SceneObject ),
  418. &_setFieldRotation, &defaultProtectedGetFn,
  419. "Object world orientation." );
  420. addProtectedField( "scale", TypePoint3F, Offset( mObjScale, SceneObject ),
  421. &_setFieldScale, &defaultProtectedGetFn,
  422. "Object world scale." );
  423. endGroup( "Transform" );
  424. addGroup( "Editing" );
  425. addProtectedField( "isRenderEnabled", TypeBool, Offset( mObjectFlags, SceneObject ),
  426. &_setRenderEnabled, &_getRenderEnabled,
  427. "Controls client-side rendering of the object.\n"
  428. "@see isRenderable()\n" );
  429. addProtectedField( "isSelectionEnabled", TypeBool, Offset( mObjectFlags, SceneObject ),
  430. &_setSelectionEnabled, &_getSelectionEnabled,
  431. "Determines if the object may be selected from wihin the Tools.\n"
  432. "@see isSelectable()\n" );
  433. endGroup( "Editing" );
  434. addGroup( "Mounting" );
  435. addProtectedField( "mountPID", TypePID, Offset( mMountPID, SceneObject ), &_setMountPID, &defaultProtectedGetFn,
  436. "@brief PersistentID of object we are mounted to.\n\n"
  437. "Unlike the SimObjectID that is determined at run time, the PersistentID of an object is saved with the level/mission and "
  438. "may be used to form a link between objects." );
  439. addField( "mountNode", TypeS32, Offset( mMount.node, SceneObject ), "Node we are mounted to." );
  440. addField( "mountPos", TypeMatrixPosition, Offset( mMount.xfm, SceneObject ), "Position we are mounted at ( object space of our mount object )." );
  441. addField( "mountRot", TypeMatrixRotation, Offset( mMount.xfm, SceneObject ), "Rotation we are mounted at ( object space of our mount object )." );
  442. endGroup( "Mounting" );
  443. Parent::initPersistFields();
  444. }
  445. //-----------------------------------------------------------------------------
  446. bool SceneObject::_setFieldPosition( void *object, const char *index, const char *data )
  447. {
  448. SceneObject* so = static_cast<SceneObject*>( object );
  449. if ( so )
  450. {
  451. MatrixF txfm( so->getTransform() );
  452. Con::setData( TypeMatrixPosition, &txfm, 0, 1, &data );
  453. so->setTransform( txfm );
  454. }
  455. return false;
  456. }
  457. //-----------------------------------------------------------------------------
  458. bool SceneObject::_setFieldRotation( void *object, const char *index, const char *data )
  459. {
  460. SceneObject* so = static_cast<SceneObject*>( object );
  461. if ( so )
  462. {
  463. MatrixF txfm( so->getTransform() );
  464. Con::setData( TypeMatrixRotation, &txfm, 0, 1, &data );
  465. so->setTransform( txfm );
  466. }
  467. return false;
  468. }
  469. //-----------------------------------------------------------------------------
  470. bool SceneObject::_setFieldScale( void *object, const char *index, const char *data )
  471. {
  472. SceneObject* so = static_cast<SceneObject*>( object );
  473. if ( so )
  474. {
  475. Point3F scale;
  476. Con::setData( TypePoint3F, &scale, 0, 1, &data );
  477. so->setScale( scale );
  478. }
  479. return false;
  480. }
  481. //-----------------------------------------------------------------------------
  482. bool SceneObject::writeField( StringTableEntry fieldName, const char* value )
  483. {
  484. if( !Parent::writeField( fieldName, value ) )
  485. return false;
  486. static StringTableEntry sIsRenderEnabled = StringTable->insert( "isRenderEnabled" );
  487. static StringTableEntry sIsSelectionEnabled = StringTable->insert( "isSelectionEnabled" );
  488. static StringTableEntry sMountNode = StringTable->insert( "mountNode" );
  489. static StringTableEntry sMountPos = StringTable->insert( "mountPos" );
  490. static StringTableEntry sMountRot = StringTable->insert( "mountRot" );
  491. // Don't write flag fields if they are at their default values.
  492. if( fieldName == sIsRenderEnabled && dAtob( value ) )
  493. return false;
  494. else if( fieldName == sIsSelectionEnabled && dAtob( value ) )
  495. return false;
  496. else if ( mMountPID == NULL && ( fieldName == sMountNode ||
  497. fieldName == sMountPos ||
  498. fieldName == sMountRot ) )
  499. {
  500. return false;
  501. }
  502. return true;
  503. }
  504. //-----------------------------------------------------------------------------
  505. static void scopeCallback( SceneObject* obj, void* conPtr )
  506. {
  507. NetConnection* ptr = reinterpret_cast< NetConnection* >( conPtr );
  508. if( obj->isScopeable() )
  509. ptr->objectInScope(obj);
  510. }
  511. void SceneObject::onCameraScopeQuery( NetConnection* connection, CameraScopeQuery* query )
  512. {
  513. #ifdef GHOSTSCOPING
  514. SceneManager* scenemanager = getSceneManager();
  515. GameConnection* conn = dynamic_cast<GameConnection*> (connection);
  516. if (conn && conn->getVisibleGhostDistance() == 0.0f)
  517. query->visibleDistance = scenemanager->getVisibleGhostDistance();
  518. else
  519. query->visibleDistance = conn->getVisibleGhostDistance();
  520. #endif
  521. // Object itself is in scope.
  522. if( this->isScopeable() )
  523. connection->objectInScope( this );
  524. // If we're mounted to something, that object is in scope too.
  525. if( isMounted() )
  526. connection->objectInScope( mMount.object );
  527. // If we're added to a scene graph, let the graph do the scene scoping.
  528. // Otherwise just put everything in the server container in scope.
  529. if( getSceneManager() )
  530. getSceneManager()->scopeScene( query, connection );
  531. else
  532. gServerContainer.findObjects( 0xFFFFFFFF, scopeCallback, connection );
  533. }
  534. //-----------------------------------------------------------------------------
  535. bool SceneObject::isRenderEnabled() const
  536. {
  537. AbstractClassRep *classRep = getClassRep();
  538. return ( mObjectFlags.test( RenderEnabledFlag ) && classRep->isRenderEnabled() );
  539. }
  540. //-----------------------------------------------------------------------------
  541. void SceneObject::setRenderEnabled( bool value )
  542. {
  543. if( value )
  544. mObjectFlags.set( RenderEnabledFlag );
  545. else
  546. mObjectFlags.clear( RenderEnabledFlag );
  547. setMaskBits( FlagMask );
  548. }
  549. //-----------------------------------------------------------------------------
  550. const char* SceneObject::_getRenderEnabled( void* object, const char* data )
  551. {
  552. SceneObject* obj = reinterpret_cast< SceneObject* >( object );
  553. if( obj->mObjectFlags.test( RenderEnabledFlag ) )
  554. return "true";
  555. else
  556. return "false";
  557. }
  558. //-----------------------------------------------------------------------------
  559. bool SceneObject::_setRenderEnabled( void *object, const char *index, const char *data )
  560. {
  561. SceneObject* obj = reinterpret_cast< SceneObject* >( object );
  562. obj->setRenderEnabled( dAtob( data ) );
  563. return false;
  564. }
  565. //-----------------------------------------------------------------------------
  566. bool SceneObject::isSelectionEnabled() const
  567. {
  568. AbstractClassRep *classRep = getClassRep();
  569. return ( mObjectFlags.test( SelectionEnabledFlag ) && classRep->isSelectionEnabled() );
  570. }
  571. //-----------------------------------------------------------------------------
  572. void SceneObject::setSelectionEnabled( bool value )
  573. {
  574. if( value )
  575. mObjectFlags.set( SelectionEnabledFlag );
  576. else
  577. mObjectFlags.clear( SelectionEnabledFlag );
  578. // Not synchronized on network so don't set dirty bit.
  579. }
  580. //-----------------------------------------------------------------------------
  581. const char* SceneObject::_getSelectionEnabled( void* object, const char* data )
  582. {
  583. SceneObject* obj = reinterpret_cast< SceneObject* >( object );
  584. if( obj->mObjectFlags.test( SelectionEnabledFlag ) )
  585. return "true";
  586. else
  587. return "false";
  588. }
  589. //-----------------------------------------------------------------------------
  590. bool SceneObject::_setSelectionEnabled( void *object, const char *index, const char *data )
  591. {
  592. SceneObject* obj = reinterpret_cast< SceneObject* >( object );
  593. obj->setSelectionEnabled( dAtob( data ) );
  594. return false;
  595. }
  596. //--------------------------------------------------------------------------
  597. U32 SceneObject::packUpdate( NetConnection* conn, U32 mask, BitStream* stream )
  598. {
  599. U32 retMask = Parent::packUpdate( conn, mask, stream );
  600. if ( stream->writeFlag( mask & FlagMask ) )
  601. stream->writeRangedU32( (U32)mObjectFlags, 0, getObjectFlagMax() );
  602. if ( mask & MountedMask )
  603. {
  604. if ( mMount.object )
  605. {
  606. S32 gIndex = conn->getGhostIndex( mMount.object );
  607. if ( stream->writeFlag( gIndex != -1 ) )
  608. {
  609. stream->writeFlag( true );
  610. stream->writeInt( gIndex, NetConnection::GhostIdBitSize );
  611. if ( stream->writeFlag( mMount.node != -1 ) )
  612. stream->writeInt( mMount.node, NumMountPointBits );
  613. mathWrite( *stream, mMount.xfm );
  614. }
  615. else
  616. // Will have to try again later
  617. retMask |= MountedMask;
  618. }
  619. else
  620. // Unmount if this isn't the initial packet
  621. if ( stream->writeFlag( !(mask & InitialUpdateMask) ) )
  622. stream->writeFlag( false );
  623. }
  624. else
  625. stream->writeFlag( false );
  626. return retMask;
  627. }
  628. //-----------------------------------------------------------------------------
  629. void SceneObject::unpackUpdate( NetConnection* conn, BitStream* stream )
  630. {
  631. Parent::unpackUpdate( conn, stream );
  632. // FlagMask
  633. if ( stream->readFlag() )
  634. mObjectFlags = stream->readRangedU32( 0, getObjectFlagMax() );
  635. // MountedMask
  636. if ( stream->readFlag() )
  637. {
  638. if ( stream->readFlag() )
  639. {
  640. S32 gIndex = stream->readInt( NetConnection::GhostIdBitSize );
  641. SceneObject* obj = dynamic_cast<SceneObject*>( conn->resolveGhost( gIndex ) );
  642. S32 node = -1;
  643. if ( stream->readFlag() ) // node != -1
  644. node = stream->readInt( NumMountPointBits );
  645. MatrixF xfm;
  646. mathRead( *stream, &xfm );
  647. if ( !obj )
  648. {
  649. conn->setLastError( "Invalid packet from server." );
  650. return;
  651. }
  652. obj->mountObject( this, node, xfm );
  653. }
  654. else
  655. unmount();
  656. }
  657. }
  658. //-----------------------------------------------------------------------------
  659. void SceneObject::_updateZoningState() const
  660. {
  661. if( mZoneRefDirty )
  662. {
  663. SceneZoneSpaceManager* manager = getSceneManager()->getZoneManager();
  664. if( manager )
  665. manager->updateObject( const_cast< SceneObject* >( this ) );
  666. else
  667. mZoneRefDirty = false;
  668. }
  669. }
  670. //-----------------------------------------------------------------------------
  671. U32 SceneObject::_getCurrZone( const U32 index ) const
  672. {
  673. _updateZoningState();
  674. // Not the most efficient way to do this, walking the list,
  675. // but it's an uncommon call...
  676. ZoneRef* walk = mZoneRefHead;
  677. for( U32 i = 0; i < index; ++ i )
  678. {
  679. walk = walk->nextInObj;
  680. AssertFatal( walk != NULL, "SceneObject::_getCurrZone - Too few object refs!" );
  681. }
  682. AssertFatal( walk != NULL, "SceneObject::_getCurrZone - Too few object refs!" );
  683. return walk->zone;
  684. }
  685. //-----------------------------------------------------------------------------
  686. Point3F SceneObject::getPosition() const
  687. {
  688. Point3F pos;
  689. mObjToWorld.getColumn(3, &pos);
  690. return pos;
  691. }
  692. //-----------------------------------------------------------------------------
  693. Point3F SceneObject::getRenderPosition() const
  694. {
  695. Point3F pos;
  696. mRenderObjToWorld.getColumn(3, &pos);
  697. return pos;
  698. }
  699. //-----------------------------------------------------------------------------
  700. void SceneObject::setPosition(const Point3F &pos)
  701. {
  702. AssertFatal( !mIsNaN( pos ), "SceneObject::setPosition() - The position is NaN!" );
  703. MatrixF xform = mObjToWorld;
  704. xform.setColumn(3, pos);
  705. setTransform(xform);
  706. }
  707. //-----------------------------------------------------------------------------
  708. F32 SceneObject::distanceTo(const Point3F &pnt) const
  709. {
  710. return mWorldBox.getDistanceToPoint( pnt );
  711. }
  712. //-----------------------------------------------------------------------------
  713. void SceneObject::processAfter( ProcessObject *obj )
  714. {
  715. AssertFatal( dynamic_cast<SceneObject*>( obj ), "SceneObject::processAfter - Got non-SceneObject!" );
  716. mAfterObject = (SceneObject*)obj;
  717. if ( mAfterObject->mAfterObject == this )
  718. mAfterObject->mAfterObject = NULL;
  719. getProcessList()->markDirty();
  720. }
  721. //-----------------------------------------------------------------------------
  722. void SceneObject::clearProcessAfter()
  723. {
  724. mAfterObject = NULL;
  725. }
  726. //-----------------------------------------------------------------------------
  727. void SceneObject::setProcessTick( bool t )
  728. {
  729. if ( t == mProcessTick )
  730. return;
  731. if ( mProcessTick )
  732. {
  733. plUnlink();
  734. mProcessTick = false;
  735. }
  736. else
  737. {
  738. // Just to be sure...
  739. plUnlink();
  740. getProcessList()->addObject( this );
  741. mProcessTick = true;
  742. }
  743. }
  744. //-----------------------------------------------------------------------------
  745. ProcessList* SceneObject::getProcessList() const
  746. {
  747. if ( isClientObject() )
  748. return ClientProcessList::get();
  749. else
  750. return ServerProcessList::get();
  751. }
  752. //-------------------------------------------------------------------------
  753. bool SceneObject::isMounted()
  754. {
  755. resolveMountPID();
  756. return mMount.object != NULL;
  757. }
  758. //-----------------------------------------------------------------------------
  759. S32 SceneObject::getMountedObjectCount()
  760. {
  761. S32 count = 0;
  762. for (SceneObject* itr = mMount.list; itr; itr = itr->mMount.link)
  763. count++;
  764. return count;
  765. }
  766. //-----------------------------------------------------------------------------
  767. SceneObject* SceneObject::getMountedObject(S32 idx)
  768. {
  769. if (idx >= 0) {
  770. S32 count = 0;
  771. for (SceneObject* itr = mMount.list; itr; itr = itr->mMount.link)
  772. if (count++ == idx)
  773. return itr;
  774. }
  775. return NULL;
  776. }
  777. //-----------------------------------------------------------------------------
  778. S32 SceneObject::getMountedObjectNode(S32 idx)
  779. {
  780. if (idx >= 0) {
  781. S32 count = 0;
  782. for (SceneObject* itr = mMount.list; itr; itr = itr->mMount.link)
  783. if (count++ == idx)
  784. return itr->mMount.node;
  785. }
  786. return -1;
  787. }
  788. //-----------------------------------------------------------------------------
  789. SceneObject* SceneObject::getMountNodeObject(S32 node)
  790. {
  791. for (SceneObject* itr = mMount.list; itr; itr = itr->mMount.link)
  792. if (itr->mMount.node == node)
  793. return itr;
  794. return NULL;
  795. }
  796. //-----------------------------------------------------------------------------
  797. bool SceneObject::_setMountPID( void* object, const char* index, const char* data )
  798. {
  799. SceneObject* so = static_cast<SceneObject*>( object );
  800. if ( so )
  801. {
  802. // Unmount old object (PID reference is released even if it had been resolved yet)
  803. if ( so->mMountPID )
  804. {
  805. so->mMountPID->decRefCount();
  806. so->mMountPID = NULL;
  807. }
  808. so->unmount();
  809. // Get the new PID (new object will be mounted on demand)
  810. Con::setData( TypePID, &so->mMountPID, 0, 1, &data );
  811. if ( so->mMountPID )
  812. so->mMountPID->incRefCount(); // Prevent PID from being deleted out from under us!
  813. }
  814. return false;
  815. }
  816. void SceneObject::resolveMountPID()
  817. {
  818. if ( mMountPID && !mMount.object )
  819. {
  820. SceneObject *obj = dynamic_cast< SceneObject* >( mMountPID->getObject() );
  821. if ( obj )
  822. obj->mountObject( this, mMount.node, mMount.xfm );
  823. }
  824. }
  825. //-----------------------------------------------------------------------------
  826. void SceneObject::mountObject( SceneObject *obj, S32 node, const MatrixF &xfm )
  827. {
  828. if ( obj->mMount.object == this )
  829. {
  830. // Already mounted to this
  831. // So update our node and xfm which may have changed.
  832. obj->mMount.node = node;
  833. obj->mMount.xfm = xfm;
  834. }
  835. else
  836. {
  837. if ( obj->mMount.object )
  838. obj->unmount();
  839. obj->mMount.object = this;
  840. obj->mMount.node = node;
  841. obj->mMount.link = mMount.list;
  842. obj->mMount.xfm = xfm;
  843. mMount.list = obj;
  844. // Assign PIDs to both objects
  845. if ( isServerObject() )
  846. {
  847. obj->getOrCreatePersistentId();
  848. if ( !obj->mMountPID )
  849. {
  850. obj->mMountPID = getOrCreatePersistentId();
  851. obj->mMountPID->incRefCount();
  852. }
  853. }
  854. obj->onMount( this, node );
  855. }
  856. }
  857. //-----------------------------------------------------------------------------
  858. void SceneObject::unmountObject( SceneObject *obj )
  859. {
  860. if ( obj->mMount.object == this )
  861. {
  862. // Find and unlink the object
  863. for ( SceneObject **ptr = &mMount.list; *ptr; ptr = &(*ptr)->mMount.link )
  864. {
  865. if ( *ptr == obj )
  866. {
  867. *ptr = obj->mMount.link;
  868. break;
  869. }
  870. }
  871. obj->mMount.object = NULL;
  872. obj->mMount.link = NULL;
  873. if( obj->mMountPID != NULL ) // Only on server.
  874. {
  875. obj->mMountPID->decRefCount();
  876. obj->mMountPID = NULL;
  877. }
  878. obj->onUnmount( this, obj->mMount.node );
  879. }
  880. }
  881. //-----------------------------------------------------------------------------
  882. void SceneObject::unmount()
  883. {
  884. if (mMount.object)
  885. mMount.object->unmountObject(this);
  886. }
  887. //-----------------------------------------------------------------------------
  888. void SceneObject::onMount( SceneObject *obj, S32 node )
  889. {
  890. deleteNotify( obj );
  891. if ( !isGhost() )
  892. {
  893. setMaskBits( MountedMask );
  894. //onMount_callback( node );
  895. }
  896. }
  897. //-----------------------------------------------------------------------------
  898. void SceneObject::onUnmount( SceneObject *obj, S32 node )
  899. {
  900. clearNotify(obj);
  901. if ( !isGhost() )
  902. {
  903. setMaskBits( MountedMask );
  904. //onUnmount_callback( node );
  905. }
  906. }
  907. //-----------------------------------------------------------------------------
  908. void SceneObject::getMountTransform( S32 index, const MatrixF &xfm, MatrixF *outMat )
  909. {
  910. MatrixF mountTransform( xfm );
  911. const Point3F &scale = getScale();
  912. Point3F position = mountTransform.getPosition();
  913. position.convolve( scale );
  914. mountTransform.setPosition( position );
  915. outMat->mul( mObjToWorld, mountTransform );
  916. }
  917. //-----------------------------------------------------------------------------
  918. void SceneObject::getRenderMountTransform( F32 delta, S32 index, const MatrixF &xfm, MatrixF *outMat )
  919. {
  920. MatrixF mountTransform( xfm );
  921. const Point3F &scale = getScale();
  922. Point3F position = mountTransform.getPosition();
  923. position.convolve( scale );
  924. mountTransform.setPosition( position );
  925. outMat->mul( mRenderObjToWorld, mountTransform );
  926. }
  927. //=============================================================================
  928. // Console API.
  929. //=============================================================================
  930. // MARK: ---- Console API ----
  931. //-----------------------------------------------------------------------------
  932. DefineEngineMethod( SceneObject, getType, S32, (),,
  933. "Return the type mask for this object.\n"
  934. "@return The numeric type mask for the object." )
  935. {
  936. return object->getTypeMask();
  937. }
  938. //-----------------------------------------------------------------------------
  939. DefineEngineMethod( SceneObject, mountObject, bool,
  940. ( SceneObject* objB, S32 slot, TransformF txfm ), ( MatrixF::Identity ),
  941. "@brief Mount objB to this object at the desired slot with optional transform.\n\n"
  942. "@param objB Object to mount onto us\n"
  943. "@param slot Mount slot ID\n"
  944. "@param txfm (optional) mount offset transform\n"
  945. "@return true if successful, false if failed (objB is not valid)" )
  946. {
  947. if ( objB )
  948. {
  949. object->mountObject( objB, slot, txfm.getMatrix() );
  950. return true;
  951. }
  952. return false;
  953. }
  954. //-----------------------------------------------------------------------------
  955. DefineEngineMethod( SceneObject, unmountObject, bool, ( SceneObject* target ),,
  956. "@brief Unmount an object from ourselves.\n\n"
  957. "@param target object to unmount\n"
  958. "@return true if successful, false if failed\n" )
  959. {
  960. if ( target )
  961. {
  962. object->unmountObject(target);
  963. return true;
  964. }
  965. return false;
  966. }
  967. //-----------------------------------------------------------------------------
  968. DefineEngineMethod( SceneObject, unmount, void, (),,
  969. "Unmount us from the currently mounted object if any.\n" )
  970. {
  971. object->unmount();
  972. }
  973. //-----------------------------------------------------------------------------
  974. DefineEngineMethod( SceneObject, isMounted, bool, (),,
  975. "@brief Check if we are mounted to another object.\n\n"
  976. "@return true if mounted to another object, false if not mounted." )
  977. {
  978. return object->isMounted();
  979. }
  980. //-----------------------------------------------------------------------------
  981. DefineEngineMethod( SceneObject, getObjectMount, S32, (),,
  982. "@brief Get the object we are mounted to.\n\n"
  983. "@return the SimObjectID of the object we're mounted to, or 0 if not mounted." )
  984. {
  985. return object->isMounted()? object->getObjectMount()->getId(): 0;
  986. }
  987. //-----------------------------------------------------------------------------
  988. DefineEngineMethod( SceneObject, getMountedObjectCount, S32, (),,
  989. "Get the number of objects mounted to us.\n"
  990. "@return the number of mounted objects." )
  991. {
  992. return object->getMountedObjectCount();
  993. }
  994. //-----------------------------------------------------------------------------
  995. DefineEngineMethod( SceneObject, getMountedObject, S32, ( S32 slot ),,
  996. "Get the object mounted at a particular slot.\n"
  997. "@param slot mount slot index to query\n"
  998. "@return ID of the object mounted in the slot, or 0 if no object." )
  999. {
  1000. SceneObject* mobj = object->getMountedObject( slot );
  1001. return mobj? mobj->getId(): 0;
  1002. }
  1003. //-----------------------------------------------------------------------------
  1004. DefineEngineMethod( SceneObject, getMountedObjectNode, S32, ( S32 slot ),,
  1005. "@brief Get the mount node index of the object mounted at our given slot.\n\n"
  1006. "@param slot mount slot index to query\n"
  1007. "@return index of the mount node used by the object mounted in this slot." )
  1008. {
  1009. return object->getMountedObjectNode( slot );
  1010. }
  1011. //-----------------------------------------------------------------------------
  1012. DefineEngineMethod( SceneObject, getMountNodeObject, S32, ( S32 node ),,
  1013. "@brief Get the object mounted at our given node index.\n\n"
  1014. "@param node mount node index to query\n"
  1015. "@return ID of the first object mounted at the node, or 0 if none found." )
  1016. {
  1017. SceneObject* mobj = object->getMountNodeObject( node );
  1018. return mobj? mobj->getId(): 0;
  1019. }
  1020. //-----------------------------------------------------------------------------
  1021. DefineEngineMethod( SceneObject, getTransform, TransformF, (),,
  1022. "Get the object's transform.\n"
  1023. "@return the current transform of the object\n" )
  1024. {
  1025. return object->getTransform();
  1026. }
  1027. //-----------------------------------------------------------------------------
  1028. DefineEngineMethod( SceneObject, getInverseTransform, TransformF, (),,
  1029. "Get the object's inverse transform.\n"
  1030. "@return the inverse transform of the object\n" )
  1031. {
  1032. return object->getWorldTransform();
  1033. }
  1034. //-----------------------------------------------------------------------------
  1035. DefineEngineMethod( SceneObject, getPosition, Point3F, (),,
  1036. "Get the object's world position.\n"
  1037. "@return the current world position of the object\n" )
  1038. {
  1039. return object->getTransform().getPosition();
  1040. }
  1041. DefineEngineMethod( SceneObject, setPosition, void, (Point3F pos),,
  1042. "Set the object's world position.\n"
  1043. "@param pos the new world position of the object\n" )
  1044. {
  1045. return object->setPosition(pos);
  1046. }
  1047. //-----------------------------------------------------------------------------
  1048. DefineEngineMethod( SceneObject, getEulerRotation, Point3F, (),,
  1049. "Get Euler rotation of this object.\n"
  1050. "@return the orientation of the object in the form of rotations around the "
  1051. "X, Y and Z axes in degrees.\n" )
  1052. {
  1053. Point3F euler = object->getTransform().toEuler();
  1054. // Convert to degrees.
  1055. euler.x = mRadToDeg( euler.x );
  1056. euler.y = mRadToDeg( euler.y );
  1057. euler.z = mRadToDeg( euler.z );
  1058. return euler;
  1059. }
  1060. //-----------------------------------------------------------------------------
  1061. DefineEngineMethod( SceneObject, getForwardVector, VectorF, (),,
  1062. "Get the direction this object is facing.\n"
  1063. "@return a vector indicating the direction this object is facing.\n"
  1064. "@note This is the object's y axis." )
  1065. {
  1066. return object->getTransform().getForwardVector();
  1067. }
  1068. //-----------------------------------------------------------------------------
  1069. DefineEngineMethod( SceneObject, getRightVector, VectorF, (),,
  1070. "Get the right vector of the object.\n"
  1071. "@return a vector indicating the right direction of this object."
  1072. "@note This is the object's x axis." )
  1073. {
  1074. return object->getTransform().getRightVector();
  1075. }
  1076. //-----------------------------------------------------------------------------
  1077. DefineEngineMethod( SceneObject, getUpVector, VectorF, (),,
  1078. "Get the up vector of the object.\n"
  1079. "@return a vector indicating the up direction of this object."
  1080. "@note This is the object's z axis." )
  1081. {
  1082. return object->getTransform().getUpVector();
  1083. }
  1084. //-----------------------------------------------------------------------------
  1085. DefineEngineMethod( SceneObject, setTransform, void, ( TransformF txfm ),,
  1086. "Set the object's transform (orientation and position)."
  1087. "@param txfm object transform to set" )
  1088. {
  1089. if ( !txfm.hasRotation() )
  1090. object->setPosition( txfm.getPosition() );
  1091. else
  1092. object->setTransform( txfm.getMatrix() );
  1093. }
  1094. //-----------------------------------------------------------------------------
  1095. DefineEngineMethod( SceneObject, getScale, Point3F, (),,
  1096. "Get the object's scale.\n"
  1097. "@return object scale as a Point3F" )
  1098. {
  1099. return object->getScale();
  1100. }
  1101. //-----------------------------------------------------------------------------
  1102. DefineEngineMethod( SceneObject, setScale, void, ( Point3F scale ),,
  1103. "Set the object's scale.\n"
  1104. "@param scale object scale to set\n" )
  1105. {
  1106. object->setScale( scale );
  1107. }
  1108. //-----------------------------------------------------------------------------
  1109. DefineEngineMethod( SceneObject, getWorldBox, Box3F, (),,
  1110. "Get the object's world bounding box.\n"
  1111. "@return six fields, two Point3Fs, containing the min and max points of the "
  1112. "worldbox." )
  1113. {
  1114. return object->getWorldBox();
  1115. }
  1116. //-----------------------------------------------------------------------------
  1117. DefineEngineMethod( SceneObject, getWorldBoxCenter, Point3F, (),,
  1118. "Get the center of the object's world bounding box.\n"
  1119. "@return the center of the world bounding box for this object." )
  1120. {
  1121. Point3F center;
  1122. object->getWorldBox().getCenter( &center );
  1123. return center;
  1124. }
  1125. //-----------------------------------------------------------------------------
  1126. DefineEngineMethod( SceneObject, getObjectBox, Box3F, (),,
  1127. "Get the object's bounding box (relative to the object's origin).\n"
  1128. "@return six fields, two Point3Fs, containing the min and max points of the "
  1129. "objectbox." )
  1130. {
  1131. return object->getObjBox();
  1132. }
  1133. //-----------------------------------------------------------------------------
  1134. DefineEngineMethod( SceneObject, isGlobalBounds, bool, (),,
  1135. "Check if this object has a global bounds set.\n"
  1136. "If global bounds are set to be true, then the object is assumed to have an "
  1137. "infinitely large bounding box for collision and rendering purposes.\n"
  1138. "@return true if the object has a global bounds." )
  1139. {
  1140. return object->isGlobalBounds();
  1141. }