afxXM_Spin.cpp

Engine/source/afx/xm/afxXM_Spin.cpp

More...

Classes:

Public Functions

ConsoleDocClass(afxXM_SpinData , "@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_SpinData , "@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_SpinData )

  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/mathIO.h"
 30#include "math/mathUtils.h"
 31
 32#include "afx/afxEffectWrapper.h"
 33#include "afx/afxChoreographer.h"
 34#include "afx/xm/afxXfmMod.h"
 35#include "afx/util/afxPath3D.h"
 36#include "afx/util/afxPath.h"
 37
 38//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
 39
 40class afxXM_SpinData : public afxXM_WeightedBaseData
 41{
 42  typedef afxXM_WeightedBaseData Parent;
 43
 44public:
 45  Point3F       spin_axis;
 46  F32           spin_angle;
 47  F32           spin_angle_var;
 48  F32           spin_rate;
 49  F32           spin_rate_var;
 50
 51public:
 52  /*C*/         afxXM_SpinData() : spin_axis(0,0,1), spin_angle(0),  spin_angle_var(0), spin_rate(0), spin_rate_var(0) { }
 53  /*C*/         afxXM_SpinData(const afxXM_SpinData&, bool = false);
 54
 55  void          packData(BitStream* stream);
 56  void          unpackData(BitStream* stream);
 57  bool          onAdd();
 58
 59  virtual bool  allowSubstitutions() const { return true; }
 60
 61  static void   initPersistFields();
 62
 63  afxXM_Base*   create(afxEffectWrapper* fx, bool on_server);
 64
 65  DECLARE_CONOBJECT(afxXM_SpinData);
 66  DECLARE_CATEGORY("AFX");
 67};
 68
 69//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//
 70
 71class afxXM_Spin_weighted : public afxXM_WeightedBase
 72{
 73  typedef afxXM_WeightedBase Parent;
 74
 75  Point3F       spin_axis;
 76  F32           spin_rate;
 77  F32           theta;
 78
 79public:
 80  /*C*/         afxXM_Spin_weighted(afxXM_SpinData*, afxEffectWrapper*);
 81
 82  virtual void  updateParams(F32 dt, F32 elapsed, afxXM_Params& params);
 83};
 84
 85//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//
 86
 87class afxXM_Spin_fixed : public afxXM_Base
 88{
 89  typedef afxXM_Base Parent;
 90
 91  Point3F       spin_axis;
 92  F32           spin_rate;
 93  F32           theta;
 94
 95public:
 96  /*C*/         afxXM_Spin_fixed(afxXM_SpinData*, afxEffectWrapper*);
 97
 98  virtual void  updateParams(F32 dt, F32 elapsed, afxXM_Params& params);
 99};
