guiObjectView.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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. #ifndef _GUIOBJECTVIEW_H_
  23. #define _GUIOBJECTVIEW_H_
  24. #ifndef _GUITSCONTROL_H_
  25. #include "gui/3d/guiTSControl.h"
  26. #endif
  27. #ifndef _TSSHAPEINSTANCE_H_
  28. #include "ts/tsShapeInstance.h"
  29. #endif
  30. #include "T3D/assets/ShapeAsset.h"
  31. class LightInfo;
  32. /// A control that displays a TSShape in its view.
  33. class GuiObjectView : public GuiTSCtrl, protected AssetPtrCallback
  34. {
  35. public:
  36. typedef GuiTSCtrl Parent;
  37. DECLARE_CALLBACK( void, onMouseEnter, ());
  38. DECLARE_CALLBACK( void, onMouseLeave, ());
  39. protected:
  40. /// @name Mouse Control
  41. /// @{
  42. enum MouseState
  43. {
  44. None,
  45. Rotating,
  46. Zooming
  47. };
  48. /// Current mouse operation.
  49. MouseState mMouseState;
  50. /// Last mouse position during tracked mouse operations.
  51. Point2I mLastMousePoint;
  52. /// @}
  53. /// @name Model
  54. /// @{
  55. ///Model loaded for display.
  56. DECLARE_SHAPEASSET_REFACTOR(GuiObjectView, Model)
  57. TSShapeInstance* mModelInstance;
  58. /// Name of skin to use on model.
  59. String mSkinName;
  60. /// @}
  61. /// @name Camera State
  62. /// @{
  63. Point3F mCameraPos;
  64. MatrixF mCameraMatrix;
  65. EulerF mCameraRot;
  66. Point3F mOrbitPos;
  67. F32 mMaxOrbitDist;
  68. F32 mMinOrbitDist;
  69. EulerF mCameraRotation;
  70. ///
  71. F32 mOrbitDist;
  72. /// Multiplier for camera mouse operations (rotation and zooming).
  73. F32 mCameraSpeed;
  74. /// @}
  75. /// @name Mounting
  76. /// @{
  77. ///Model to mount to the primary model.
  78. DECLARE_SHAPEASSET_REFACTOR(GuiObjectView, MountedModel)
  79. TSShapeInstance* mMountedModelInstance;
  80. ///
  81. String mMountSkinName;
  82. /// Index of the node to mount the secondary model to. -1 (disabled) by default.
  83. S32 mMountNode;
  84. /// Name of node to mount the secondary model to. Unset by default.
  85. String mMountNodeName;
  86. ///
  87. MatrixF mMountTransform;
  88. /// @}
  89. /// @name Animation
  90. /// @{
  91. /// Index of the animation sequence to play on the model. -1 (disabled) by default.
  92. S32 mAnimationSeq;
  93. /// Name of the animation sequence to play on the model. Unset by default.
  94. String mAnimationSeqName;
  95. /// Animation thread on the model.
  96. TSThread* mRunThread;
  97. /// Last time we rendered the model. Used for animation.
  98. S32 mLastRenderTime;
  99. /// @}
  100. /// @name Lighting
  101. /// @{
  102. /// Light object used as sun during rendering.
  103. LightInfo* mLight;
  104. ///
  105. LinearColorF mLightColor;
  106. ///
  107. LinearColorF mLightAmbient;
  108. ///
  109. Point3F mLightDirection;
  110. /// @}
  111. ///
  112. void _initAnimation();
  113. ///
  114. void _initMount();
  115. ///
  116. void onStaticModified( StringTableEntry slotName, const char* newValue ) override;
  117. public:
  118. GuiObjectView();
  119. ~GuiObjectView();
  120. /// @name Model
  121. /// @{
  122. /// Return the name of the skin used on the primary model.
  123. const String& getSkin() const { return mSkinName; }
  124. /// Set the skin to use on the primary model.
  125. void setSkin( const String& name );
  126. /// Set the model to show in this view.
  127. bool setObjectModel( const String& modelName );
  128. /// @}
  129. /// @name Animation
  130. /// @{
  131. /// Set the animation sequence to play on the model.
  132. /// @param seqIndex Index of sequence to play.
  133. void setObjectAnimation( S32 seqIndex );
  134. /// Set the animation sequence to play on the model.
  135. /// @param seqIndex Name of sequence to play.
  136. void setObjectAnimation( const String& sequenceName );
  137. /// @}
  138. /// @name Mounting
  139. /// @{
  140. /// Return the name of the skin used on the mounted model.
  141. const String& getMountSkin() const { return mMountSkinName; }
  142. /// Set the skin to use on the mounted model.
  143. void setMountSkin( const String& name );
  144. ///
  145. void setMountNode( S32 index );
  146. ///
  147. void setMountNode( const String& nodeName );
  148. ///
  149. bool setMountedObject( const String& modelName );
  150. /// @}
  151. /// @name Camera
  152. /// @{
  153. /// Return the current camera speed multiplier.
  154. F32 getCameraSpeed() const { return mCameraSpeed; }
  155. /// Set the multiplier to apply to camera rotation and zooming.
  156. void setCameraSpeed( F32 factor );
  157. ///
  158. F32 getOrbitDistance() const { return mOrbitDist; }
  159. /// Sets the distance at which the camera orbits the object. Clamped to the
  160. /// acceptable range defined in the class by min and max orbit distances.
  161. ///
  162. /// @param distance The distance to set the orbit to (will be clamped).
  163. void setOrbitDistance( F32 distance );
  164. /// Sets the angle of the camera on it's orbit in relation to the object.
  165. void setCameraRotation( const EulerF& rotation );
  166. /// @}
  167. /// @name Lighting
  168. /// @{
  169. ///
  170. void setLightColor( const LinearColorF& color );
  171. ///
  172. void setLightAmbient( const LinearColorF& color );
  173. ///
  174. void setLightDirection( const Point3F& direction );
  175. /// @}
  176. // GuiTsCtrl.
  177. bool onWake() override;
  178. void onMouseEnter( const GuiEvent& event ) override;
  179. void onMouseLeave( const GuiEvent& event ) override;
  180. void onMouseDown( const GuiEvent& event ) override;
  181. void onMouseUp( const GuiEvent& event ) override;
  182. void onMouseDragged( const GuiEvent& event ) override;
  183. void onRightMouseDown( const GuiEvent& event ) override;
  184. void onRightMouseUp( const GuiEvent& event ) override;
  185. void onRightMouseDragged( const GuiEvent& event ) override;
  186. bool processCameraQuery( CameraQuery* query ) override;
  187. void renderWorld( const RectI& updateRect ) override;
  188. static void initPersistFields();
  189. DECLARE_CONOBJECT( GuiObjectView );
  190. DECLARE_DESCRIPTION( "A control that shows a TSShape model." );
  191. protected:
  192. void onAssetRefreshed(AssetPtrBase* pAssetPtrBase) override
  193. {
  194. if (getModel())
  195. setObjectModel(_getModelAssetId());
  196. if (getMountedModel())
  197. setMountedObject(_getMountedModelAssetId());
  198. }
  199. };
  200. #endif // !_GUIOBJECTVIEW_H_