Torque3D Documentation / _generateds / guiObjectView.h

guiObjectView.h

Engine/source/T3D/guiObjectView.h

More...

Classes:

class

A control that displays a TSShape in its view.

Detailed Description

  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2012 GarageGames, LLC
  4//
  5// Permission is hereby granted, free of charge, to any person obtaining a copy
  6// of this software and associated documentation files (the "Software"), to
  7// deal in the Software without restriction, including without limitation the
  8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9// sell copies of the Software, and to permit persons to whom the Software is
 10// furnished to do so, subject to the following conditions:
 11//
 12// The above copyright notice and this permission notice shall be included in
 13// all copies or substantial portions of the Software.
 14//
 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 21// IN THE SOFTWARE.
 22//-----------------------------------------------------------------------------
 23
 24#ifndef _GUIOBJECTVIEW_H_
 25#define _GUIOBJECTVIEW_H_
 26
 27#ifndef _GUITSCONTROL_H_
 28   #include "gui/3d/guiTSControl.h"
 29#endif
 30#ifndef _TSSHAPEINSTANCE_H_
 31   #include "ts/tsShapeInstance.h"
 32#endif
 33
 34
 35class LightInfo;
 36
 37
 38/// A control that displays a TSShape in its view.
 39class GuiObjectView : public GuiTSCtrl
 40{
 41   public:
 42   
 43      typedef GuiTSCtrl Parent;
 44
 45     DECLARE_CALLBACK( void, onMouseEnter, ());
 46     DECLARE_CALLBACK( void, onMouseLeave, ());
 47
 48   protected:
 49   
 50      /// @name Mouse Control
 51      /// @{
 52   
 53      enum MouseState
 54      {
 55         None,
 56         Rotating,
 57         Zooming
 58      };
 59
 60      /// Current mouse operation.
 61      MouseState  mMouseState;
 62      
 63      /// Last mouse position during tracked mouse operations.
 64      Point2I mLastMousePoint;
 65
 66      /// @}
 67      
 68      /// @name Model
 69      /// @{
 70      
 71      /// Name of the model loaded for display.
 72      String mModelName;
 73
 74      /// Model being displayed in the view.
 75      TSShapeInstance* mModel;
 76
 77      /// Name of skin to use on model.
 78      String mSkinName;
 79      
 80      /// @}
 81      
 82      /// @name Camera State
 83      /// @{
 84
 85      Point3F mCameraPos;
 86      MatrixF mCameraMatrix;
 87      EulerF mCameraRot;
 88      Point3F mOrbitPos;
 89      
 90      F32 mMaxOrbitDist;
 91      F32 mMinOrbitDist;
 92      EulerF mCameraRotation;
 93      
 94      ///
 95      F32 mOrbitDist;
 96      
 97      /// Multiplier for camera mouse operations (rotation and zooming).
 98      F32 mCameraSpeed;
 99
100      /// @}
101      
102      /// @name Mounting
103      /// @{
104      
105      /// Name of model to mount to the primary model.
106      String mMountedModelName;
107      
108      ///
109      String mMountSkinName;
110
111      /// Index of the node to mount the secondary model to.  -1 (disabled) by default.
112      S32 mMountNode;
113      
114      /// Name of node to mount the secondary model to.  Unset by default.
115      String mMountNodeName;
116
117      /// Model mounted as an image to the primary model.
118      TSShapeInstance* mMountedModel;
119            
120      ///
121      MatrixF mMountTransform;
122      
123      /// @}
124      
125      /// @name Animation
126      /// @{
127
128      /// Index of the animation sequence to play on the model.  -1 (disabled) by default.
129      S32 mAnimationSeq;
130      
131      /// Name of the animation sequence to play on the model.  Unset by default.
132      String mAnimationSeqName;
133
134      /// Animation thread on the model.
135      TSThread* mRunThread;
136      
137      /// Last time we rendered the model.  Used for animation.
138      S32 mLastRenderTime;
139      
140      /// @}
141      
142      /// @name Lighting
143      /// @{
144      
145      /// Light object used as sun during rendering.
146      LightInfo* mLight;
147      
148      ///
149      LinearColorF mLightColor;
150      
151      ///
152      LinearColorF mLightAmbient;
153      
154      ///
155      Point3F mLightDirection;
156      
157      /// @}
158
159      ///
160      void _initAnimation();
161      
162      ///
163      void _initMount();
164      
165      ///
166      void onStaticModified( StringTableEntry slotName, const char* newValue );
167
168   public:
169   
170      GuiObjectView();
171      ~GuiObjectView();
172      
173      /// @name Model
174      /// @{
175      
176      ///
177      const String& getModelName() const { return mModelName; }
178
179      /// Return the instance of the model being rendered in the view.
180      TSShapeInstance* getModel() const { return mModel; }
181      
182      /// Return the name of the skin used on the primary model.
183      const String& getSkin() const { return mSkinName; }
184            
185      /// Set the skin to use on the primary model.
186      void setSkin( const String& name );
187
188      /// Set the model to show in this view.
189      void setObjectModel( const String& modelName );
190      
191      /// @}
192      
193      /// @name Animation
194      /// @{
195      
196      /// Set the animation sequence to play on the model.
197      /// @param seqIndex Index of sequence to play.
198      void setObjectAnimation( S32 seqIndex );
199            
200      /// Set the animation sequence to play on the model.
201      /// @param seqIndex Name of sequence to play.
202      void setObjectAnimation( const String& sequenceName );
203      
204      /// @}
205      
206      /// @name Mounting
207      /// @{
208      
209      /// Return the model mounted to the current primary model; NULL if none.
210      TSShapeInstance* getMountedModel() const { return mMountedModel; }
211      
212      ///
213      const String& getMountedModelName() const { return mMountedModelName; }
214      
215      /// Return the name of the skin used on the mounted model.
216      const String& getMountSkin() const { return mMountSkinName; }
217      
218      /// Set the skin to use on the mounted model.
219      void setMountSkin( const String& name );
220
221      ///
222      void setMountNode( S32 index );
223      
224      ///
225      void setMountNode( const String& nodeName );
226      
227      ///
228      void setMountedObject( const String& modelName );
229            
230      /// @}
231      
232      /// @name Camera
233      /// @{
234      
235      /// Return the current camera speed multiplier.
236      F32 getCameraSpeed() const { return mCameraSpeed; }
237      
238      /// Set the multiplier to apply to camera rotation and zooming.
239      void setCameraSpeed( F32 factor );
240      
241      ///
242      F32 getOrbitDistance() const { return mOrbitDist; }
243      
244      /// Sets the distance at which the camera orbits the object. Clamped to the
245      /// acceptable range defined in the class by min and max orbit distances.
246      ///
247      /// @param distance The distance to set the orbit to (will be clamped).
248      void setOrbitDistance( F32 distance );
249      
250      /// Sets the angle of the camera on it's orbit in relation to the object.
251      void setCameraRotation( const EulerF& rotation );
252      
253      /// @}
254      
255      /// @name Lighting
256      /// @{
257      
258      ///
259      void setLightColor( const LinearColorF& color );
260      
261      ///
262      void setLightAmbient( const LinearColorF& color );
263      
264      ///
265      void setLightDirection( const Point3F& direction );
266      
267      /// @}
268      
269      // GuiTsCtrl.
270      bool onWake();
271
272      void onMouseEnter( const GuiEvent& event );
273      void onMouseLeave( const GuiEvent& event );
274      void onMouseDown( const GuiEvent& event );
275      void onMouseUp( const GuiEvent& event );
276      void onMouseDragged( const GuiEvent& event );
277      void onRightMouseDown( const GuiEvent& event );
278      void onRightMouseUp( const GuiEvent& event );
279      void onRightMouseDragged( const GuiEvent& event );
280
281      bool processCameraQuery( CameraQuery* query );
282      void renderWorld( const RectI& updateRect );
283      
284      static void initPersistFields();
285
286      DECLARE_CONOBJECT( GuiObjectView );
287      DECLARE_DESCRIPTION( "A control that shows a TSShape model." );   
288};
289
290#endif // !_GUIOBJECTVIEW_H_
291