guiObjectView.h 7.8 KB

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