afxXM_Aim.cpp

Engine/source/afx/xm/afxXM_Aim.cpp

More...

Classes:

Public Functions

ConsoleDocClass(afxXM_AimData , "@brief An xmod <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">datablock.\n\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">afxXMods\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">AFX\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Datablocks\n</a>" )

Detailed Description

Public Functions

ConsoleDocClass(afxXM_AimData , "@brief An xmod <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">datablock.\n\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">afxXMods\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">AFX\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Datablocks\n</a>" )

IMPLEMENT_CO_DATABLOCK_V1(afxXM_AimData )

  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 "afx/arcaneFX.h"
 28
 29#include "math/mathUtils.h"
 30
 31#include "afx/afxEffectWrapper.h"
 32#include "afx/afxChoreographer.h"
 33#include "afx/xm/afxXfmMod.h"
 34
 35//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
 36
 37class afxXM_AimData : public afxXM_WeightedBaseData
 38{
 39  typedef afxXM_WeightedBaseData Parent;
 40
 41public:
 42  bool          aim_z_only;
 43
 44public:
 45  /*C*/         afxXM_AimData();
 46  /*C*/         afxXM_AimData(const afxXM_AimData&, bool = false);
 47
 48  void          packData(BitStream* stream);
 49  void          unpackData(BitStream* stream);
 50
 51  virtual bool  allowSubstitutions() const { return true; }
 52
 53  static void   initPersistFields();
 54
 55  afxXM_Base*   create(afxEffectWrapper* fx, bool on_server);
 56
 57  DECLARE_CONOBJECT(afxXM_AimData);
 58  DECLARE_CATEGORY("AFX");
 59};
 60
 61//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//
 62
 63class afxConstraint;
 64
 65class afxXM_Aim_weighted : public afxXM_WeightedBase
 66{
 67  typedef afxXM_WeightedBase Parent;
 68
 69public:
 70  /*C*/           afxXM_Aim_weighted(afxXM_AimData*, afxEffectWrapper*);
 71
 72  virtual void    updateParams(F32 dt, F32 elapsed, afxXM_Params& params);
 73};
 74
 75//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//
 76
 77class afxXM_Aim_weighted_z : public afxXM_WeightedBase
 78{
 79  typedef afxXM_WeightedBase Parent;
 80
 81public:
 82  /*C*/           afxXM_Aim_weighted_z(afxXM_AimData*, afxEffectWrapper*);
 83
 84  virtual void    updateParams(F32 dt, F32 elapsed, afxXM_Params& params);
 85};
 86
 87//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//
 88
 89class afxXM_Aim_fixed : public afxXM_Base
 90{
 91  typedef afxXM_Base Parent;
 92
 93public:
 94  /*C*/           afxXM_Aim_fixed(afxXM_AimData*, afxEffectWrapper*);
 95
 96  virtual void    updateParams(F32 dt, F32 elapsed, afxXM_Params& params);
 97};
 98
 99//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//
100
101class afxXM_Aim_fixed_z : public afxXM_Base
102{
103  typedef afxXM_Base Parent;
104
105public:
106  /*C*/           afxXM_Aim_fixed_z(afxXM_AimData*, afxEffectWrapper*);
107
108  virtual void    updateParams(F32 dt, F32 elapsed, afxXM_Params& params);
109};
110
111//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
112
113IMPLEMENT_CO_DATABLOCK_V1(afxXM_AimData);
114
115ConsoleDocClass( afxXM_AimData,
116   "@brief An xmod datablock.\n\n"
117
118   "@ingroup afxXMods\n"
119   "@ingroup AFX\n"
120   "@ingroup Datablocks\n"
121);
122
123afxXM_AimData::afxXM_AimData()
124{
125  aim_z_only = false;
126}
127
128afxXM_AimData::afxXM_AimData(const afxXM_AimData& other, bool temp_clone) : afxXM_WeightedBaseData(other, temp_clone)
129{
130  aim_z_only = other.aim_z_only;
131}
132
133void afxXM_AimData::initPersistFields()
134{
135  addField("aimZOnly",          TypeBool,    Offset(aim_z_only, afxXM_AimData),
136    "...");
137
138  Parent::initPersistFields();
139}
140
141void afxXM_AimData::packData(BitStream* stream)
142{
143  Parent::packData(stream);
144  stream->writeFlag(aim_z_only);
145}
146
147void afxXM_AimData::unpackData(BitStream* stream)
148{
149  Parent::unpackData(stream);
150  aim_z_only = stream->readFlag();
151}
152
153afxXM_Base* afxXM_AimData::create(afxEffectWrapper* fx, bool on_server)
154{
155  afxXM_AimData* datablock = this;
156
157  if (getSubstitutionCount() > 0)
158  {
159    datablock = new afxXM_AimData(*this, true);
160    this->performSubstitutions(datablock, fx->getChoreographer(), fx->getGroupIndex());
161  }
162
163  if (datablock->aim_z_only)
164  {
165    if (datablock->hasFixedWeight())
166      return new afxXM_Aim_fixed_z(datablock, fx);
167    else
168      return new afxXM_Aim_weighted_z(datablock, fx);
169  }
170  else
171  {
172    if (datablock->hasFixedWeight())
173      return new afxXM_Aim_fixed(datablock, fx);
174    else
175      return new afxXM_Aim_weighted(datablock, fx);
176  }
177}
178
179//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//
180
181afxXM_Aim_weighted::afxXM_Aim_weighted(afxXM_AimData* db, afxEffectWrapper* fxw) 
182  : afxXM_WeightedBase(db, fxw)
183{ 
184}
185
186void afxXM_Aim_weighted::updateParams(F32 dt, F32 elapsed, afxXM_Params& params)
187{ 
188  VectorF line_of_sight = params.pos2 - params.pos;
189  line_of_sight.normalize();
190
191  F32 wt_factor = calc_weight_factor(elapsed); 
192
193  QuatF qt_ori_incoming(params.ori);
194  
195  MatrixF ori_outgoing = MathUtils::createOrientFromDir(line_of_sight); 
196  QuatF qt_ori_outgoing(ori_outgoing);
197
198  QuatF qt_ori = qt_ori_incoming.slerp(qt_ori_outgoing, wt_factor);
199
200  qt_ori.setMatrix(&params.ori);
201}
202
203//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//
204
205afxXM_Aim_weighted_z::afxXM_Aim_weighted_z(afxXM_AimData* db, afxEffectWrapper* fxw) 
206  : afxXM_WeightedBase(db, fxw)
207{ 
208}
209
210void afxXM_Aim_weighted_z::updateParams(F32 dt, F32 elapsed, afxXM_Params& params)
211{
212  Point3F aim_at_pos = params.pos2;
213  aim_at_pos.z = params.pos.z;
214
215  VectorF line_of_sight = aim_at_pos - params.pos;
216  line_of_sight.normalize();
217
218  F32 wt_factor = calc_weight_factor(elapsed); 
219
220  QuatF qt_ori_incoming(params.ori);
221  
222  MatrixF ori_outgoing = MathUtils::createOrientFromDir(line_of_sight); 
223  QuatF qt_ori_outgoing( ori_outgoing );
224
225  QuatF qt_ori = qt_ori_incoming.slerp(qt_ori_outgoing, wt_factor);
226
227  qt_ori.setMatrix(&params.ori);
228}
229
230//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//
231
232afxXM_Aim_fixed::afxXM_Aim_fixed(afxXM_AimData* db, afxEffectWrapper* fxw) 
233  : afxXM_Base(db, fxw)
234{ 
235}
236
237void afxXM_Aim_fixed::updateParams(F32 dt, F32 elapsed, afxXM_Params& params)
238{
239  VectorF line_of_sight = params.pos2 - params.pos;
240  line_of_sight.normalize();  
241  params.ori = MathUtils::createOrientFromDir(line_of_sight); 
242}
243
244//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//
245
246afxXM_Aim_fixed_z::afxXM_Aim_fixed_z(afxXM_AimData* db, afxEffectWrapper* fxw) 
247  : afxXM_Base(db, fxw)
248{ 
249}
250
251void afxXM_Aim_fixed_z::updateParams(F32 dt, F32 elapsed, afxXM_Params& params)
252{
253  Point3F aim_at_pos = params.pos2;    
254  aim_at_pos.z = params.pos.z;
255
256  VectorF line_of_sight = aim_at_pos - params.pos;
257  line_of_sight.normalize();
258
259  params.ori = MathUtils::createOrientFromDir(line_of_sight);
260}
261
262//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
263