guiObjectView.h 7.6 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. class LightInfo;
  31. /// A control that displays a TSShape in its view.
  32. class GuiObjectView : public GuiTSCtrl
  33. {
  34. public:
  35. typedef GuiTSCtrl Parent;
  36. DECLARE_CALLBACK( void, onMouseEnter, ());
  37. DECLARE_CALLBACK( void, onMouseLeave, ());
  38. protected:
  39. /// @name Mouse Control
  40. /// @{
  41. enum MouseState
  42. {
  43. None,
  44. Rotating,
  45. Zooming
  46. };
  47. /// Current mouse operation.
  48. MouseState mMouseState;
  49. /// Last mouse position during tracked mouse operations.
  50. Point2I mLastMousePoint;
  51. /// @}
  52. /// @name Model
  53. /// @{
  54. /// Name of the model loaded for display.
  55. String mModelName;
  56. /// Model being displayed in the view.
  57. TSShapeInstance* mModel;
  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. ///
  70. F32 mOrbitDist;
  71. /// Multiplier for camera mouse operations (rotation and zooming).
  72. F32 mCameraSpeed;
  73. /// @}
  74. /// @name Mounting
  75. /// @{
  76. /// Name of model to mount to the primary model.
  77. String mMountedModelName;
  78. ///
  79. String mMountSkinName;
  80. /// Index of the node to mount the secondary model to. -1 (disabled) by default.
  81. S32 mMountNode;
  82. /// Name of node to mount the secondary model to. Unset by default.
  83. String mMountNodeName;
  84. /// Model mounted as an image to the primary model.
  85. TSShapeInstance* mMountedModel;
  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. ColorF mLightColor;
  106. ///
  107. ColorF mLightAmbient;
  108. ///
  109. Point3F mLightDirection;
  110. /// @}
  111. ///
  112. void _initAnimation();
  113. ///
  114. void _initMount();
  115. ///
  116. void onStaticModified( StringTableEntry slotName, const char* newValue );
  117. public:
  118. GuiObjectView();
  119. ~GuiObjectView();
  120. /// @name Model
  121. /// @{
  122. ///
  123. const String& getModelName() const { return mModelName; }
  124. /// Return the instance of the model being rendered in the view.
  125. TSShapeInstance* getModel() const { return mModel; }
  126. /// Return the name of the skin used on the primary model.
  127. const String& getSkin() const { return mSkinName; }
  128. /// Set the skin to use on the primary model.
  129. void setSkin( const String& name );
  130. /// Set the model to show in this view.
  131. void setObjectModel( const String& modelName );
  132. /// @}
  133. /// @name Animation
  134. /// @{
  135. /// Set the animation sequence to play on the model.
  136. /// @param seqIndex Index of sequence to play.
  137. void setObjectAnimation( S32 seqIndex );
  138. /// Set the animation sequence to play on the model.
  139. /// @param seqIndex Name of sequence to play.
  140. void setObjectAnimation( const String& sequenceName );
  141. /// @}
  142. /// @name Mounting
  143. /// @{
  144. /// Return the model mounted to the current primary model; NULL if none.
  145. TSShapeInstance* getMountedModel() const { return mMountedModel; }
  146. ///
  147. const String& getMountedModelName() const { return mMountedModelName; }
  148. /// Return the name of the skin used on the mounted model.
  149. const String& getMountSkin() const { return mMountSkinName; }
  150. /// Set the skin to use on the mounted model.
  151. void setMountSkin( const String& name );
  152. ///
  153. void setMountNode( S32 index );
  154. ///
  155. void setMountNode( const String& nodeName );
  156. ///
  157. void setMountedObject( const String& modelName );
  158. /// @}
  159. /// @name Camera
  160. /// @{
  161. /// Return the current camera speed multiplier.
  162. F32 getCameraSpeed() const { return mCameraSpeed; }
  163. /// Set the multiplier to apply to camera rotation and zooming.
  164. void setCameraSpeed( F32 factor );
  165. ///
  166. F32 getOrbitDistance() const { return mOrbitDist; }
  167. /// Sets the distance at which the camera orbits the object. Clamped to the
  168. /// acceptable range defined in the class by min and max orbit distances.
  169. ///
  170. /// @param distance The distance to set the orbit to (will be clamped).
  171. void setOrbitDistance( F32 distance );
  172. /// @}
  173. /// @name Lighting
  174. /// @{
  175. ///
  176. void setLightColor( const ColorF& color );
  177. ///
  178. void setLightAmbient( const ColorF& color );
  179. ///
  180. void setLightDirection( const Point3F& direction );
  181. /// @}
  182. // GuiTsCtrl.
  183. bool onWake();
  184. void onMouseEnter( const GuiEvent& event );
  185. void onMouseLeave( const GuiEvent& event );
  186. void onMouseDown( const GuiEvent& event );
  187. void onMouseUp( const GuiEvent& event );
  188. void onMouseDragged( const GuiEvent& event );
  189. void onRightMouseDown( const GuiEvent& event );
  190. void onRightMouseUp( const GuiEvent& event );
  191. void onRightMouseDragged( const GuiEvent& event );
  192. bool processCameraQuery( CameraQuery* query );
  193. void renderWorld( const RectI& updateRect );
  194. static void initPersistFields();
  195. DECLARE_CONOBJECT( GuiObjectView );
  196. DECLARE_DESCRIPTION( "A control that shows a TSShape model." );
  197. };
  198. #endif // !_GUIOBJECTVIEW_H_