guiObjectView.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  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
  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(GuiObjectView, Model, onModelChanged);
  57. static bool _setModelData(void* obj, const char* index, const char* data)\
  58. {
  59. bool ret = false;
  60. GuiObjectView* object = static_cast<GuiObjectView*>(obj);
  61. ret = object->setObjectModel(StringTable->insert(data));
  62. return ret;
  63. }
  64. void onModelChanged();
  65. TSShapeInstance* mModelInstance;
  66. /// Name of skin to use on model.
  67. String mSkinName;
  68. /// @}
  69. /// @name Camera State
  70. /// @{
  71. Point3F mCameraPos;
  72. MatrixF mCameraMatrix;
  73. EulerF mCameraRot;
  74. Point3F mOrbitPos;
  75. F32 mMaxOrbitDist;
  76. F32 mMinOrbitDist;
  77. EulerF mCameraRotation;
  78. ///
  79. F32 mOrbitDist;
  80. /// Multiplier for camera mouse operations (rotation and zooming).
  81. F32 mCameraSpeed;
  82. /// @}
  83. /// @name Mounting
  84. /// @{
  85. ///Model to mount to the primary model.
  86. DECLARE_SHAPEASSET(GuiObjectView, MountedModel, onMountedModelChanged);
  87. static bool _setMountedModelData(void* obj, const char* index, const char* data)\
  88. {
  89. bool ret = false;
  90. GuiObjectView* object = static_cast<GuiObjectView*>(obj);
  91. ret = object->setMountedObject(StringTable->insert(data));
  92. return ret;
  93. }
  94. void onMountedModelChanged();
  95. TSShapeInstance* mMountedModelInstance;
  96. ///
  97. String mMountSkinName;
  98. /// Index of the node to mount the secondary model to. -1 (disabled) by default.
  99. S32 mMountNode;
  100. /// Name of node to mount the secondary model to. Unset by default.
  101. String mMountNodeName;
  102. ///
  103. MatrixF mMountTransform;
  104. /// @}
  105. /// @name Animation
  106. /// @{
  107. /// Index of the animation sequence to play on the model. -1 (disabled) by default.
  108. S32 mAnimationSeq;
  109. /// Name of the animation sequence to play on the model. Unset by default.
  110. String mAnimationSeqName;
  111. /// Animation thread on the model.
  112. TSThread* mRunThread;
  113. /// Last time we rendered the model. Used for animation.
  114. S32 mLastRenderTime;
  115. /// @}
  116. /// @name Lighting
  117. /// @{
  118. /// Light object used as sun during rendering.
  119. LightInfo* mLight;
  120. ///
  121. LinearColorF mLightColor;
  122. ///
  123. LinearColorF mLightAmbient;
  124. ///
  125. Point3F mLightDirection;
  126. /// @}
  127. ///
  128. void _initAnimation();
  129. ///
  130. void _initMount();
  131. ///
  132. void onStaticModified( StringTableEntry slotName, const char* newValue ) override;
  133. public:
  134. GuiObjectView();
  135. ~GuiObjectView();
  136. /// @name Model
  137. /// @{
  138. /// Return the name of the skin used on the primary model.
  139. const String& getSkin() const { return mSkinName; }
  140. /// Set the skin to use on the primary model.
  141. void setSkin( const String& name );
  142. /// Set the model to show in this view.
  143. bool setObjectModel( const String& modelName );
  144. /// @}
  145. /// @name Animation
  146. /// @{
  147. /// Set the animation sequence to play on the model.
  148. /// @param seqIndex Index of sequence to play.
  149. void setObjectAnimation( S32 seqIndex );
  150. /// Set the animation sequence to play on the model.
  151. /// @param seqIndex Name of sequence to play.
  152. void setObjectAnimation( const String& sequenceName );
  153. /// @}
  154. /// @name Mounting
  155. /// @{
  156. /// Return the name of the skin used on the mounted model.
  157. const String& getMountSkin() const { return mMountSkinName; }
  158. /// Set the skin to use on the mounted model.
  159. void setMountSkin( const String& name );
  160. ///
  161. void setMountNode( S32 index );
  162. ///
  163. void setMountNode( const String& nodeName );
  164. ///
  165. bool setMountedObject( const String& modelName );
  166. /// @}
  167. /// @name Camera
  168. /// @{
  169. /// Return the current camera speed multiplier.
  170. F32 getCameraSpeed() const { return mCameraSpeed; }
  171. /// Set the multiplier to apply to camera rotation and zooming.
  172. void setCameraSpeed( F32 factor );
  173. ///
  174. F32 getOrbitDistance() const { return mOrbitDist; }
  175. /// Sets the distance at which the camera orbits the object. Clamped to the
  176. /// acceptable range defined in the class by min and max orbit distances.
  177. ///
  178. /// @param distance The distance to set the orbit to (will be clamped).
  179. void setOrbitDistance( F32 distance );
  180. /// Sets the angle of the camera on it's orbit in relation to the object.
  181. void setCameraRotation( const EulerF& rotation );
  182. /// @}
  183. /// @name Lighting
  184. /// @{
  185. ///
  186. void setLightColor( const LinearColorF& color );
  187. ///
  188. void setLightAmbient( const LinearColorF& color );
  189. ///
  190. void setLightDirection( const Point3F& direction );
  191. /// @}
  192. // GuiTsCtrl.
  193. bool onWake() override;
  194. void onMouseEnter( const GuiEvent& event ) override;
  195. void onMouseLeave( const GuiEvent& event ) override;
  196. void onMouseDown( const GuiEvent& event ) override;
  197. void onMouseUp( const GuiEvent& event ) override;
  198. void onMouseDragged( const GuiEvent& event ) override;
  199. void onRightMouseDown( const GuiEvent& event ) override;
  200. void onRightMouseUp( const GuiEvent& event ) override;
  201. void onRightMouseDragged( const GuiEvent& event ) override;
  202. bool processCameraQuery( CameraQuery* query ) override;
  203. void renderWorld( const RectI& updateRect ) override;
  204. static void initPersistFields();
  205. DECLARE_CONOBJECT( GuiObjectView );
  206. DECLARE_DESCRIPTION( "A control that shows a TSShape model." );
  207. };
  208. #endif // !_GUIOBJECTVIEW_H_