Game Development Community

dev|Pro Game Development Curriculum

Controlling the camera angle in GuiObjectView

by Kyrah Abattoir · 04/07/2013 (9:32 pm) · 3 comments

This is a very simple mofification of the GuiObjectView class that will add methods and controls to set the camera rotation through the gui editor.
This is useful if you have non interactive GuiObjectView and want to set them to a specific view angle.

(My code will be enclosed in tags with the original code around it.)

In guiObjectView.h:
@ line 90
F32 mMaxOrbitDist;
      F32 mMinOrbitDist;
      
      // Kyrah :: added a way to set the camera GuiObjectView rotation >>>
      EulerF mCameraRotation;
      // Kyrah :: added a way to set the camera GuiObjectView rotation <<<

      ///
      F32 mOrbitDist;
      
      /// Multiplier for camera mouse operations (rotation and zooming).
@line 248
/// @param distance The distance to set the orbit to (will be clamped).
      void setOrbitDistance( F32 distance );

      // Kyrah :: added a way to set the camera GuiObjectView rotation >>>
      void setCameraRotation( const EulerF& rotation );
      // Kyrah :: added a way to set the camera GuiObjectView rotation <<<
      
      /// @}
      
      /// @name Lighting


In guiObjectView.cpp:
@ line 181
addField( "maxOrbitDiststance", TypeF32, Offset( mMaxOrbitDist, GuiObjectView ),
         "Minimum distance below which the camera will not zoom in further." );
      addField( "cameraSpeed", TypeF32, Offset( mCameraSpeed, GuiObjectView ),
         "Multiplier for mouse camera operations." );
      // Kyrah :: added a way to set the camera GuiObjectView rotation >>>
      addField( "cameraRotation", TypePoint3F, Offset( mCameraRotation, GuiObjectView ),
         "Set the camera rotation." );
      // Kyrah :: added a way to set the camera GuiObjectView rotation <<<

   endGroup( "Camera" );
   
   Parent::initPersistFields();
@ line 209
static StringTableEntry sMaxOrbitDistance = StringTable->insert( "maxOrbitDistance" );
   static StringTableEntry sAnimSequence = StringTable->insert( "animSequence" );

   // Kyrah :: added a way to set the camera GuiObjectView rotation >>>
   static StringTableEntry sCameraRotation = StringTable->insert( "cameraRotation" );
   // Kyrah :: added a way to set the camera GuiObjectView rotation <<<
   
   if( slotName == sShapeFile )
      setObjectModel( String( mModelName ) );
@ line 236
else if( slotName == sAnimSequence )
      setObjectAnimation( String( mAnimationSeqName ) );
   // Kyrah :: added a way to set the camera GuiObjectView rotation >>>
   else if( slotName == sCameraRotation )
      setCameraRotation( mCameraRotation );
   // Kyrah :: added a way to set the camera GuiObjectView rotation <<<
}

//------------------------------------------------------------------------------

// Kyrah :: added a way to set the camera GuiObjectView rotation >>>
void GuiObjectView::setCameraRotation( const EulerF& rotation )
{
    mCameraRot.set(rotation);
}
// Kyrah :: added a way to set the camera GuiObjectView rotation <<<

bool GuiObjectView::onWake()
{
   if( !Parent::onWake() )

This should add a handy new field "cameraRotation" (which take values in radiant i believe) in the camera subsection.

#1
04/08/2013 (12:39 pm)
Nice resource, thanks.
#2
04/09/2013 (8:06 am)
Useful resource.
#3
05/06/2013 (6:24 pm)
wow,thanks~~