guiObjectView.h 7.8 KB

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