Torque3D Documentation / _generateds / afxEA_CameraPuppet.cpp

afxEA_CameraPuppet.cpp

Engine/source/afx/ea/afxEA_CameraPuppet.cpp

More...

Classes:

Detailed Description

  1
  2
  3//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  4// Arcane-FX for MIT Licensed Open Source version of Torque 3D from GarageGames
  5// Copyright (C) 2015 Faust Logic, Inc.
  6//
  7// Permission is hereby granted, free of charge, to any person obtaining a copy
  8// of this software and associated documentation files (the "Software"), to
  9// deal in the Software without restriction, including without limitation the
 10// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 11// sell copies of the Software, and to permit persons to whom the Software is
 12// furnished to do so, subject to the following conditions:
 13//
 14// The above copyright notice and this permission notice shall be included in
 15// all copies or substantial portions of the Software.
 16//
 17// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 18// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 19// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 20// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 21// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 22// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 23// IN THE SOFTWARE.
 24//
 25//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
 26
 27#include <typeinfo>
 28#include "afx/arcaneFX.h"
 29
 30#include "T3D/gameBase/gameConnection.h"
 31
 32#include "afx/afxChoreographer.h"
 33#include "afx/afxEffectDefs.h"
 34#include "afx/afxEffectWrapper.h"
 35#include "afx/afxCamera.h"
 36#include "afx/ce/afxCameraPuppet.h"
 37
 38//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
 39// afxEA_CameraPuppet 
 40
 41class afxEA_CameraPuppet : public afxEffectWrapper
 42{
 43  typedef afxEffectWrapper Parent;
 44
 45  afxCameraPuppetData* puppet_data;
 46  afxConstraint*    cam_cons;
 47  bool              was_1st_person;
 48
 49  void              do_runtime_substitutions();
 50
 51public:
 52  /*C*/             afxEA_CameraPuppet();
 53
 54  virtual void      ea_set_datablock(SimDataBlock*);
 55  virtual bool      ea_start();
 56  virtual bool      ea_update(F32 dt);
 57  virtual void      ea_finish(bool was_stopped);
 58
 59  virtual void      getUnconstrainedPosition(Point3F& pos);
 60  virtual void      getUnconstrainedTransform(MatrixF& xfm);
 61};
 62
 63//~~~~~~~~~~~~~~~~~~~~//
 64
 65afxEA_CameraPuppet::afxEA_CameraPuppet()
 66{
 67  puppet_data = 0;
 68  cam_cons = 0;
 69  was_1st_person = false;
 70}
 71
 72void afxEA_CameraPuppet::ea_set_datablock(SimDataBlock* db)
 73{
 74  puppet_data = dynamic_cast<afxCameraPuppetData*>(db);
 75}
 76
 77bool afxEA_CameraPuppet::ea_start()
 78{
 79  if (!puppet_data)
 80  {
 81    Con::errorf("afxEA_CameraPuppet::ea_start() -- missing or incompatible datablock.");
 82    return false;
 83  }
 84
 85  do_runtime_substitutions();
 86
 87  afxConstraintID obj_id = mCons_mgr->getConstraintId(puppet_data->cam_def);
 88  cam_cons = mCons_mgr->getConstraint(obj_id);
 89
 90  SceneObject* obj = (cam_cons) ? cam_cons->getSceneObject() : 0;
 91  if (obj && obj->isClientObject())
 92  {
 93    GameConnection* conn = GameConnection::getConnectionToServer();
 94    if (conn)
 95    {
 96      was_1st_person = conn->isFirstPerson();
 97      if (was_1st_person)
 98        conn->setFirstPerson(false);
 99    }
100  }
101
102  return true;
103}
104
105bool afxEA_CameraPuppet::ea_update(F32 dt)
106{
107  SceneObject* obj = (cam_cons) ? cam_cons->getSceneObject() : 0;
108
109  if (obj && mIn_scope)
110  {
111    obj->setTransform(mUpdated_xfm);
112  }
113
114  return true;
115}
116
117void afxEA_CameraPuppet::ea_finish(bool was_stopped)
118{
119  afxCamera* afx_cam = dynamic_cast<afxCamera*>((cam_cons) ? cam_cons->getSceneObject() : 0);
120  if (afx_cam && afx_cam->isClientObject())
121    afx_cam->setThirdPersonSnapClient();
122
123  if (was_1st_person)
124  {
125    GameConnection* conn = GameConnection::getConnectionToServer();
126    if (conn)
127      conn->setFirstPerson(true);
128  }
129}
130
131void afxEA_CameraPuppet::getUnconstrainedPosition(Point3F& pos)
132{
133  SceneObject* obj = (cam_cons) ? cam_cons->getSceneObject() : 0;
134  if (obj)
135    pos = obj->getRenderPosition();
136  else
137    pos.zero();
138}
139
140void afxEA_CameraPuppet::getUnconstrainedTransform(MatrixF& xfm)
141{
142  SceneObject* obj = (cam_cons) ? cam_cons->getSceneObject() : 0;
143  if (obj)
144    xfm = obj->getRenderTransform();
145  else
146    xfm.identity();
147}
148
149void afxEA_CameraPuppet::do_runtime_substitutions()
150{
151  // only clone the datablock if there are substitutions
152  if (puppet_data->getSubstitutionCount() > 0)
153  {
154    // clone the datablock and perform substitutions
155    afxCameraPuppetData* orig_db = puppet_data;
156    puppet_data = new afxCameraPuppetData(*orig_db, true);
157    orig_db->performSubstitutions(puppet_data, mChoreographer, mGroup_index);
158  }
159}
160
161//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
162
163class afxEA_CameraPuppetDesc : public afxEffectAdapterDesc, public afxEffectDefs 
164{
165  static afxEA_CameraPuppetDesc desc;
166
167public:
168  virtual bool  testEffectType(const SimDataBlock*) const;
169  virtual bool  requiresStop(const afxEffectWrapperData*, const afxEffectTimingData&) const;
170  virtual bool  runsOnServer(const afxEffectWrapperData*) const;
171  virtual bool  runsOnClient(const afxEffectWrapperData*) const;
172
173  virtual afxEffectWrapper* create() const { return new afxEA_CameraPuppet; }
174};
175
176afxEA_CameraPuppetDesc afxEA_CameraPuppetDesc::desc;
177
178bool afxEA_CameraPuppetDesc::testEffectType(const SimDataBlock* db) const
179{
180  return (typeid(afxCameraPuppetData) == typeid(*db));
181}
182
183bool afxEA_CameraPuppetDesc::requiresStop(const afxEffectWrapperData* ew, const afxEffectTimingData& timing) const
184{
185  return (timing.lifetime < 0);
186}
187
188bool afxEA_CameraPuppetDesc::runsOnServer(const afxEffectWrapperData* ew) const
189{
190  U8 networking = ((const afxCameraPuppetData*)ew->effect_data)->networking;
191  return ((networking & (SERVER_ONLY | SERVER_AND_CLIENT)) != 0);
192}
193
194bool afxEA_CameraPuppetDesc::runsOnClient(const afxEffectWrapperData* ew) const
195{
196  U8 networking = ((const afxCameraPuppetData*)ew->effect_data)->networking;
197  return ((networking & (CLIENT_ONLY | SERVER_AND_CLIENT)) != 0);
198}
199
200//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
201