100
101//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
102
103IMPLEMENT_CO_DATABLOCK_V1(afxXM_SpinData);
104
105ConsoleDocClass( afxXM_SpinData,
106   "@brief An xmod datablock.\n\n"
107
108   "@ingroup afxXMods\n"
109   "@ingroup AFX\n"
110   "@ingroup Datablocks\n"
111);
112
113afxXM_SpinData::afxXM_SpinData(const afxXM_SpinData& other, bool temp_clone) : afxXM_WeightedBaseData(other, temp_clone)
114{
115  spin_axis = other.spin_axis;
116  spin_angle = other.spin_angle;
117  spin_angle_var = other.spin_angle_var;
118  spin_rate = other.spin_rate;
119  spin_rate_var = other.spin_rate_var;
120}
121
122void afxXM_SpinData::initPersistFields()
123{
124  addField("spinAxis",            TypePoint3F,  Offset(spin_axis, afxXM_SpinData),
125    "...");
126  addField("spinAngle",           TypeF32,      Offset(spin_angle, afxXM_SpinData),
127    "...");
128  addField("spinAngleVariance",   TypeF32,      Offset(spin_angle_var, afxXM_SpinData),
129    "...");
130  addField("spinRate",            TypeF32,      Offset(spin_rate, afxXM_SpinData),
131    "...");
132  addField("spinRateVariance",    TypeF32,      Offset(spin_rate_var, afxXM_SpinData),
133    "...");
134
135  Parent::initPersistFields();
136}
137
138void afxXM_SpinData::packData(BitStream* stream)
139{
140  Parent::packData(stream);
141  mathWrite(*stream, spin_axis);
142  stream->write(spin_angle);
143  stream->write(spin_angle_var);
144  stream->write(spin_rate);
145  stream->write(spin_rate_var);
146}
147
148void afxXM_SpinData::unpackData(BitStream* stream)
149{
150  Parent::unpackData(stream);
151  mathRead(*stream, &spin_axis);
152  stream->read(&spin_angle);
153  stream->read(&spin_angle_var);
154  stream->read(&spin_rate);
155  stream->read(&spin_rate_var);
156}
157
158bool afxXM_SpinData::onAdd()
159{
160  if (Parent::onAdd() == false)
161    return false;
162
163  spin_axis.normalizeSafe();
164
165  return true;
166}
167
168afxXM_Base* afxXM_SpinData::create(afxEffectWrapper* fx, bool on_server)
169{
170  afxXM_SpinData* datablock = this;
171
172  if (getSubstitutionCount() > 0)
173  {
174    datablock = new afxXM_SpinData(*this, true);
175    this->performSubstitutions(datablock, fx->getChoreographer(), fx->getGroupIndex());
176  }
177
178  if (datablock->hasFixedWeight())
179    return new afxXM_Spin_fixed(datablock, fx);
180  else
181    return new afxXM_Spin_weighted(datablock, fx);
182}
183
184//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//
185
186afxXM_Spin_weighted::afxXM_Spin_weighted(afxXM_SpinData* db, afxEffectWrapper* fxw)
187    : afxXM_WeightedBase(db, fxw) 
188{ 
189  spin_axis = db->spin_axis;
190
191  spin_rate = db->spin_rate;
192  if (db->spin_rate_var != 0.0f)
193    spin_rate += gRandGen.randF()*2.0f*db->spin_rate_var - db->spin_rate_var;
194  spin_rate *= db->getWeightFactor()/<a href="/coding/class/classafxxm__base/#classafxxm__base_1a53eea351c62b62b2b9d59be7977cb793">time_factor</a>;
195
196  F32 spin_angle = db->spin_angle;
197  if (db->spin_angle_var != 0.0f)
198    spin_angle += gRandGen.randF()*2.0f*db->spin_angle_var - db->spin_angle_var;
199  theta = mDegToRad(spin_angle);
200}
201
202void afxXM_Spin_weighted::updateParams(F32 dt, F32 elapsed, afxXM_Params& params)
203{
204  F32 wt_factor = calc_weight_factor(elapsed);
205  F32 rate = spin_rate*wt_factor;
206  theta += mDegToRad(dt*rate);
207
208  AngAxisF spin_aa(spin_axis, theta);
209  MatrixF spin_xfm; spin_aa.setMatrix(&spin_xfm);
210  
211  params.ori.mul(spin_xfm);
212}
213
214//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//
215
216afxXM_Spin_fixed::afxXM_Spin_fixed(afxXM_SpinData* db, afxEffectWrapper* fxw)
217    : afxXM_Base(db, fxw) 
218{ 
219  spin_axis = db->spin_axis;
220
221  spin_rate = db->spin_rate;
222  if (db->spin_rate_var != 0.0f)
223    spin_rate += gRandGen.randF()*2.0f*db->spin_rate_var - db->spin_rate_var;
224  spin_rate *= db->getWeightFactor()/<a href="/coding/class/classafxxm__base/#classafxxm__base_1a53eea351c62b62b2b9d59be7977cb793">time_factor</a>;
225
226  F32 spin_angle = db->spin_angle;
227  if (db->spin_angle_var != 0.0f)
228    spin_angle += gRandGen.randF()*2.0f*db->spin_angle_var - db->spin_angle_var;
229  theta = mDegToRad(spin_angle);
230}
231
232void afxXM_Spin_fixed::updateParams(F32 dt, F32 elapsed, afxXM_Params& params)
233{
234  theta += mDegToRad(dt*spin_rate);
235
236  AngAxisF spin_aa(spin_axis, theta);
237  MatrixF spin_xfm; spin_aa.setMatrix(&spin_xfm);
238  
239  params.ori.mul(spin_xfm);
240}
241
242//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
243