SceneObject.h 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781
  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. #ifndef _SCENE_OBJECT_H_
  23. #define _SCENE_OBJECT_H_
  24. #ifndef _SCENE_H_
  25. #include "2d/scene/Scene.h"
  26. #endif
  27. #ifndef _DEBUG_STATS_H_
  28. #include "2d/scene/DebugStats.h"
  29. #endif
  30. #ifndef _SIMBASE_H_
  31. #include "sim/simBase.h"
  32. #endif
  33. #ifndef _MMATH_H_
  34. #include "math/mMath.h"
  35. #endif
  36. #ifndef _SCENE_WINDOW_H_
  37. #include "2d/gui/SceneWindow.h"
  38. #endif
  39. #ifndef _BATCH_RENDER_H_
  40. #include "2d/core/BatchRender.h"
  41. #endif
  42. #ifndef _UTILITY_H_
  43. #include "2d/core/Utility.h"
  44. #endif
  45. #ifndef _PHYSICS_PROXY_H_
  46. #include "2d/scene/PhysicsProxy.h"
  47. #endif
  48. #ifndef _SCENE_RENDER_OBJECT_H_
  49. #include "2d/scene/SceneRenderObject.h"
  50. #endif
  51. #ifndef _BEHAVIOR_COMPONENT_H_
  52. #include "component/behaviors/behaviorComponent.h"
  53. #endif
  54. #ifndef _BEHAVIORINSTANCE_H_
  55. #include "component/behaviors/behaviorInstance.h"
  56. #endif
  57. //-----------------------------------------------------------------------------
  58. struct tDestroyNotification
  59. {
  60. SceneObject* mpSceneObject;
  61. U32 mRefCount;
  62. };
  63. //-----------------------------------------------------------------------------
  64. typedef VectorPtr<b2FixtureDef*> typeCollisionFixtureDefVector;
  65. typedef VectorPtr<b2Fixture*> typeCollisionFixtureVector;
  66. typedef Vector<tDestroyNotification> typeDestroyNotificationVector;
  67. //-----------------------------------------------------------------------------
  68. const S32 GL_INVALID_BLEND_FACTOR = -1;
  69. const S32 INVALID_COLLISION_SHAPE_INDEX = -1;
  70. //-----------------------------------------------------------------------------
  71. extern EnumTable bodyTypeTable;
  72. extern EnumTable srcBlendFactorTable;
  73. extern EnumTable dstBlendFactorTable;
  74. //-----------------------------------------------------------------------------
  75. class SceneObject :
  76. public BehaviorComponent,
  77. public SceneRenderObject,
  78. public PhysicsProxy
  79. {
  80. private:
  81. typedef BehaviorComponent Parent;
  82. public:
  83. friend class Scene;
  84. friend class SceneWindow;
  85. friend class ContactFilter;
  86. friend class WorldQuery;
  87. friend class DebugDraw;
  88. friend class SceneObjectRotateToEvent;
  89. protected:
  90. /// Scene.
  91. SimObjectPtr<Scene> mpScene;
  92. /// Target Scene.
  93. /// NOTE: Unfortunately this is required as the scene can be set via a field which
  94. /// occurs before the object is registered with the simulation therefore
  95. /// any simulation related functionality cannot be used such as TorqueScript
  96. /// callbacks.
  97. SimObjectPtr<Scene> mpTargetScene;
  98. /// Lifetime.
  99. F32 mLifetime;
  100. bool mLifetimeActive;
  101. /// Scene layers.
  102. U32 mSceneLayer;
  103. U32 mSceneLayerMask;
  104. F32 mSceneLayerDepth;
  105. /// Scene groups.
  106. U32 mSceneGroup;
  107. U32 mSceneGroupMask;
  108. /// Area.
  109. Vector2 mSize;
  110. bool mAutoSizing;
  111. b2AABB mPreTickAABB;
  112. b2AABB mCurrentAABB;
  113. Vector2 mLocalSizeOOBB[4];
  114. Vector2 mRenderOOBB[4];
  115. S32 mWorldProxyId;
  116. // Growing
  117. bool mGrowActive;
  118. Vector2 mTargetSize;
  119. Vector2 mDeltaSize;
  120. /// Position / Angle.
  121. Vector2 mPreTickPosition;
  122. F32 mPreTickAngle;
  123. Vector2 mRenderPosition;
  124. F32 mRenderAngle;
  125. bool mSpatialDirty;
  126. Vector2 mLastCheckedPosition;
  127. Vector2 mTargetPosition;
  128. bool mTargetPositionActive;
  129. F32 mDistanceToTarget;
  130. F32 mTargetPositionMargin;
  131. bool mTargetPositionFound;
  132. bool mSnapToTargetPosition;
  133. bool mStopAtTargetPosition;
  134. /// Body.
  135. b2Body* mpBody;
  136. b2BodyDef mBodyDefinition;
  137. U32 mWorldQueryKey;
  138. /// Collision control.
  139. U32 mCollisionLayerMask;
  140. U32 mCollisionGroupMask;
  141. bool mCollisionSuppress;
  142. bool mCollisionOneWay;
  143. b2FixtureDef mDefaultFixture;
  144. bool mGatherContacts;
  145. Scene::typeContactVector* mpCurrentContacts;
  146. /// General collision shape access.
  147. typeCollisionFixtureDefVector mCollisionFixtureDefs;
  148. typeCollisionFixtureVector mCollisionFixtures;
  149. /// Render visibility.
  150. bool mVisible;
  151. /// Render blending.
  152. bool mBlendMode;
  153. S32 mSrcBlendFactor;
  154. S32 mDstBlendFactor;
  155. ColorF mBlendColor;
  156. F32 mAlphaTest;
  157. // Fading
  158. bool mFadeActive;
  159. ColorF mTargetColor;
  160. F32 mDeltaRed;
  161. F32 mDeltaGreen;
  162. F32 mDeltaBlue;
  163. F32 mDeltaAlpha;
  164. /// Render sorting.
  165. Vector2 mSortPoint;
  166. /// Input events.
  167. bool mUseInputEvents;
  168. /// Script callbacks.
  169. bool mUpdateCallback;
  170. bool mCollisionCallback;
  171. bool mSleepingCallback;
  172. bool mLastAwakeState;
  173. /// Debug mode.
  174. U32 mDebugMask;
  175. /// Camera mounting.
  176. SceneWindow* mpAttachedCamera;
  177. /// GUI attachment.
  178. bool mAttachedGuiSizeControl;
  179. GuiControl* mpAttachedGui;
  180. SceneWindow* mpAttachedGuiSceneWindow;
  181. /// Safe deletion.
  182. bool mBeingSafeDeleted;
  183. bool mSafeDeleteReady;
  184. /// Destroy notifications.
  185. typeDestroyNotificationVector mDestroyNotifyList;
  186. /// Miscellaneous.
  187. bool mBatchIsolated;
  188. U32 mSerialiseKey;
  189. bool mEditorTickAllowed;
  190. bool mPickingAllowed;
  191. bool mAlwaysInScope;
  192. U32 mRotateToEventId;
  193. U32 mSerialId;
  194. StringTableEntry mRenderGroup;
  195. protected:
  196. static S32 QSORT_CALLBACK sceneObjectLayerDepthSort(const void* a, const void* b);
  197. /// Scene (un)registering.
  198. virtual void OnRegisterScene( Scene* pScene );
  199. virtual void OnUnregisterScene( Scene* pScene );
  200. /// Ticking.
  201. void resetTickSpatials( const bool resize = false );
  202. inline bool getSpatialDirty( void ) const { return mSpatialDirty; }
  203. /// Contact processing.
  204. void initializeContactGathering( void );
  205. /// Taml callbacks.
  206. virtual void onTamlCustomWrite( TamlCustomNodes& customNodes );
  207. virtual void onTamlCustomRead( const TamlCustomNodes& customNodes );
  208. // Effect Processing.
  209. F32 processEffect( const F32 current, const F32 target, const F32 rate );
  210. public:
  211. SceneObject();
  212. virtual ~SceneObject();
  213. /// Engine.
  214. virtual bool onAdd();
  215. virtual void onRemove();
  216. virtual void onDestroyNotify( SceneObject* pSceneObject );
  217. static void initPersistFields();
  218. /// Integration.
  219. virtual void preIntegrate( const F32 totalTime, const F32 elapsedTime, DebugStats* pDebugStats );
  220. virtual void integrateObject( const F32 totalTime, const F32 elapsedTime, DebugStats* pDebugStats );
  221. virtual void postIntegrate(const F32 totalTime, const F32 elapsedTime, DebugStats *pDebugStats);
  222. virtual void interpolateObject( const F32 timeDelta );
  223. inline bool getIsEditorTickAllowed( void ) const { return mEditorTickAllowed; }
  224. /// Render batching.
  225. inline void setBatchIsolated( const bool batchIsolated ) { mBatchIsolated = batchIsolated; }
  226. virtual bool getBatchIsolated( void ) { return mBatchIsolated; }
  227. virtual bool isBatchRendered( void ) { return true; }
  228. virtual bool validRender( void ) const { return true; }
  229. virtual bool shouldRender( void ) const { return false; }
  230. /// Render Output.
  231. virtual bool canPrepareRender( void ) const { return false; }
  232. virtual void scenePrepareRender( const SceneRenderState* pSceneRenderState, SceneRenderQueue* pSceneRenderQueue ) {}
  233. virtual void sceneRender( const SceneRenderState* pSceneRenderState, const SceneRenderRequest* pSceneRenderRequest, BatchRender* pBatchRenderer ) {}
  234. virtual void sceneRenderFallback( const SceneRenderState* pSceneRenderState, const SceneRenderRequest* pSceneRenderRequest, BatchRender* pBatchRenderer );
  235. virtual void sceneRenderOverlay( const SceneRenderState* pSceneRenderState );
  236. /// Networking.
  237. virtual U32 packUpdate(NetConnection * conn, U32 mask, BitStream *stream);
  238. virtual void unpackUpdate(NetConnection * conn, BitStream *stream);
  239. /// Scene.
  240. inline Scene* const getScene( void ) const { return mpScene; }
  241. inline F32 getSceneTime( void ) const { if ( mpScene ) return mpScene->getSceneTime(); else return 0.0f; }
  242. /// Enabled.
  243. virtual void setEnabled( const bool enabled );
  244. /// Lifetime.
  245. void setLifetime( const F32 lifetime );
  246. inline F32 getLifetime( void ) const { return mLifetime; }
  247. void updateLifetime( const F32 elapsedTime );
  248. /// Scene layers.
  249. void setSceneLayer( const U32 sceneLayer );
  250. inline U32 getSceneLayer(void) const { return mSceneLayer; }
  251. inline U32 getSceneLayerMask( void ) const { return mSceneLayerMask; }
  252. /// Scene Layer depth.
  253. inline void setSceneLayerDepth( const F32 order ) { mSceneLayerDepth = order; };
  254. inline F32 getSceneLayerDepth( void ) const { return mSceneLayerDepth; }
  255. bool setSceneLayerDepthFront( void );
  256. bool setSceneLayerDepthBack( void );
  257. bool setSceneLayerDepthForward( void );
  258. bool setSceneLayerDepthBackward( void );
  259. /// Scene groups.
  260. void setSceneGroup( const U32 sceneGroup );
  261. inline U32 getSceneGroup(void ) const { return mSceneGroup; }
  262. inline U32 getSceneGroupMask( void ) const { return mSceneGroupMask; }
  263. /// Area.
  264. virtual void setArea( const Vector2& corner1, const Vector2& corner2 );
  265. inline bool getAutoSizing( void ) const { return mAutoSizing; }
  266. virtual void setSize( const Vector2& size );
  267. inline void setSize( const F32 width, const F32 height ){ setSize( Vector2(width, height) ); }
  268. inline Vector2 getSize( void ) const { return mSize; }
  269. inline Vector2 getHalfSize( void ) const { return mSize * 0.5f; }
  270. inline b2AABB getAABB( void ) const { return mCurrentAABB; }
  271. inline RectF getAABBRectangle( void ) const { const b2Vec2 size = mCurrentAABB.upperBound-mCurrentAABB.lowerBound; return RectF( mCurrentAABB.lowerBound.x, mCurrentAABB.lowerBound.y, size.x, size.y ); }
  272. inline S32 getWorldProxy( void ) const { return mWorldProxyId; }
  273. /// Position / Angle.
  274. virtual void setPosition( const Vector2& position );
  275. inline Vector2 getPosition(void) const { if ( mpScene ) return mpBody->GetPosition(); else return mBodyDefinition.position; }
  276. inline Vector2 getRenderPosition(void) const { return mRenderPosition; }
  277. inline F32 getRenderAngle(void) const { return mRenderAngle; }
  278. inline const b2Vec2* getRenderOOBB(void) const { return mRenderOOBB; }
  279. inline const b2Vec2* getLocalSizedOOBB( void ) const { return mLocalSizeOOBB; }
  280. virtual void setAngle( const F32 radians );
  281. inline F32 getAngle(void) const { if ( mpScene ) return mpBody->GetAngle(); else return mBodyDefinition.angle; }
  282. virtual void setFixedAngle( const bool fixed ) { if ( mpScene ) mpBody->SetFixedRotation( fixed ); else mBodyDefinition.fixedRotation = fixed; }
  283. inline bool getFixedAngle(void) const { if ( mpScene ) return mpBody->IsFixedRotation(); else return mBodyDefinition.fixedRotation; }
  284. b2Transform getTransform( void ) const { if ( mpScene ) return mpBody->GetTransform(); else return b2Transform( mBodyDefinition.position, b2Rot(mBodyDefinition.angle) ); }
  285. b2Transform getRenderTransform( void ) const { return b2Transform( getRenderPosition(), b2Rot( getRenderAngle()) ); }
  286. inline Vector2 getLocalCenter(void) const { if ( mpScene ) return mpBody->GetLocalCenter(); else return b2Vec2_zero; }
  287. inline Vector2 getWorldCenter(void) const { if ( mpScene ) return mpBody->GetWorldCenter(); else return mBodyDefinition.position; }
  288. Vector2 getLocalPoint( const Vector2& worldPoint );
  289. Vector2 getWorldPoint( const Vector2& localPoint );
  290. Vector2 getLocalVector( const Vector2& worldVector );
  291. Vector2 getWorldVector( const Vector2& localVector );
  292. bool getIsPointInOOBB( const Vector2& worldPoint );
  293. bool getIsPointInCollisionShape( const U32 shapeIndex, const Vector2& worldPoint );
  294. /// Body.
  295. virtual ePhysicsProxyType getPhysicsProxyType( void ) const { return PhysicsProxy::PHYSIC_PROXY_SCENEOBJECT; }
  296. inline b2Body* getBody( void ) const { return mpBody; }
  297. void setBodyType( const b2BodyType type );
  298. inline b2BodyType getBodyType(void) const { if ( mpScene ) return mpBody->GetType(); else return mBodyDefinition.type; }
  299. inline void setActive( const bool active ) { if ( mpScene ) mpBody->SetActive( active ); else mBodyDefinition.active = active; }
  300. inline bool getActive(void) const { if ( mpScene ) return mpBody->IsActive(); else return mBodyDefinition.active; }
  301. inline void setAwake( const bool awake ) { if ( mpScene ) mpBody->SetAwake( awake ); else mBodyDefinition.awake = awake; }
  302. inline bool getAwake(void) const { if ( mpScene ) return mpBody->IsAwake(); else return mBodyDefinition.awake; }
  303. inline void setBullet( const bool bullet ) { if ( mpScene ) mpBody->SetBullet( bullet ); else mBodyDefinition.bullet = bullet; }
  304. inline bool getBullet(void) const { if ( mpScene ) return mpBody->IsBullet(); else return mBodyDefinition.bullet; }
  305. inline void setSleepingAllowed( const bool allowed ) { if ( mpScene ) mpBody->SetSleepingAllowed( allowed ); else mBodyDefinition.allowSleep = allowed; }
  306. inline bool getSleepingAllowed(void) const { if ( mpScene ) return mpBody->IsSleepingAllowed(); else return mBodyDefinition.allowSleep; }
  307. inline F32 getMass( void ) const { if ( mpScene ) return mpBody->GetMass(); else return 0.0f; }
  308. inline F32 getInertia( void ) const { if ( mpScene ) return mpBody->GetInertia(); else return 0.0f; }
  309. /// Collision control.
  310. void setCollisionAgainst( const SceneObject* pSceneObject, const bool clearMasks );
  311. inline void setCollisionGroupMask( const U32 groupMask ) { mCollisionGroupMask = groupMask; }
  312. inline U32 getCollisionGroupMask(void) const { return mCollisionGroupMask; }
  313. inline void setCollisionLayerMask( const U32 layerMask ) { mCollisionLayerMask = layerMask; }
  314. inline U32 getCollisionLayerMask(void) const { return mCollisionLayerMask; }
  315. void setDefaultDensity( const F32 density, const bool updateShapes = true );
  316. inline F32 getDefaultDensity( void ) const { return mDefaultFixture.density; }
  317. void setDefaultFriction( const F32 friction, const bool updateShapes = true );
  318. inline F32 getDefaultFriction( void ) const { return mDefaultFixture.friction; }
  319. void setDefaultRestitution( const F32 restitution, const bool updateShapes = true );
  320. inline F32 getDefaultRestitution( void ) const { return mDefaultFixture.restitution; }
  321. inline void setCollisionSuppress( const bool status ) { mCollisionSuppress = status; }
  322. inline bool getCollisionSuppress(void) const { return mCollisionSuppress; }
  323. inline void setCollisionOneWay( const bool status ) { mCollisionOneWay = status; }
  324. inline bool getCollisionOneWay(void) const { return mCollisionOneWay; }
  325. inline const Scene::typeContactVector* getCurrentContacts( void ) const { return mpCurrentContacts; }
  326. inline U32 getCurrentContactCount( void ) const { if ( mpCurrentContacts != NULL ) return mpCurrentContacts->size(); else return 0; }
  327. virtual void setGatherContacts( const bool gatherContacts ) { mGatherContacts = gatherContacts; initializeContactGathering(); }
  328. inline bool getGatherContacts( void ) const { return mGatherContacts; }
  329. virtual void onBeginCollision( const TickContact& tickContact );
  330. virtual void onEndCollision( const TickContact& tickContact );
  331. /// Velocities.
  332. inline void setLinearVelocity( const Vector2& velocity ) { if ( mpScene ) mpBody->SetLinearVelocity( velocity ); else mBodyDefinition.linearVelocity = velocity; }
  333. inline Vector2 getLinearVelocity(void) const { if ( mpScene ) return mpBody->GetLinearVelocity(); else return mBodyDefinition.linearVelocity; }
  334. inline Vector2 getLinearVelocityFromWorldPoint( const Vector2& worldPoint ) { if ( mpScene ) return mpBody->GetLinearVelocityFromWorldPoint( worldPoint ); else return mBodyDefinition.linearVelocity; }
  335. inline Vector2 getLinearVelocityFromLocalPoint( const Vector2& localPoint ) { if ( mpScene ) return mpBody->GetLinearVelocityFromLocalPoint( localPoint ); else return mBodyDefinition.linearVelocity; }
  336. inline void setAngularVelocity( const F32 velocity ) { if ( mpScene ) mpBody->SetAngularVelocity( velocity ); else mBodyDefinition.angularVelocity = velocity; }
  337. inline F32 getAngularVelocity(void) const { if ( mpScene ) return mpBody->GetAngularVelocity(); else return mBodyDefinition.angularVelocity; }
  338. inline void setLinearDamping( const F32 damping ) { if ( mpScene ) mpBody->SetLinearDamping( damping ); else mBodyDefinition.linearDamping = damping; }
  339. inline F32 getLinearDamping(void) const { if ( mpScene ) return mpBody->GetLinearDamping(); else return mBodyDefinition.linearDamping; }
  340. inline void setAngularDamping( const F32 damping ) { if ( mpScene ) mpBody->SetAngularDamping( damping ); else mBodyDefinition.angularDamping = damping; }
  341. inline F32 getAngularDamping(void) const { if ( mpScene ) return mpBody->GetAngularDamping(); else return mBodyDefinition.angularDamping; }
  342. /// Move/Rotate to.
  343. bool moveTo(const Vector2& targetWorldPoint, const F32 speed, const bool autoStop = true, const bool snapToTarget = true, const F32 margin = 0.1f);
  344. bool rotateTo( const F32 targetAngle, const F32 speed, const bool autoStop = true, const bool warpToTarget = true );
  345. void cancelMoveTo( const bool autoStop = true );
  346. void cancelRotateTo( const bool autoStop = true );
  347. inline bool isMoveToComplete( void ) const { return !mTargetPositionActive; }
  348. inline bool isRotateToComplete( void ) const { return mRotateToEventId == 0; }
  349. void updateTargetPosition( void );
  350. // Fade to
  351. bool fadeTo( const ColorF& targetColor, const F32 deltaRed, const F32 deltaGreen, const F32 deltaBlue, const F32 deltaAlpha );
  352. inline void cancelFadeTo( void ) { mFadeActive = false; }
  353. inline bool isFadeToComplete( void ) const { return !mFadeActive; }
  354. void updateBlendColor( const F32 elapsedTime );
  355. // Grow to
  356. bool growTo( const Vector2& targetSize, const Vector2& deltaSize );
  357. inline void cancelGrowTo(void) { mGrowActive = false; }
  358. inline bool isGrowToComplete(void) const { return !mGrowActive; }
  359. void updateSize(const F32 elapsedTime);
  360. /// Force and impulse.
  361. void applyForce( const Vector2& worldForce, const bool wake = true );
  362. void applyForce( const Vector2& worldForce, const Vector2& worldPoint, const bool wake = true);
  363. void applyTorque( const F32 torque, const bool wake = true );
  364. void applyLinearImpulse( const Vector2& worldImpulse, const bool wake = true );
  365. void applyLinearImpulse( const Vector2& worldImpulse, const Vector2& worldPoint, const bool wake = true );
  366. void applyAngularImpulse( const F32 impulse, const bool wake = true );
  367. /// Gravity scaling.
  368. inline void setGravityScale( const F32 scale ) { if ( mpScene ) mpBody->SetGravityScale( scale ); else mBodyDefinition.gravityScale = scale; }
  369. inline F32 getGravityScale(void) const { if ( mpScene ) return mpBody->GetGravityScale(); else return mBodyDefinition.gravityScale; }
  370. /// General collision shape access.
  371. void deleteCollisionShape( const U32 shapeIndex );
  372. void clearCollisionShapes( void );
  373. inline U32 getCollisionShapeCount( void ) const { if ( mpScene ) return mCollisionFixtures.size(); else return mCollisionFixtureDefs.size(); }
  374. b2Shape::Type getCollisionShapeType( const U32 shapeIndex ) const;
  375. S32 getCollisionShapeIndex( const b2Fixture* pFixture ) const;
  376. void setCollisionShapeDefinition( const U32 shapeIndex, const b2FixtureDef& fixtureDef );
  377. b2FixtureDef getCollisionShapeDefinition( const U32 shapeIndex ) const;
  378. const b2CircleShape* getCollisionCircleShape( const U32 shapeIndex ) const;
  379. const b2PolygonShape* getCollisionPolygonShape( const U32 shapeIndex ) const;
  380. const b2ChainShape* getCollisionChainShape( const U32 shapeIndex ) const;
  381. const b2EdgeShape* getCollisionEdgeShape( const U32 shapeIndex ) const;
  382. void setCollisionShapeDensity( const U32 shapeIndex, const F32 density );
  383. F32 getCollisionShapeDensity( const U32 shapeIndex ) const;
  384. void setCollisionShapeFriction( const U32 shapeIndex, const F32 friction );
  385. F32 getCollisionShapeFriction( const U32 shapeIndex ) const;
  386. void setCollisionShapeRestitution( const U32 shapeIndex, const F32 restitution );
  387. F32 getCollisionShapeRestitution( const U32 shapeIndex ) const;
  388. void setCollisionShapeIsSensor( const U32 shapeIndex, const bool isSensor );
  389. bool getCollisionShapeIsSensor( const U32 shapeIndex ) const;
  390. /// Circle collision shape creation.
  391. S32 createCircleCollisionShape( const F32 radius );
  392. S32 createCircleCollisionShape( const F32 radius, const b2Vec2& localPosition );
  393. /// Circle collision shape access.
  394. F32 getCircleCollisionShapeRadius( const U32 shapeIndex ) const;
  395. Vector2 getCircleCollisionShapeLocalPosition( const U32 shapeIndex ) const;
  396. /// Polygon collision shape creation.
  397. S32 createPolygonCollisionShape( const U32 pointCount, const b2Vec2* localPoints );
  398. S32 createPolygonBoxCollisionShape( const F32 width, const F32 height );
  399. S32 createPolygonBoxCollisionShape( const F32 width, const F32 height, const b2Vec2& localCentroid );
  400. S32 createPolygonBoxCollisionShape( const F32 width, const F32 height, const b2Vec2& localCentroid, const F32 rotation );
  401. /// Polygon collision shape access.
  402. U32 getPolygonCollisionShapePointCount( const U32 shapeIndex ) const;
  403. Vector2 getPolygonCollisionShapeLocalPoint( const U32 shapeIndex, const U32 pointIndex ) const;
  404. /// Chain collision shape creation.
  405. S32 createChainCollisionShape( const U32 pointCount, const b2Vec2* localPoints );
  406. S32 createChainCollisionShape( const U32 pointCount, const b2Vec2* localPoints,
  407. const bool hasAdjacentLocalPositionStart, const bool hasAdjacentLocalPositionEnd,
  408. const b2Vec2& adjacentLocalPositionStart, const b2Vec2& adjacentLocalPositionEnd );
  409. /// Chain collision shape access.
  410. U32 getChainCollisionShapePointCount( const U32 shapeIndex ) const;
  411. Vector2 getChainCollisionShapeLocalPoint( const U32 shapeIndex, const U32 pointIndex ) const;
  412. bool getChainCollisionShapeHasAdjacentStart( const U32 shapeIndex ) const;
  413. bool getChainCollisionShapeHasAdjacentEnd( const U32 shapeIndex ) const;
  414. Vector2 getChainCollisionShapeAdjacentStart( const U32 shapeIndex ) const;
  415. Vector2 getChainCollisionShapeAdjacentEnd( const U32 shapeIndex ) const;
  416. /// Edge collision shape creation.
  417. S32 createEdgeCollisionShape( const b2Vec2& localPositionStart, const b2Vec2& localPositionEnd );
  418. S32 createEdgeCollisionShape( const b2Vec2& localPositionStart, const b2Vec2& localPositionEnd,
  419. const bool hasAdjacentLocalPositionStart, const bool hasAdjacentLocalPositionEnd,
  420. const b2Vec2& adjacentLocalPositionStart, const b2Vec2& adjacentLocalPositionEnd );
  421. /// Edge collision shape access.
  422. Vector2 getEdgeCollisionShapeLocalPositionStart( const U32 shapeIndex ) const;
  423. Vector2 getEdgeCollisionShapeLocalPositionEnd( const U32 shapeIndex ) const;
  424. bool getEdgeCollisionShapeHasAdjacentStart( const U32 shapeIndex ) const;
  425. bool getEdgeCollisionShapeHasAdjacentEnd( const U32 shapeIndex ) const;
  426. Vector2 getEdgeCollisionShapeAdjacentStart( const U32 shapeIndex ) const;
  427. Vector2 getEdgeCollisionShapeAdjacentEnd( const U32 shapeIndex ) const;
  428. /// Render visibility.
  429. inline void setVisible( const bool status ) { mVisible = status; }
  430. inline bool getVisible(void) const { return mVisible; }
  431. /// Render blending.
  432. inline void setBlendMode( const bool blendMode ) { mBlendMode = blendMode; }
  433. inline bool getBlendMode( void ) const { return mBlendMode; }
  434. inline void setSrcBlendFactor( const S32 blendFactor ) { mSrcBlendFactor = blendFactor; }
  435. inline S32 getSrcBlendFactor( void ) const { return mSrcBlendFactor; }
  436. inline void setDstBlendFactor( const S32 blendFactor ) { mDstBlendFactor = blendFactor; }
  437. inline S32 getDstBlendFactor( void ) const { return mDstBlendFactor; }
  438. inline void setBlendColor( const ColorF& blendColor ) { mBlendColor = blendColor; }
  439. inline const ColorF& getBlendColor( void ) const { return mBlendColor; }
  440. inline void setBlendAlpha( const F32 alpha ) { mBlendColor.alpha = alpha; }
  441. inline F32 getBlendAlpha( void ) const { return mBlendColor.alpha; }
  442. inline void setAlphaTest( const F32 alpha ) { mAlphaTest = alpha; }
  443. inline F32 getAlphaTest( void ) const { return mAlphaTest; }
  444. void setBlendOptions( void );
  445. static void resetBlendOptions( void );
  446. /// Render sorting.
  447. inline void setSortPoint( const Vector2& pt ) { mSortPoint = pt; }
  448. inline const Vector2& getSortPoint(void) const { return mSortPoint; }
  449. inline void setRenderGroup( const char* pRenderGroup ) { mRenderGroup = StringTable->insert(pRenderGroup); }
  450. inline StringTableEntry getRenderGroup( void ) const { return mRenderGroup; }
  451. /// Input events.
  452. inline void setUseInputEvents( bool mouseStatus ) { mUseInputEvents = mouseStatus; }
  453. inline bool getUseInputEvents( void ) const { return mUseInputEvents; }
  454. virtual void onInputEvent( StringTableEntry name, const GuiEvent& event, const Vector2& worldMousePoint );
  455. // Script callbacks.
  456. inline void setUpdateCallback( bool status ) { mUpdateCallback = status; }
  457. inline bool getUpdateCallback( void ) const { return mUpdateCallback; }
  458. inline void setCollisionCallback( const bool status ) { mCollisionCallback = status; }
  459. inline bool getCollisionCallback(void) const { return mCollisionCallback; }
  460. inline void setSleepingCallback( bool status ) { mSleepingCallback = status; }
  461. inline bool getSleepingCallback( void ) const { return mSleepingCallback; }
  462. /// Debug mode.
  463. inline void setDebugOn( const U32 debugMask ) { mDebugMask |= debugMask; }
  464. inline void setDebugOff( const U32 debugMask ) { mDebugMask &= ~debugMask; }
  465. inline U32 getDebugMask( void ) const { return mDebugMask; }
  466. /// Camera mounting.
  467. inline void addCameraMountReference( SceneWindow* pAttachedCamera ) { mpAttachedCamera = pAttachedCamera; }
  468. inline void removeCameraMountReference( void ) { mpAttachedCamera = NULL; }
  469. inline void dismountCamera( void ) { if ( mpAttachedCamera ) mpAttachedCamera->dismountMe( this ); }
  470. // GUI attachment.
  471. void attachGui( GuiControl* pGuiControl, SceneWindow* pSceneWindow, const bool sizeControl );
  472. void detachGui( void );
  473. inline void updateAttachedGui( void );
  474. // Picking.
  475. inline void setPickingAllowed( const bool pickingAllowed ) { mPickingAllowed = pickingAllowed; }
  476. inline bool getPickingAllowed(void) const { return mPickingAllowed; }
  477. /// Cloning.
  478. virtual void copyFrom( SceneObject* pSceneObject, const bool copyDynamicFields );
  479. virtual void copyTo( SimObject* object );
  480. S32 copyCollisionShapes( SceneObject* pSceneObject, const bool clearTargetShapes = true, const S32 shapeIndex = -1 );
  481. /// Safe deletion.
  482. inline void setSafeDelete( const bool status ) { mSafeDeleteReady = status; }
  483. inline bool getSafeDelete( void ) const { return mSafeDeleteReady; }
  484. inline bool isBeingDeleted( void ) const { return mBeingSafeDeleted; }
  485. virtual void safeDelete( void );
  486. /// Destroy notifications.
  487. void addDestroyNotification( SceneObject* pSceneObject );
  488. void removeDestroyNotification( SceneObject* pSceneObject );
  489. void processDestroyNotifications( void );
  490. /// Component notifications.
  491. void notifyComponentsAddToScene( void );
  492. void notifyComponentsRemoveFromScene( void );
  493. void notifyComponentsUpdate( void );
  494. /// Miscellaneous.
  495. inline const char* scriptThis(void) const { return Con::getIntArg(getId()); }
  496. inline bool getIsAlwaysInScope(void) const { return mAlwaysInScope; }
  497. inline void setWorldQueryKey( const U32 key ) { mWorldQueryKey = key; }
  498. inline U32 getWorldQueryKey( void ) const { return mWorldQueryKey; }
  499. static U32 getGlobalSceneObjectCount( void );
  500. inline U32 getSerialId( void ) const { return mSerialId; }
  501. // Read / Write fields.
  502. virtual bool writeField(StringTableEntry fieldname, const char* value);
  503. static b2BodyType getBodyTypeEnum(const char* label);
  504. static const char* getBodyTypeDescription(const b2BodyType bodyType);
  505. static b2Shape::Type getCollisionShapeTypeEnum(const char* label);
  506. static const char* getCollisionShapeTypeDescription(const b2Shape::Type collisionShapeType);
  507. static S32 getSrcBlendFactorEnum(const char* label);
  508. static S32 getDstBlendFactorEnum(const char* label);
  509. static const char* getSrcBlendFactorDescription(const GLenum factor);
  510. static const char* getDstBlendFactorDescription(const GLenum factor);
  511. /// Declare Console Object.
  512. DECLARE_CONOBJECT( SceneObject );
  513. protected:
  514. S32 copyCircleCollisionShapeTo( SceneObject* pSceneObject, const b2FixtureDef& fixtureDef ) const;
  515. S32 copyPolygonCollisionShapeTo( SceneObject* pSceneObject, const b2FixtureDef& fixtureDef ) const;
  516. S32 copyChainCollisionShapeTo( SceneObject* pSceneObject, const b2FixtureDef& fixtureDef ) const;
  517. S32 copyEdgeCollisionShapeTo( SceneObject* pSceneObject, const b2FixtureDef& fixtureDef ) const;
  518. protected:
  519. /// Lifetime.
  520. static bool setLifetime(void* obj, const char* data) { static_cast<SceneObject*>(obj)->setLifetime(dAtof(data)); return false; }
  521. static bool writeLifetime( void* obj, StringTableEntry pFieldName ) { return static_cast<SceneObject*>(obj)->getLifetime() > 0.0f ; }
  522. /// Scene layers.
  523. static bool setSceneLayer(void* obj, const char* data) { static_cast<SceneObject*>(obj)->setSceneLayer(dAtoi(data)); return false; }
  524. static bool writeSceneLayer( void* obj, StringTableEntry pFieldName ) { return static_cast<SceneObject*>(obj)->getSceneLayer() > 0 ; }
  525. static bool setSceneLayerDepth(void* obj, const char* data) { static_cast<SceneObject*>(obj)->setSceneLayerDepth(dAtof(data)); return false; }
  526. static bool writeSceneLayerDepth( void* obj, StringTableEntry pFieldName ) { return mNotZero(static_cast<SceneObject*>(obj)->getSceneLayerDepth()); }
  527. /// Scene groups.
  528. static bool setSceneGroup(void* obj, const char* data) { static_cast<SceneObject*>(obj)->setSceneGroup(dAtoi(data)); return false; }
  529. static bool writeSceneGroup( void* obj, StringTableEntry pFieldName ) { return static_cast<SceneObject*>(obj)->getSceneGroup() > 0 ; }
  530. /// Area.
  531. static bool setSize(void* obj, const char* data)
  532. {
  533. SceneObject* pSceneObject = static_cast<SceneObject*>(obj);
  534. if ( pSceneObject->getAutoSizing() )
  535. {
  536. Con::warnf( "Cannot set the size of a type '%s' as it automatically sizes itself.", pSceneObject->getClassName() );
  537. return false;
  538. }
  539. pSceneObject->setSize(Vector2(data));
  540. return false;
  541. }
  542. static bool writeSize( void* obj, StringTableEntry pFieldName ) { SceneObject* pSceneObject = static_cast<SceneObject*>(obj); return !pSceneObject->getAutoSizing() && pSceneObject->getSize().notEqual(Vector2::getOne()); }
  543. /// Position / Angle.
  544. static bool setPosition(void* obj, const char* data) { static_cast<SceneObject*>(obj)->setPosition(Vector2(data)); return false; }
  545. static const char* getPosition(void* obj, const char* data) { return static_cast<SceneObject*>(obj)->getPosition().scriptThis(); }
  546. static bool writePosition( void* obj, StringTableEntry pFieldName ) { return static_cast<SceneObject*>(obj)->getPosition().notZero(); }
  547. static bool setAngle(void* obj, const char* data) { static_cast<SceneObject*>(obj)->setAngle(mDegToRad(dAtof(data))); return false; }
  548. static const char* getAngle(void* obj, const char* data) { return Con::getFloatArg( mRadToDeg(static_cast<SceneObject*>(obj)->getAngle() ) ); }
  549. static bool writeAngle( void* obj, StringTableEntry pFieldName ) { return mNotZero(static_cast<SceneObject*>(obj)->getAngle()); }
  550. static bool setFixedAngle(void* obj, const char* data) { static_cast<SceneObject*>(obj)->setFixedAngle(dAtob(data)); return false; }
  551. static const char* getFixedAngle(void* obj, const char* data) { return Con::getBoolArg( static_cast<SceneObject*>(obj)->getFixedAngle() ); }
  552. static bool writeFixedAngle( void* obj, StringTableEntry pFieldName ) { return static_cast<SceneObject*>(obj)->getFixedAngle() == true; }
  553. /// Body.
  554. static bool setBodyType(void* obj, const char* data)
  555. {
  556. // Fetch body type.
  557. const b2BodyType type = getBodyTypeEnum( data );
  558. // Check for error.
  559. if ( type != b2_staticBody && type != b2_kinematicBody && type != b2_dynamicBody )
  560. return false;
  561. static_cast<SceneObject*>(obj)->setBodyType(type);
  562. return false;
  563. }
  564. static const char* getBodyType(void* obj, const char* data) { return getBodyTypeDescription( static_cast<SceneObject*>(obj)->getBodyType() ); }
  565. static bool writeBodyType( void* obj, StringTableEntry pFieldName ) { return static_cast<SceneObject*>(obj)->getBodyType() != b2_dynamicBody; }
  566. static bool setActive(void* obj, const char* data) { static_cast<SceneObject*>(obj)->setActive(dAtob(data)); return false; }
  567. static const char* getActive(void* obj, const char* data) { return Con::getBoolArg( static_cast<SceneObject*>(obj)->getActive() ); }
  568. static bool writeActive( void* obj, StringTableEntry pFieldName ) { return static_cast<SceneObject*>(obj)->getActive() == false; }
  569. static bool setAwake(void* obj, const char* data) { static_cast<SceneObject*>(obj)->setAwake(dAtob(data)); return false; }
  570. static const char* getAwake(void* obj, const char* data) { return Con::getBoolArg( static_cast<SceneObject*>(obj)->getAwake() ); }
  571. static bool writeAwake( void* obj, StringTableEntry pFieldName ) { return static_cast<SceneObject*>(obj)->getAwake() == false; }
  572. static bool setBullet(void* obj, const char* data) { static_cast<SceneObject*>(obj)->setBullet(dAtob(data)); return false; }
  573. static const char* getBullet(void* obj, const char* data) { return Con::getBoolArg( static_cast<SceneObject*>(obj)->getBullet() ); }
  574. static bool writeBullet( void* obj, StringTableEntry pFieldName ) { return static_cast<SceneObject*>(obj)->getBullet() == true; }
  575. static bool setSleepingAllowed(void* obj, const char* data) { static_cast<SceneObject*>(obj)->setSleepingAllowed(dAtob(data)); return false; }
  576. static const char* getSleepingAllowed(void* obj, const char* data) { return Con::getBoolArg( static_cast<SceneObject*>(obj)->getSleepingAllowed() ); }
  577. static bool writeSleepingAllowed( void* obj, StringTableEntry pFieldName ) { return static_cast<SceneObject*>(obj)->getSleepingAllowed() == false; }
  578. /// Collision control.
  579. static bool setDefaultDensity(void* obj, const char* data) { static_cast<SceneObject*>(obj)->setDefaultDensity(dAtof(data)); return false; }
  580. static bool writeDefaultDensity( void* obj, StringTableEntry pFieldName ) { return mNotEqual(static_cast<SceneObject*>(obj)->getDefaultDensity(), 1.0f); }
  581. static bool setDefaultFriction(void* obj, const char* data) { static_cast<SceneObject*>(obj)->setDefaultFriction(dAtof(data)); return false; }
  582. static bool writeDefaultFriction( void* obj, StringTableEntry pFieldName ) {return mNotEqual(static_cast<SceneObject*>(obj)->getDefaultFriction(), 0.2f); }
  583. static bool setDefaultRestitution(void* obj, const char* data) { static_cast<SceneObject*>(obj)->setDefaultRestitution(dAtof(data)); return false; }
  584. static bool writeDefaultRestitution( void* obj, StringTableEntry pFieldName ) { return mNotEqual(static_cast<SceneObject*>(obj)->getDefaultRestitution(), 0.0f); }
  585. static bool setCollisionGroups(void* obj, const char* data) { static_cast<SceneObject*>(obj)->setCollisionGroupMask(Utility::mConvertStringToMask(data)); return false; }
  586. static const char* getCollisionGroups(void* obj, const char* data) { return Utility::mConvertMaskToString( static_cast<SceneObject*>(obj)->getCollisionGroupMask() ); }
  587. static bool writeCollisionGroups( void* obj, StringTableEntry pFieldName ) { return static_cast<SceneObject*>(obj)->getCollisionGroupMask() != MASK_ALL; }
  588. static bool setCollisionLayers(void* obj, const char* data) { static_cast<SceneObject*>(obj)->setCollisionLayerMask(Utility::mConvertStringToMask(data)); return false; }
  589. static const char* getCollisionLayers(void* obj, const char* data) { return Utility::mConvertMaskToString( static_cast<SceneObject*>(obj)->getCollisionLayerMask() ); }
  590. static bool writeCollisionLayers( void* obj, StringTableEntry pFieldName ) { return static_cast<SceneObject*>(obj)->getCollisionLayerMask() != MASK_ALL; }
  591. static bool writeCollisionSuppress( void* obj, StringTableEntry pFieldName ) { return static_cast<SceneObject*>(obj)->getCollisionSuppress() == true; }
  592. static bool writeCollisionOneWay( void* obj, StringTableEntry pFieldName ) { return static_cast<SceneObject*>(obj)->getCollisionOneWay() == true; }
  593. static bool setGatherContacts(void* obj, const char* data) { static_cast<SceneObject*>(obj)->setGatherContacts(dAtoi(data)); return false; }
  594. static bool writeGatherContacts( void* obj, StringTableEntry pFieldName ) { return static_cast<SceneObject*>(obj)->getGatherContacts() == true; }
  595. /// Velocities.
  596. static bool setLinearVelocity(void* obj, const char* data) { static_cast<SceneObject*>(obj)->setLinearVelocity(Vector2(data)); return false; }
  597. static const char* getLinearVelocity(void* obj, const char* data) { return static_cast<SceneObject*>(obj)->getLinearVelocity().scriptThis(); }
  598. static bool writeLinearVelocity( void* obj, StringTableEntry pFieldName ) { return static_cast<SceneObject*>(obj)->getLinearVelocity().notZero(); }
  599. static bool setAngularVelocity(void* obj, const char* data) { static_cast<SceneObject*>(obj)->setAngularVelocity(mDegToRad(dAtof(data))); return false; }
  600. static const char* getAngularVelocity(void* obj, const char* data) { return Con::getFloatArg( mRadToDeg(static_cast<SceneObject*>(obj)->getAngularVelocity() ) ); }
  601. static bool writeAngularVelocity( void* obj, StringTableEntry pFieldName ) { return mNotZero(static_cast<SceneObject*>(obj)->getAngularVelocity()); }
  602. static bool setLinearDamping(void* obj, const char* data) { static_cast<SceneObject*>(obj)->setLinearDamping(dAtof(data)); return false; }
  603. static const char* getLinearDamping(void* obj, const char* data) { return Con::getFloatArg( static_cast<SceneObject*>(obj)->getLinearDamping() ); }
  604. static bool writeLinearDamping( void* obj, StringTableEntry pFieldName ) { return mNotZero(static_cast<SceneObject*>(obj)->getLinearDamping()); }
  605. static bool setAngularDamping(void* obj, const char* data) { static_cast<SceneObject*>(obj)->setAngularDamping(dAtof(data)); return false; }
  606. static const char* getAngularDamping(void* obj, const char* data) { return Con::getFloatArg( static_cast<SceneObject*>(obj)->getAngularDamping() ); }
  607. static bool writeAngularDamping( void* obj, StringTableEntry pFieldName ) { return mNotZero(static_cast<SceneObject*>(obj)->getAngularDamping()); }
  608. /// Gravity scaling.
  609. static bool setGravityScale(void* obj, const char* data) { static_cast<SceneObject*>(obj)->setGravityScale(dAtof(data)); return false; }
  610. static const char* getGravityScale(void* obj, const char* data) { return Con::getFloatArg( static_cast<SceneObject*>(obj)->getGravityScale() ); }
  611. static bool writeGravityScale( void* obj, StringTableEntry pFieldName ) { return mNotEqual(static_cast<SceneObject*>(obj)->getGravityScale(), 1.0f); }
  612. /// Render visibility.
  613. static bool writeVisible( void* obj, StringTableEntry pFieldName ) { return static_cast<SceneObject*>(obj)->getVisible() == false; }
  614. /// Render blending.
  615. static bool writeBlendMode( void* obj, StringTableEntry pFieldName ) { return static_cast<SceneObject*>(obj)->getBlendMode() == false; }
  616. static bool writeSrcBlendFactor( void* obj, StringTableEntry pFieldName ) { return static_cast<SceneObject*>(obj)->getSrcBlendFactor() != GL_SRC_ALPHA; }
  617. static bool writeDstBlendFactor( void* obj, StringTableEntry pFieldName ) { return static_cast<SceneObject*>(obj)->getDstBlendFactor() != GL_ONE_MINUS_SRC_ALPHA; }
  618. static bool writeBlendColor( void* obj, StringTableEntry pFieldName ) { return static_cast<SceneObject*>(obj)->getBlendColor() != ColorF(1.0f, 1.0f, 1.0f, 1.0f); }
  619. static bool writeAlphaTest( void* obj, StringTableEntry pFieldName ) { return static_cast<SceneObject*>(obj)->getAlphaTest() >= 0.0f; }
  620. /// Render sorting.
  621. static bool writeSortPoint( void* obj, StringTableEntry pFieldName ) { return static_cast<SceneObject*>(obj)->getSortPoint().notZero(); }
  622. static bool writeRenderGroup( void* obj, StringTableEntry pFieldName ) { return static_cast<SceneObject*>(obj)->getRenderGroup() != StringTable->EmptyString; }
  623. /// Input events.
  624. static bool writeUseInputEvents( void* obj, StringTableEntry pFieldName ) { return static_cast<SceneObject*>(obj)->getUseInputEvents() == true; }
  625. /// Picking.
  626. static bool writePickingAllowed( void* obj, StringTableEntry pFieldName ) { return static_cast<SceneObject*>(obj)->getPickingAllowed() == false; }
  627. /// Script callbacks.
  628. static bool writeUpdateCallback( void* obj, StringTableEntry pFieldName ) { return static_cast<SceneObject*>(obj)->getUpdateCallback() == true; }
  629. static bool writeCollisionCallback( void* obj, StringTableEntry pFieldName ) { return static_cast<SceneObject*>(obj)->getCollisionCallback() == true; }
  630. static bool writeSleepingCallback( void* obj, StringTableEntry pFieldName ) { return static_cast<SceneObject*>(obj)->getSleepingCallback() == true; }
  631. /// Scene.
  632. static bool setScene(void* obj, const char* data)
  633. {
  634. Scene* pScene = dynamic_cast<Scene*>(Sim::findObject(data));
  635. SceneObject* object = static_cast<SceneObject*>(obj);
  636. if (pScene)
  637. {
  638. if (object->getScene()) object->getScene()->removeFromScene(object);
  639. // is the scene object registered?
  640. if ( object->isProperlyAdded() )
  641. {
  642. // Yes, so we can add to the scene now.
  643. pScene->addToScene(object);
  644. }
  645. else
  646. {
  647. // No, so just set the target scene directly and it will be added to that scene when registered.
  648. object->mpTargetScene = pScene;
  649. }
  650. }
  651. return false;
  652. }
  653. static bool writeScene( void* obj, StringTableEntry pFieldName ) { return false; }
  654. };
  655. #endif // _SCENE_OBJECT_H_