Torque3D Documentation / _generateds / afxXM_RandomRot.cpp

afxXM_RandomRot.cpp

Engine/source/afx/xm/afxXM_RandomRot.cpp

More...

Classes:

Public Functions

ConsoleDocClass(afxXM_RandomRotData , "@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_RandomRotData , "@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_RandomRotData )

  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
 36//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
 37
 38class afxXM_RandomRotData : public afxXM_BaseData
 39{
 40  typedef afxXM_BaseData Parent;
 41
 42public:
 43  Point3F       axis;
 44  F32           theta_min;
 45  F32           theta_max;
 46  F32           phi_min;
 47  F32           phi_max;
 48
 49public:
 50  /*C*/         afxXM_RandomRotData(); 
 51  /*C*/         afxXM_RandomRotData(const afxXM_RandomRotData&, bool = false);
 52
 53  void          packData(BitStream* stream);
 54  void          unpackData(BitStream* stream);
 55  bool          onAdd();
 56
 57  virtual bool  allowSubstitutions() const { return true; }
 58
 59  static void   initPersistFields();
 60
 61  afxXM_Base*   create(afxEffectWrapper* fx, bool on_server);
 62
 63  DECLARE_CONOBJECT(afxXM_RandomRotData);
 64  DECLARE_CATEGORY("AFX");
 65};
 66
 67class afxXM_RandomRot : public afxXM_Base
 68{
 69  typedef afxXM_Base Parent;
 70
 71  MatrixF       rand_ori;
 72
 73public:
 74  /*C*/         afxXM_RandomRot(afxXM_RandomRotData*, afxEffectWrapper*);
 75
 76  virtual void  updateParams(F32 dt, F32 elapsed, afxXM_Params& params);
 77};
 78
 79//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
 80
 81IMPLEMENT_CO_DATABLOCK_V1(afxXM_RandomRotData);
 82
 83ConsoleDocClass( afxXM_RandomRotData,
 84   "@brief An xmod datablock.\n\n"
 85
 86   "@ingroup afxXMods\n"
 87   "@ingroup AFX\n"
 88   "@ingroup Datablocks\n"
 89);
 90
 91afxXM_RandomRotData::afxXM_RandomRotData()
 92{
 93  axis.set(0,0,1);
 94  theta_min = 0.0f; 
 95  theta_max = 360.0f;
 96  phi_min = 0.0f; 
 97  phi_max = 360.0f;
 98}
 99
100afxXM_RandomRotData::afxXM_RandomRotData(const afxXM_RandomRotData& other, bool temp_clone) : afxXM_BaseData(other, temp_clone)
101{
102  axis = other.axis;
103  theta_min = other.theta_min;
104  theta_max = other.theta_max;
105  phi_min = other.phi_min;
106  phi_max = other.phi_max;
107}
108
109void afxXM_RandomRotData::initPersistFields()
110{
111  addField("axis",      TypePoint3F,  Offset(axis, afxXM_RandomRotData),
112    "...");
113  addField("thetaMin",  TypeF32,      Offset(theta_min, afxXM_RandomRotData),
114    "...");
115  addField("thetaMax",  TypeF32,      Offset(theta_max, afxXM_RandomRotData),
116    "...");
117  addField("phiMin",    TypeF32,      Offset(phi_min, afxXM_RandomRotData),
118    "...");
119  addField("phiMax",    TypeF32,      Offset(phi_max, afxXM_RandomRotData),
120    "...");
121
122  Parent::initPersistFields();
123}
124
125void afxXM_RandomRotData::packData(BitStream* stream)
126{
127  Parent::packData(stream);
128  mathWrite(*stream, axis);
129  stream->write(theta_min);
130  stream->write(theta_max);
131  stream->write(phi_min);
132  stream->write(phi_max);
133}
134
135void afxXM_RandomRotData::unpackData(BitStream* stream)
136{
137  Parent::unpackData(stream);
138  mathRead(*stream, &axis);
139  stream->read(&theta_min);
140  stream->read(&theta_max);
141  stream->read(&phi_min);
142  stream->read(&phi_max);
143}
144
145bool afxXM_RandomRotData::onAdd()
146{
147  if (Parent::onAdd() == false)
148    return false;
149
150  axis.normalizeSafe();
151
152  return true;
153}
154
155afxXM_Base* afxXM_RandomRotData::create(afxEffectWrapper* fx, bool on_server)
156{
157  afxXM_RandomRotData* datablock = this;
158
159  if (getSubstitutionCount() > 0)
160  {
161    datablock = new afxXM_RandomRotData(*this, true);
162    this->performSubstitutions(datablock, fx->getChoreographer(), fx->getGroupIndex());
163  }
164
165  return new afxXM_RandomRot(datablock, fx);
166}
167
168//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//
169
170afxXM_RandomRot::afxXM_RandomRot(afxXM_RandomRotData* db, afxEffectWrapper* fxw)
171: afxXM_Base(db, fxw) 
172{ 
173  Point3F rand_dir = MathUtils::randomDir(db->axis, db->theta_min, db->theta_max, db->phi_min, db->phi_max);
174  rand_ori = MathUtils::createOrientFromDir(rand_dir);
175}
176
177void afxXM_RandomRot::updateParams(F32 dt, F32 elapsed, afxXM_Params& params)
178{
179  params.ori = rand_ori;
180}
181
182//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
183