Torque3D Documentation / _generateds / VCameraGroup.cpp

VCameraGroup.cpp

Engine/source/Verve/Extension/Camera/VCameraGroup.cpp

More...

Detailed Description

Public Functions

IMPLEMENT_CONOBJECT(VCameraGroup )

  1
  2//-----------------------------------------------------------------------------
  3// Verve
  4// Copyright (C) 2014 - Violent Tulip
  5//
  6// Permission is hereby granted, free of charge, to any person obtaining a copy
  7// of this software and associated documentation files (the "Software"), to
  8// deal in the Software without restriction, including without limitation the
  9// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 10// sell copies of the Software, and to permit persons to whom the Software is
 11// furnished to do so, subject to the following conditions:
 12//
 13// The above copyright notice and this permission notice shall be included in
 14// all copies or substantial portions of the Software.
 15//
 16// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 17// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 18// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 19// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 20// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 21// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 22// IN THE SOFTWARE.
 23//-----------------------------------------------------------------------------
 24#include "Verve/Extension/Camera/VCameraGroup.h"
 25#include "Verve/Extension/Camera/VCameraTrack.h"
 26
 27//-----------------------------------------------------------------------------
 28IMPLEMENT_CONOBJECT( VCameraGroup );
 29//-----------------------------------------------------------------------------
 30
 31VCameraGroup *VCameraGroup::mActiveGroup = NULL;
 32VCameraGroup::CameraChangeSignal VCameraGroup::mCameraChangeSignal;
 33
 34//-----------------------------------------------------------------------------
 35
 36VCameraGroup::VCameraGroup( void )
 37{
 38    setLabel( "CameraGroup" );
 39};
 40
 41//-----------------------------------------------------------------------------
 42//
 43// Tree Methods.
 44//
 45//-----------------------------------------------------------------------------
 46
 47//-----------------------------------------------------------------------------
 48// 
 49// VCameraGroup::onAttach();
 50// 
 51// This callback subscribes this object to the controller's event signal.
 52// 
 53//-----------------------------------------------------------------------------
 54void VCameraGroup::onAttach( void )
 55{
 56    Parent::onAttach();
 57
 58    // Valid Controller?
 59    if ( getController() )
 60    {
 61        // Subscribe to Events.
 62        getController()->getControllerEventSignal().notify( this, &VCameraGroup::onControllerEvent );
 63    }
 64}
 65
 66//-----------------------------------------------------------------------------
 67// 
 68// VCameraGroup::onAttach();
 69// 
 70// This callback removes this object from the controller's event signal
 71// notification list.
 72// 
 73//-----------------------------------------------------------------------------
 74void VCameraGroup::onDetach( void )
 75{
 76    // Valid Controller?
 77    if ( getController() )
 78    {
 79        // Remove Event Notification.
 80        getController()->getControllerEventSignal().remove( this, &VCameraGroup::onControllerEvent );
 81    }
 82
 83    Parent::onDetach();
 84}
 85
 86//-----------------------------------------------------------------------------
 87//
 88// Controller Methods.
 89//
 90//-----------------------------------------------------------------------------
 91
 92//-----------------------------------------------------------------------------
 93// 
 94// VCameraGroup::onControllerEvent( pEvent );
 95// 
 96// When the controller's state changes, this method is called.
 97// 
 98// For a full list of possible events, see the 'eControllerEventType'
 99// declaration in VController.h.
100// 
101//-----------------------------------------------------------------------------
102bool VCameraGroup::onControllerEvent( VController::eControllerEventType pEvent )
103{
104    if ( !getController() )
105    {
106        AssertFatal( false, "VCameraGroup::onControllerEvent() - Invalid Controller." );
107        return false;
108    }
109
110    // Enabled?
111    if ( !isEnabled() )
112    {
113        // Continue Processing Events.
114        return true;
115    }
116
117    switch( pEvent )
118    {
119#ifdef VT_EDITOR
120        case VController::k_EventPause :
121#endif
122        case VController::k_EventStop :
123            {
124
125                // Clear the Camera.
126                clearActiveGroup();
127
128            } break;
129    }
130
131    return true;
132}
133
134//-----------------------------------------------------------------------------
135//
136// Camera Methods.
137//
138//-----------------------------------------------------------------------------
139
140//-----------------------------------------------------------------------------
141// 
142// VCameraGroup::setActive();
143// 
144// Set this Group to Active.
145// 
146//-----------------------------------------------------------------------------
147void VCameraGroup::setActive( void )
148{
149    // Set Active.
150    setActiveGroup( this );
151}
152
153//-----------------------------------------------------------------------------
154// 
155// VCameraGroup::clearActiveGroup();
156// 
157// Clear the Active Camera.
158// 
159//-----------------------------------------------------------------------------
160void VCameraGroup::clearActiveGroup( void )
161{
162    if ( mActiveGroup )
163    {
164        // Deactivate Signal.
165        mActiveGroup->getCameraEventSignal().trigger( k_EventDeactivate );
166    }
167
168    // Store.
169    mActiveGroup = NULL;
170
171    // Clear Camera Object.
172    VTorque::setCamera( NULL );
173
174    // Change Signal.
175    getCameraChangeSignal().trigger( NULL );
176}
177
178//-----------------------------------------------------------------------------
179// 
180// VCameraGroup::setActiveGroup( pCameraGroup );
181// 
182// Change the current camera group. The actual camera object is the object that
183// the group references.
184// 
185// A NULL value of pCameraGroup will clear the active camera, which generally
186// reverts to the connection's control object. The camera is also cleared when
187// the Controller stops playing.
188// 
189//-----------------------------------------------------------------------------
190void VCameraGroup::setActiveGroup( VCameraGroup *pCameraGroup )
191{
192    // Change Camera?
193    if ( pCameraGroup == mActiveGroup ||
194         pCameraGroup && !pCameraGroup->isEnabled() )
195    {
196        // Invalid Target.
197        return;
198    }
199
200    if ( mActiveGroup )
201    {
202        // Deactivate Signal.
203        mActiveGroup->getCameraEventSignal().trigger( k_EventDeactivate );
204    }
205
206    // Store.
207    mActiveGroup = pCameraGroup;
208
209    if ( mActiveGroup )
210    {
211        // Set Camera Object.
212        VTorque::setCamera( mActiveGroup->getSceneObject() );
213
214        // Activate Signal.
215        mActiveGroup->getCameraEventSignal().trigger( k_EventActivate );
216    }
217    else
218    {
219        // Clear Camera Object.
220        VTorque::setCamera( NULL );
221    }
222
223    // Change Signal.
224    getCameraChangeSignal().trigger( mActiveGroup );
225}
226